• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Carabiner 1.0: Asset Management Library

#11
[eluser]tonydewan[/eluser]
Trice: It's definitely on the list. I just need to think through how to best implement it...

Pyro: Let us know how that works for you! I've not used your Asset Helper, but a quick glance makes me think that you might run into issues with caching. Currently, Carabiner uses only one cache folder, and filenames are built based on the most recent last modified date of the files, plus an md5 hash of all of the filenames. I'm not sure that would play nice with your helper, but I hope it works out. Let me know if you need any illumination about how/why Carabiner does what it does. You also might look at the two minification libraries separately. They might be easier to hook into your helper.

#12
[eluser]Murodese[/eluser]
Great library, thanks.

#13
[eluser]freshface[/eluser]
A great addition would be is to give screen or print with a css asset.

#14
[eluser]dannyded[/eluser]
Very good library. But you have some bugs in it.

When you try to pass array to $this->carabiner->css method, array offset error appears.
You need to use for each function inside $this->carabiner->js and $this->carabiner->css to when you pass array. For example:

Code:
if( is_array($dev_file) ){
        
        if( is_array($dev_file[0]) ){
        
            foreach($dev_file as $file){
                
                $this->_asset('js', $file[0], $file[1], $file[2]);
            
            }
            
        }else{
            // you are missing this part
            foreach($dev_file as $file){                
                $this->_asset('js', $file, $prod_file, $combine);
            }
            
        }
        
    }else{
    
        $this->_asset('js', $dev_file, $prod_file, $combine);

    }


One more bug is when you set combine = true false and dev = false.
In that case, js or css file path isn't returned correctly.
Solution (arround line 484), you need to set $f = $f instead $f = $this->cache_uri . $f:
Code:
} elseif(!$this->combine && $this->minify_css) { // we want to minify, but not combine
                    
                    // minify each file, cache it, and serve it up. Oy.
                    foreach($this->css as $ref):
                        
                        if( isset($ref['prod']) ){
                        
                            $f = $this->style_uri . $ref['prod'];
                        
                        } else {
                        
                            $f = filemtime( realpath( $this->style_path . $ref['dev'] ) ) . md5($ref['dev']) . '.css';
                        
                            if( !file_exists($this->cache_path.$f) ){
    
                                $c = $this->_minify( 'css', $ref['dev'] );
                                $this->_cache($f, $c);
                            
                            }
                            // $f = $this->cache_uri . $f;
                            $f = $f;

                        }

#15
[eluser]umefarooq[/eluser]
hi on windows server I'm facing the following problem. while loading js and css assets. right now im loading js but it is same for css also.
Code:
A PHP Error was encountered

Severity: Warning

Message: file_get_contents(G:\umer_data\AppServ\www\dfwstatic/js/niceforms-default.css) [function.file-get-contents]: failed to open stream: No such file or directory

Filename: libraries/carabiner.php

Line Number: 611

#16
[eluser]tonydewan[/eluser]
DannyD:

Thanks for the feedback! The first bug you provided comes from not setting all 3 possible attributes in your array. Your fix doesn't quite work, but something like this will:

Code:
if( is_array($dev_file) ){
            
            if( is_array($dev_file[0]) ){
            
                foreach($dev_file as $file){
                    
                    $d = $file[0];
                    $p = (isset($file[1])) ? $file[1] : '';
                    $c = (isset($file[2])) ? $file[2] : $combine;

                    $this->_asset('js', $d, $p, $c);
                
                }
                
            }else{
                
                $d = $dev_file[0];
                $p = (isset($dev_file[1])) ? $dev_file[1] : '';
                $c = (isset($dev_file[2])) ? $dev_file[2] : $combine;
                
                $this->_asset('js', $d, $p, $c);
                
            }
            
        }else{
        
            $this->_asset('js', $dev_file, $prod_file, $combine);
    
        }

Your second bug is also a great find. However, you don't need to set
Code:
$f = $f;
You can just remove that line altogether.

I'll be updating the library to include these fixes. Thanks!



umefarooq:

I haven't got access to a Windows server to test on, but I think this might fix your problem. In the function called _minify, change both lines that look like this:
Code:
$contents = file_get_contents($this->style_path.$file_ref, 'r');

to this:
Code:
$contents = file_get_contents( realpath($this->script_path.$file_ref) );

I think that will fix your problem, but I'm not sure. Let me know if it does, and I'll update the library with those fixes as well.

Note that you'll probably get the same error again, but from a different part of the library. There are four calls to file_get_contents in the _combine function, that will need a similar change.

Thanks for the feedback, everyone.

#17
[eluser]freshface[/eluser]
@tonydewan How about setting the css "type", screen, print, …

#18
[eluser]Tom Schlick[/eluser]
really nice! im going to try it out tonight after i get home. i really like the idea of having dev/live settings so i can debug and ive been trying to find a good lib to compress it all. thanks a lot. keep up the good work

#19
[eluser]dannyded[/eluser]
your solution doesn't work for me again.. it prints only first element in array..

#20
[eluser]umefarooq[/eluser]
really nice library i love it only feature i need gzip can you add this it makes my life very easy i can use as many js and css files as i want for a specific page. really love it.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.