Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
casset - an alternative asset class which supports minifying scripts, cleaner syntax
  • Hi all, I spent today writing an alternative to the Asset class. I'm coming from codeigniter, and was longing for something like the wonderful carabiner library.
    While I don't yet have the full carabiner feature set, Casset does boast the following:
    - Minifying (and caching) css / js
    - More powerful groups
    - Enabling / disabling groups
    - Defining groups in a config file
    - Rendering all groups at once
    - Rendering css/js from a string Please take a look -- the repo's at http://github.com/canton7/fuelphp-casset/. Suggestions, criticism, flame, contributions all equally welcome. Thanks!
  • OK, that's coded and is present in the develop branch. I'll do a release and bring it into master on Monday or so.
    Hope that solves your problem! EDIT: See the "Paths and namespacing" section in the readme.
  • Why are CSS files rendered in random order? That's stupid. CSS stands for Cascading Style Sheet. The rules cascade. If I place one file after another I probably did it for a reason. I want my rules to cascade so that the correct style is attained. I think you should change this so that CSS files retain the order that they are added. I've edited your source and removed the uasort() that's run on CSS files once retrieved. :)
  • When I checked the css spec when making that decision, I could only find reference to how precedence was worked out in css rules, and absolutely nothing to do with files. Therefore the assumption was that relying on file order to determine precedence was unspecified, and people wouldn't rely on it. Sorting the files allowed for different orders of files to be assigned the same cache file. However, looking around it appears that people do rely on css file order (whether in accordance with the spec or not -- I need to investigate more thoroughly), so I've removed the re-ordering in the develop branch. I'll probably do a release later this week, where it'll get pushed to master. Thanks for the heads-up!
  • Sounds good man! Great package by the way. Thanks heaps.
  • Thanks again for your contribution.
  • Very good work canton7! I have another idea, maybe it's useful to make a function which only returns the path to a specific file, like the img_asset_url() function in the CI asset helper: http://codeigniter.com/wiki/Asset_Helper/ It's useful when you only need the full path and not the HTML-tags. I'm no using yepnope.js (http://yepnopejs.com/) and after the test it loads a specific JS file (depending on the result of the test). A function which returns the full path of the JS file would be very useful there. What do you think?
  • Good idea! There's a private function that does pretty much that (find_files), but I'll wrap it in some syntactic sugar and expose it. There could be some confusion with the fact that filenames can contain wildcards, and therefore that arrays of files could be returned, but I'm sure there's a clean solution. I guess I could allow arbitrary additions to the default_folders array (holds the locations of img, js, css dirs) to allow people to deal with custom asset types (swf, for example) as well. I'll see if I can get it done tonight.
  • I have a data URL function I use in my stylesheets for small images. Interested in including it in the library?
  • First of all GREAT plugin, love it . I am having one issue though that may be server related. We turned on compression using AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php But for some reason the cache still is not being sent compressed. Any ideas how i can fix this?
  • Thanks for this package! But I have a problem with CSS/JS groups. I have this group:
    'groups' => array(
      'css' => array(
       'jquery-ui' => array(
        'files' => array(
         'jquery-ui.css',
        ),
        'enabled' => true,
       ),
      ),
     ),
    

    And in my view I use this:
    echo Casset::render_css();
    

    I keep getting this error:
    Notice!
    
    ErrorException [ Notice ]: Undefined index: jquery-ui.css
    
    PKGPATH/casset/classes/casset.php @ line 194:
    
    193: $parts = explode('::', $file, 2);
    194: $path = static::$asset_paths[$parts[0]];
    195: $file = $parts[1];
    

    And 2 more errors as a result of this error. The file jquery_ui.css exists in /public_html/assets/css/ and when I load the page in the browser a cache file is being created, but it's empty. This works fine:
    Casset::css('jquery-ui.css');
    echo Casset::render_css();
    

    Any idea what's going wrong?
  • My bad, that was half a documentation omission since adding in namespacing, and half forgetting that people might want to specify un-namespaced files in groups in the config file. I've updated the docs and tweaked things so that your example now works (without modification). Thanks, and apologies,
    Antony
  • Thanks for this package, it's really useful for my website. But I have a question. I'm using uploadify, which contains CSS, JS, images and some other files. Where is the best way to put these files, and use it as a group in casset? Off course I can add the files in the separate /assets/img, css, js etc. folders, but I'd like to keep the uploadify files together, something like /assets/uploadify/css, js, img etc. But then I can't enable it as a group (or can I?). I want to have it in a group so I can easily include all the necessary uploadify files on a page which needs uploadify. (In this post uploadify is just an example)
  • You'll want to create a namespace for the uploadify stuff, use something like this in your config:
    'paths' => array(
       'core' => 'assets/',
       'uploadify' => 'assets/uploadify/'
    ),
    

    Then use this namespace when defining your groups. You have to use the namespace explicitly with each file (as there's no way to call set_path), but that's alright:
    'groups' => array(
       'js' => array(
          'uploadify' => array(
             'files' => array(
                'uploadify::file1.js',
                'uploadify::file2.js',
             ),
             'enabled' => true,
          ) ,
       ),
       'css' => array(
          'uploadify' => array(...),
       ),
    ),
    

    If you're lazy, you can always glob...
    'groups' => array(
       'js' => array(
          'uploadify' => array(
             'files' => array(
                'uploadify::*.js',
             ),
             'enabled' => true,
          ) ,
       ),
       'css' => array(
          'uploadify' => array(...),
       ),
    ),
    

    I've just noticed that this isn't documented anywhere... I'll stick it in the readme for the next release. Thanks!
    Antony
  • Antony Male wrote on Wednesday 15th of June 2011:
    My bad, that was half a documentation omission since adding in namespacing, and half forgetting that people might want to specify un-namespaced files in groups in the config file. I've updated the docs and tweaked things so that your example now works (without modification). Thanks, and apologies,
    Antony

    Thanks Antony, works great now!
  • Hi everyone, just a quick post to mention that v1.11 is now available. New features: - Asset URLs can be obtained, see "Getting asset paths / urls".
    - Casset::add_group() has been re-implemented.
    - Callbacks now exist: You can use these to process js/css files after they're loaded, but before they're cached. Allows use of SASS, Coffeescript, etc.
    - Exception now thrown if someone attempts to define a group that already exists.
    - Group options are now specified using array syntax, instead of separate function arguments.
    - Option to inline groups moved from Caset::render() to when the group's defined.
    - Option to add attributes to a group's tag moved from Casset::render() to when the group's defined.
    - Add dependencies between groups. Rendering a group will automatically render its dependencies.
    - New functions to allow changing of group options on-the-fly. Casset's also now on fuel-packages, so you can install it using oil. My repo might have a later version, though. Thanks, and once again suggestions always welcome! Antony
  • I think there's something similar there already https://github.com/fuel/assetic
  • Nice link, hadn't come across that library. Assetic looks to be largely focussed on minification (and, to a degree, compression), while throwing a cursory nod at grouping (and a rather complex nod at caching). Casset is smaller (and therefore much simpler), and focusses more on displaying the correct assets in the correct manner with a minimum of typing, with minification if you want it.
  • Thank you so much for this plugin. Very handy :). I seem to have encountered an issue with URLs being rewritten incorrectly in CSS files. I posted it as an issue on Github with more information: https://github.com/canton7/fuelphp-casset/issues/22
    am having one issue though that may be server related. We turned on compression using AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php But for some reason the cache still is not being sent compressed.
    All Casset does is minify and combine the files, and write them to disk. When a user accesses the files, Casset has nothing to do with it any more. They're just ordinary files served by your web server (which looks like Apache based on those configuration lines). Try searching Google for "Apache enable gzip javascript" and see if you can find any useful information :)
  • I like your library, it's quite simple as you said.. you should speak to the fuelphp dev guys to put your library inside the fuelphp repositories.
  • Thanks for the encouragement! I doubt they'll want to change anything in Fuel with a release on the way, but I might mention it once they get back onto feature-adding and Casset gets a bit more real-world experience.
  • Antony Male wrote on Wednesday 8th of June 2011:
    Thanks for the encouragement! I doubt they'll want to change anything in Fuel with a release on the way, but I might mention it once they get back onto feature-adding and Casset gets a bit more real-world experience.

    I meant as a package not something in the core, so it's easier to find
  • Aha I see. I hadn't noticed they did that. Regardless, I think I'll let it mature a little first.
  • Antony Male wrote on Wednesday 8th of June 2011:
    Aha I see. I hadn't noticed they did that. Regardless, I think I'll let it mature a little first.

    Hey, your lib looks nice, you can talk to Jelmer on irc, so he forks your library to https://github.com/fuel-packages so users can find it easier. and one more thing, if you package is in https://github.com/fuel-packages, it gets easy to install via oil :) Good luck and thanks for contribution
  • Good work Antony! I'm using the casset package in several websites now.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion