DeLynn Berry

0 notes

Rails Ticket #3506

This morning I uploaded a Patch for the Rails AssetTagHelper. This patch adds a bit of functionality that I had been looking for with regard to the javascript_include_tag and the stylesheet_link_tag. For those of you interested in the contents of the ticket, click here, or view the extended section of this post by clicking on the button below.

Next up, I plan on releasing my plugin that assists in adding versioning for stylesheets and javascripts automatically ala Justin French.

This patch makes adjustments and additions to the javascript_include_tag and stylesheet_link_tag methods of Asset Tag Helper.

javascript_include_tag

This method has been altered to now handle additional scripts to be included when using the :defaults functionality. Instead of having to make two calls to javascript_include_tag (one for the defaults and one for the scripts you would like to use), you now only have to make one.

For example:

javascript_include_tag(:defaults, “my_scripts”)

results in:

<script src=”/javascripts/prototype.js” type=”text/javascript”></script>
<script src=”/javascripts/effects.js” type=”text/javascript”></script>
<script src=”/javascripts/dragdrop.js” type=”text/javascript”></script>
<script src=”/javascripts/controls.js” type=”text/javascript”></script>
<script src=”/javascripts/my_scripts.js” type=”text/javascript”></script>

The :defaults symbol can also exist at any point in the array of scripts (which will alter where the defaults are output in the markup).

So:

javascript_include_tag(“my_scripts”, :defaults)

produces:

<script src=”/javascripts/my_scripts.js” type=”text/javascript”></script>
<script src=”/javascripts/prototype.js” type=”text/javascript”></script>
<script src=”/javascripts/effects.js” type=”text/javascript”></script>
<script src=”/javascripts/dragdrop.js” type=”text/javascript”></script>
<script src=”/javascripts/controls.js” type=”text/javascript”></script>

This is valuable if you need to have a script load prior to the inclusion of the Prototype and Scriptaculous Javascript libraries.

stylesheet_link_tag

The :defaults functionality has been added to the stylesheet_link_tag method. Right now there are no defaults in the STYLESHEET_DEFAULT_SOURCES array, but the functionality exists for adding to the array using register_stylesheet_include_default. I figured since Javascripts had this functionality, Stylesheets should too. This will allow plugins the ability to add Stylesheets as needed.

The stylesheet_link_tag method also looks to see if a RAILS_ROOT/public/stylesheets/application.css file exists and automatically adds it to the list of included CSS files when the :defaults symbol is passed (just like the javascript_include_tag method).

Filed under patches rails