canton7 / fuelphp-casset

Better asset management library for fuelphp (with minification!)
MIT License
103 stars 29 forks source link

More parameters in "files" array: relative paths & '*' for globing #32

Open younes0 opened 12 years ago

younes0 commented 12 years ago

I'm new to FuelPHP and I used my own assets library before that. In a similar way to Casset, I had groups and files to define. The problem is I can't manage to setup Casset as easily because of the files array.
Here's what I would have set for my library :

$assets_options = array(

    'js' => array(
        'js_dir' => ASSETS_PATH.DS.'javascripts', // public/assets/javascripts/
        'main' => array( // main group
            'files' => array(
                'bootstrap' => 'bootstrap.js', // located in  public/assets/javascripts/bootstrap/ 
                'jquery' => '*', // glob all files in public/assets/javascripts/jquery/ 
                'application' => array(
                    'common' => '*' // glob all files in public/assets/javascripts/application/common/
                )
            ),
            'combine' => true
        ),
    )
);

Can this be applied in Casset OR would be a nice feature to be implemented ?

canton7 commented 12 years ago

This is perfectly possible using Casset, as is. Your config would look something like this:

// In config/casset.php
<?php
return array(
   ...
   'paths' => array(
      'core' => 'assets/', // All assets in the 'core' namespace (default) are located in public/assets/
   ),
   ...
   'js_dir' => 'javascripts/', // Javascript files are located in <namespace>/javascripts/, so public/assets/javascripts/ by default
   ...
   'groups' => array(
      'js' => array(
         'main' => array( // 'main' group
            'files' => array(
               'bootstrap.js', // Add public/assets/javascripts/bootstrap.js
               'jquery/*.js', // Add public/assets/javascripts/jquery/*.js
               'application/common/*.js', // Add public/assets/javascripts/application/common/*.js
            ),
         ),
      ),
   ),
)

Does that make sense? Does that solve the problem you're having?

younes0 commented 12 years ago

Thanks it worked!

However I encountered a problem with the assets folder beeing outside (and not in public) Settings 'core' to '..\assets\' or to the full path 'C:\www\myapp\assets\' didn't work so I removed the DOCROOT references in the Casset Class as a temporary fix...

canton7 commented 12 years ago

Aha interesting. In my own testing, settings 'core' to ../assets/ or ..\\assets\\ worked fine. Did you forget to escape your backslashes?

younes0 commented 12 years ago

Since my application doesn't follow the FuelPHP structure (the Core is located in \vendor\fuelphp), it may have caused some errors with Casset. I noticed in the errors that if I set an absolute path, the DOCROOT is prefixed.A relative path: DOCROOT is not fixed. It's all about DOCROOT anyway.

canton7 commented 12 years ago

Yeah, I should probably be using realpath() instead. I'll look into it.

Do you mind if I ask you a couple more questions about your current setup, as a relative path should be working?

If core is in \vendor\fuelphp, what is DOCROOT set to? Where is your public\ folder? (This should be the same as DOCROOT). Where is your assets\ folder?

younes0 commented 12 years ago

DOCROOT is myapp\ myapp\public (switching it as docroot does not solve the problem) myapp\assets myapp\vendor\packages\casset myapp\vendor\fuelphp\core

I'm not using the Router/Request classes, so the Uri class is useless (but you don't use it apparently). IMHO maybe it's not worth to fix my problem since I didn't setup Fuelphp as recommended.

canton7 commented 12 years ago

Interesting. My code does assume that DOCROOT == the public folder == the script's CWD (a bad assumption, which I will change). But setting DOCROOT = the public folder, and setting 'core' => '../assets/' should, in theory, work.

younes0 commented 12 years ago

I made some tests again: it seems that I didn't switch the public folder as the DOCROOT sorry. Everything works fine. Thank you so much for your help.

canton7 commented 12 years ago

Aha, thanks for re-trying!

You raise a valid point though: I assume that DOCROOT is the public folder, and I don't allow absolute paths for 'core'. I'll address both of these soon. Thanks for your input!

canton7 commented 11 years ago

I'm re-opening this to remind myelf to address the above issues at some point