Rails Plugin: Javascript Dependency Manager
April 26, 2008For the past several months, I've been using a helper I wrote to manage my javascript dependencies. All it really does is allow you to specify which javascript files/libraries depend on others (i.e. scriptaculous depends on prototype) and make it easy to include them when you need them.
I didn't like having to include prototype.js, effect.js, and sidebar.js on every page, and I didn't like specifying all 3 from my view each time I needed it. So I wrote a helper, which is now available in plugin-form on GitHub.
Here is how you use it:
1 # app/views/posts/index.html.erb 2 <% js(:posts) %>
1 # app/helpers/application_helper.rb 2 module ApplicationHelper 3 include JavascriptHelper 4 def js_dependencies 5 { :posts => [:effects] } 6 end 7 end
1 # app/views/layouts/default.html.eb 2 <%= javascript_tags -%>
And that's it. It's a work-in-progress and any comments/suggestions/git-hub pull requests are encouraged.
Comments
I love it! I've written something similar for php though not as elegant. Thanks!
Leave a Comment