canton7 / fuelphp-casset

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

Path of js files #41

Closed Jenini closed 11 years ago

Jenini commented 11 years ago

Hello,

I have some trouble adding a file in my 'js_dir'. In the project, there is many other js files which are perfectly working, but when I try to add one, the new file is not even seen. So I try changing the name of one of the existing and working js file, and Casset still try to find the file with the old name. I guess I missing something here. Can you tell me where the path of the js files are stored ?

This is my config :

return array( 'paths' => array( 'core' => 'assets/', ), 'url' => Config::get('base_url'), 'js_dir' => 'scripts/', 'css_dir' => 'styles/', 'img_dir' => 'images/', 'cache_path' => 'assets/cache/', 'min' => false, 'combine' => false, 'show_files' => false, 'show_files_inline' => true, 'deps_max_depth' => 5, 'post_load_callback' => null, 'filepath_callback' => null, 'groups' => array( ), );

Thanks a lot !

Jenini

canton7 commented 11 years ago

What do you mean by "not even seen"? Casset throws an exception saying it can't find that file? Also what do you mean by "So I try changing the name of one of the existing and working js file, and Casset still try to find the file with the old name."? Do you mean you renamed a working javascript file without telling Casset you renamed it, or you told Casset you renamed it but didn't, or both?

Without these details clear it's hard to say, but my impression is that you think your configuration is saying one thing, but in fact it's saying something else. If you clarify your comments it might make more sense.

Jenini commented 11 years ago

My comment is not clear, because that doesnt make sense for me...

I will try to explain better. When I said "So I try changing the name of one of the existing and working js file, and Casset still try to find the file with the old name", I have not change my configuration, but only the name of the file (importer.js to importer2.js) and I have this error :

Casset\Casset_Exception [ Error ]: Found no files matching assets/scripts/importer.js

And my new script which is in the same directory than importer.js, is not even loaded.

At first, I thought it was enough to put the js script in the correct directory, and Casset would retrieve all the scripts in this directory. But I don't know how Casset does it ...

It is not my project at first, and I am not the one who configure Casset, so thank you canton7 for helping me.

canton7 commented 11 years ago

Aha, that makes more sense.

While it is possible to use globs in Casset - that is, you tell Casset to include all files in a particular directory - the normal way to use it is by telling it exactly which files to include. The README provides lots of details, but the the main ways of adding files are:

  1. By passing the file to \Casset::js()
  2. By defining a group in your config/casset.php, which includes files. Remember that fuel/app/config/casset.php will override fuel/packages/casset/config/casset.php.
  3. By defining a group in code, using \Casset::add_group().

Therefore somewhere in your project - I'd check for both of the config files first, then search for calls to Casset::js and Casset::add_group - someone is explicitly telling Casset which files to use. Similarly, if you want Casset to load a new file, you have to tell it to. Make sure you understand roughly what you're doing, as Casset's a lot more powerful than just "use these JS files on all pages" - there's grouping, enabling, and dependencies to be aware of. Again, the README is a good resource. If it isn't explaining something well enough, tell me and I'll update it.

Does that help?

Jenini commented 11 years ago

I think It will work if I use the Casset::js function. But I just don't understand where Casset looks to find the js files to load.

In my fuel/app/config/casset.php I tell Casset to look into assets/scripts to find js files. I did some print in the casset.php file (js() function), and when I change the name of one of the js file (file.js to file1.js) is still looking for the old name (file.js).
I just can't figure where this information is stored, and it driving me crazy :S

canton7 commented 11 years ago

It's looking for file.js because a bit of configuration somewhere is telling it to look for file.js. Like I said before, by default Casset does not simply look in your js_dir and include all the files it finds there. Instead, you tell it exactly which files to include.

Like I said before, find the bit of configuration which is telling Casset to include file.js. Maybe it's in fuel/packages/casset/config/casset.php, maybe it's in fuel/packages/casset/config/casset.php, or maybe it's in a call to Casset::js or Casset::add_group somewhere in your project. If your editor has a "find in files" search feature, use that. If you've got grep, use that. This isn't a hard problem.

Jenini commented 11 years ago

No I guess it's not a hard problem.... I will keep looking. Thank you for your help