Javascripter is a Rails plugin that helps keep your javascript files organized.
To install, just add Javascripter to your vendor/plugins
directory:
script/plugin install git://github.com/mokolabs/javascripter.git
To use Javascripter, replace your javascript_include_tags
with a single tag:
<head>
<title>the.rails.ist</title>
<%= javascripts %>
</head>
Once you do, your javascripts will be included automatically, using the conventions below.
<head>
<title>the.rails.ist</title>
<script src="/javascripts/application.js?1183566571" />
</head>
Javascripter uses a simple set of conventions:
- Javascript for your entire application should be stored in
application.js
- Javascript for specific controllers should be stored in
controller.js
- Javascript for specific actions should be stored in
controller_action.js
- Javascript for specific actions should be stored in
controller/action.js
(optional)
Follow these conventions and Javascripter will reward you with automagic goodness, loading javascripts for specific controllers or actions whenever they are active.
Need Prototype? Just use the :defaults
parameter, like normal.
<%= javascripts :defaults %>
Need to include extra javascript libraries? Use the :include
parameter:
<%= javascripts :include => "lowpro" %>
<%= javascripts :include => ["lowpro", "lightbox"] %>
Javascripter also includes a generator that will create a default application.js
script and separate javascript files for each controller in your application.
To use the generator, run this command in your terminal:
script/generate javascripts
If you add a new controller, just run the generator again and a new javascript for the controller will be created. (Existing javascripts will be ignored.)
Special thanks to Lachie Cox and the rest of my RORO Sydney comrades who asked for this plugin.
Comments and patches welcome at http://github.com/mokolabs/javascripter/.