Javascript Require plugin

Plugin details

Simplifies management of many JS files by dynamically including javascript file dependencies at the application level.

Websitehttp://brian.maybeyoureinsane.net/blog/2006/10/23/javascriptrequire/ Repositoryhttp://eventualbuddha.textdriven.com/svn/javascript_require/ Author Brian Tags Javascript LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://eventualbuddha.textdriven.com/svn/javascript_require/

My solution (from one index.js):

// require prototype menu models/tag models/interest builder moo.fx.pack.js

This is the first line of the file, and it tells my plugin to make sure that it includes these files before it includes this one when using javascript_include_tag. So the output of javascript_include_tag('index') would be this:

< script type="text/javascript" src="/javascripts/prototype.js">< /script>
< script type="text/javascript" src="/javascripts/menu.js">< /script>
< script type="text/javascript" src="/javascripts/models/tag.js">< /script>
< script type="text/javascript" src="/javascripts/models/interest.js">< /script>
< script type="text/javascript" src="/javascripts/builder.js">< /script>
< script type="text/javascript" src="/javascripts/moo.fx.pack.js">< /script>



It also handles recursive includes:

A.js: // require B …

B.js: // require C …

C.js: …

Here calling javascript_include_tag('A') returns:

< script type="text/javascript" src="/javascript/C.js">< /script>
< script type="text/javascript" src="/javascript/B.js">< /script>
< script type="text/javascript" src="/javascript/A.js">< /script>


And, if two different scripts require the same script, it’ll only be included once:

A.js: // require prototype …

B.js: // require prototype

javascript_include_tag('A', 'B'):

< script type="text/javascript" src="/javascript/prototype.js">< /script>
< script type="text/javascript" src="/javascript/A.js">< /script>
< script type="text/javascript" src="/javascript/B.js">< /script>


This even works if you include ‘A’ and ‘B’ in different calls to javascript_include_tag.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 8 months ago