jsrequire
A small lib to add a require functionality to JavaScript files. On top of a file add something like:
/* require foo/bar */
This includes the file foo/bar.js into the file. Dependencies are resolved in right order of require statments over all files.
## controller
# resolve js dependencies
path_to_js = “/absolute/path/to/javascripts”
jsrequire = JsRequire.new dependencies = jsrequire.resolve_dependencies(File.join(path_to_js, “foo.js”))
# rewrite js paths for web usage
@javascripts = JsRequire::web_path_helper(dependencies,
path_to_js => "/public/javascripts"
})
@stylesheets = dependencies
## haml view
-
for css in @stylesheets %link=> “stylesheet”, :href => css, :type => “text/css”
-
for js in @javascripts %script=> “text/javascript”, :src => js
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 aekym. See LICENSE for details.