EllisLab text mark
Advanced Search
1 of 3
1
   
Carabiner 1.0: Asset Management Library
Posted: 30 January 2009 08:47 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2008-07-25
54 posts

Great library, thanks.

 
Posted: 30 January 2009 06:22 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2008-01-30
159 posts

A great addition would be is to give screen or print with a css asset.

 
Posted: 01 February 2009 03:35 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-28
12 posts

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:

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:

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 
filemtimerealpath$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;

                        
 
Posted: 01 February 2009 07:28 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-11
758 posts

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.

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 streamNo such file or directory

Filename
libraries/carabiner.php

Line Number
611 
 Signature 

CI,JQuery,Google Maps | widget with CI loader | Thumbnail, Image Resize, Image Crop Helper | CI shortcode

 
Posted: 02 February 2009 11:44 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2009-01-21
109 posts

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:

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

$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:

$contents file_get_contents($this->style_path.$file_ref'r')


to this:

$contents file_get_contentsrealpath($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.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

 
Posted: 02 February 2009 11:54 AM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Joined: 2008-01-30
159 posts

@tonydewan How about setting the css “type”, screen, print, …

 
Posted: 06 February 2009 03:07 PM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-17
426 posts

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

 Signature 

aka trs21219
CodeSanity | Github | LinkedIn | Facebook | Twitter | Last.fm

 
Posted: 06 February 2009 07:00 PM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-28
12 posts

your solution doesn’t work for me again.. it prints only first element in array..

 
Posted: 07 February 2009 04:06 AM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-11
758 posts

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.

 Signature 

CI,JQuery,Google Maps | widget with CI loader | Thumbnail, Image Resize, Image Crop Helper | CI shortcode

 
Posted: 09 February 2009 04:11 AM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Avatar
Joined: 2007-08-10
71 posts

Let me know if I have this correct. So this does not load php to output the js and css.  It uses php only when it needs to build the cache and does so by taking the files you add minifies and caches them and outputs a direct link to the minified cached static file. 

If that is the case then this might be useful for my project.  I had been using a custom assets library but someone clued me into the fact that even though it is cached I was still loading php and using memory to output a simple file static file.

 Signature 

—————————————————
More Snippets and Code On My Blog | Validate Your Url Segments

 
Posted: 11 February 2009 12:12 PM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2009-01-16
29 posts

Im not sure how to set this up, where do I put the config stuff? In my controller?

Great work by the way!

 
Posted: 13 February 2009 05:31 PM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Avatar
Joined: 2009-01-21
109 posts

@umefarooq:  I’ll look into writing up my implementation of GZIP.  I don’t have plans to add it to Carabiner directly, however.

@Henry Weismann:  That is correct.

@jrutter:  Yes. You’ll need to apply the config once you’ve initialized the library.  That’ll be happening in your controller, most likely.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

 
Posted: 13 February 2009 06:05 PM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2009-01-21
109 posts

I’ve updated Carabiner to include css media type association.  See the new thread for more info and to download!

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

 
Posted: 08 March 2009 10:40 AM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2008-12-11
34 posts

Hi,
Just wanted to say a few words on the carabiner library.
In my opinion, it would be much better if library used config file. CI provides very good means of loading configs at initialization time to libraries. It is good to use it. Writing more than one line of code in __construct for a library and more than one line per method of a class is too much to me. Another thing, writitng configs in a cnstructor function is just asking for troubles, library should have one separated config. Next, files should be loaded per class and method, combination of class and method is unique for each aplication so you can use it to index files you want to load like so
class_method = array(‘js’ => array(‘files_here’),‘css’ => array(‘files_here’));
Next, default set of files should be specified, it means , if no configuration for a given method and class is provided, load default js set, for example nothing, and defualt css file , say with media specified for screen ...
adding extra params per class and method can be specified in the config like so: default_set_of_files +js_file_1 +js_file_2 etc ... removing files default_set_of_files -js_file_1 -js_file_2, this way you do not have to look for ceratin things every time you start new project ...

Next ... Your functions are too elaborate ... I come from ruby world, and my opinion is that, function should do one thing, no data types checking, nothing(a developer is repsonsible for providing correct data ), no extra checks, one function one thing to do. These are not methods for customers but for developers so overhead should be taken into account and simplicity should not be the main criteria ... your function are monstrous, they should not ... libraries should not mix php and html, it is not very professional. Next. no tests are provided with your library, why ? I noticed this is the standard way this community provides libraries. How can you extend code if you are not sure if you just have not broken something else ... no comment.
All in all this library presents not much value to me, there is a lot of code in it but not much is attained with it… It would be much better to exclude certain files from the given class method by not including them instaed of minify them ... Configuration is poorly designed, configuring things for every class in the constructor is asking for troubles, you have to remember what you placed and where , with 20 controllers it is not practical at all, honestly it brings more trouble than benefits.

I think this library is not much better than the assets helper ... Try harder man ... One day it might be a decent piece of code but it still lacks a lot to reach ceratain level of quality

 Signature 

http://rubyhelp.org

 
Posted: 08 March 2009 11:57 AM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Avatar
Joined: 2009-01-21
109 posts

@meteor Thanks for the feedback.  I’m sorry you don’t like Carabiner.  I’ll certainly take some of the criticisms you’ve provided into account in the future.  However, you certainly don’t need to use Carabiner.  If it’s not for you, don’t use it.  As you mentioned, there are other options available.  If you don’t like those, you can certainly write your own.

I would like to respond to a few points.

meteor - 08 March 2009 02:40 PM

it would be much better if library used config file.

This is something I’m considering for a future release.  I modeled the current config setup after the several of the older libraries by Elliot Haughlin.  As I’ve said before, I think a config file is overkill in this instance.  However, I can certainly see it being useful.

meteor - 08 March 2009 02:40 PM

writitng configs in a cnstructor function is just asking for troubles

There is no configuration in the Carabiner constructor.  The configuration happens with a separate config function.

meteor - 08 March 2009 02:40 PM

Next ... Your functions are too elaborate

I assume your talking about the display function.  I agree wholeheartedly.  That’s on my list of things to redo. I’m optimizing Carabiner as I add functionality.

meteor - 08 March 2009 02:40 PM

I come from ruby world, and my opinion is that, function should do one thing, no data types checking,

The only data type checking is in the js and css functions.  The only reason I do this is to allow arrays or arrays of arrays to be passed to these functions.  That way, the library adapts to how the developer wants to use it.  This is customization over convention, in opposition to the rails mentality of convention over customization.  The extra overhead, in my opinion, is negligible, particularly compared to the functionality gains.

meteor - 08 March 2009 02:40 PM

libraries should not mix php and html

I assume now that your talking about the _tag function.  That’s not really mixing PHP and HTML.  That’s PHP writing HTML.  Is there a better way to do it?  I’m open to ideas.

meteor - 08 March 2009 02:40 PM

Next. no tests are provided with your library, why ?

I’m truly not sure what you’re talking about. Can you give me an example?

meteor - 08 March 2009 02:40 PM

All in all this library presents not much value to me, there is a lot of code in it but not much is attained with it…I think this library is not much better than the assets helper

I’m sorry you feel that way, but there’s a simple solution: don’t use it.

Thanks again for the feedback.  You might also check out the newer (1.2) version of Carabiner.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

 
1 of 3
1