mirror of
https://github.com/lloeki/sprockets-umodule.git
synced 2025-12-06 02:24:41 +01:00
Rails support
This commit is contained in:
parent
e9a75766fd
commit
15239dbcec
5 changed files with 36 additions and 3 deletions
26
README.mdown
26
README.mdown
|
|
@ -4,8 +4,30 @@
|
|||
|
||||
## Goal
|
||||
|
||||
Save you from the boilerplate of writing module wrapping.
|
||||
`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 sprockets-umodule to your Gemfile. Name your module files with .umodule.
|
||||
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`.
|
||||
|
|
|
|||
1
lib/assets/javascripts/umodule.js.erb
Normal file
1
lib/assets/javascripts/umodule.js.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
<%= Umodule::Source.contents %>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
module Sprockets
|
||||
module Umodule
|
||||
VERSION = '1.0.0'
|
||||
VERSION = '1.1.0'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
2
lib/umodule-rails.rb
Normal file
2
lib/umodule-rails.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'sprockets-umodule'
|
||||
require 'umodule/rails'
|
||||
8
lib/umodule/rails.rb
Normal file
8
lib/umodule/rails.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require 'rails/engine'
|
||||
|
||||
module Umodule
|
||||
module Rails
|
||||
class Engine < ::Rails::Engine
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue