Sprockets support for umodule-js
Find a file
2014-04-18 19:21:01 +02:00
lib Load umodule-source for asset 2013-10-04 14:47:44 +02:00
spec Initial, working version 2013-09-30 17:22:29 +02:00
.gitignore Initial, working version 2013-09-30 17:22:29 +02:00
.travis.yml enable travis 2014-04-18 19:21:01 +02:00
Gemfile Initial, working version 2013-09-30 17:22:29 +02:00
LICENSE Initial, working version 2013-09-30 17:22:29 +02:00
Rakefile spec with rake 2014-04-18 19:20:45 +02:00
README.mdown Mention Rails in the abstract 2013-10-02 17:37:56 +02:00
sprockets-umodule.gemspec long global name 2013-10-04 14:53:09 +02:00

sprockets-umodule

umodule-js integration with Sprockets (and Rails)

Goal

sprockets-umodule saves you from the chore of writing CommonJS umodule wrapping boilerplate. The module name will automatically be set from its logical path (relative path to its asset root).

Usage

Add gem 'sprockets-umodule' to your Gemfile. Name your module files with .js.umodule or .js.umodule.coffee, matching your poison of choice.

If you're using Sprockets, load umodule.js by any way you see fit. For convenience, its source is included and can be obtained with Umodule::Source.contents, so it's merely a umodule.js.erb away:

<%= Umodule::Source.contents %>

Alternatively, you can add File.dirname(Umodule::Source.bundled_path) to the asset load path.

If you're using Rails, add gem 'sprockets-umodule, require: umodule-rails instead, which will make it an engine and set up all of this for you, so you just have to add //= require umodule to application.js.

Important note: due to some technical complications, you must also //= require your umodule assets in application.js, and possibly manage dependency ordering manually. In any case, they should be loaded after umodule.js.