bundle exec rake assets:precompile results in node.js error under 0.7.0 #41

Merged
merged 2 commits into from Apr 18, 2012
View
@@ -1,3 +1,11 @@
+# v0.7.1
+
+- Liberalize asset path filtering. `0.7.0` added filtering on the logical
+ asset path which was too aggressive in that only `.js` files were allowed in
+ builds. The RequireJS config variable `logical_asset_filter` has been
+ added, which allows `.js`, `.html`, `.txt` files by default and is user
+ configurable.
+
# v0.7.0
- Support for [almond](https://github.com/jrburke/almond) via
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- requirejs-rails (0.7.0)
+ requirejs-rails (0.7.1)
railties (>= 3.1.1, < 3.3)
GEM
View
@@ -6,15 +6,15 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
## Usage
-1. Add this to your Rails app's `Gemfile`:
+1. Add this to your Rails app's `Gemfile`:
```
gem 'requirejs-rails'
```
-2. Remove all Sprockets directives such as `//= require jquery` from `application.js` and elsewhere. Instead establish JavaScript dependencies using AMD-style `define()` and `require()` calls.
+2. Remove all Sprockets directives such as `//= require jquery` from `application.js` and elsewhere. Instead establish JavaScript dependencies using AMD-style `define()` and `require()` calls.
-3. Use `requirejs_include_tag` at the top-level of your app's layout(s). Other modules will be pulled in dynamically by `require.js` in development and for production builds optimized by `r.js`. Here's a basic `app/views/layouts/application.html.erb` modified for `requirejs-rails`:
+3. Use `requirejs_include_tag` at the top-level of your app's layout(s). Other modules will be pulled in dynamically by `require.js` in development and for production builds optimized by `r.js`. Here's a basic `app/views/layouts/application.html.erb` modified for `requirejs-rails`:
```erb
<!DOCTYPE html>
@@ -34,32 +34,35 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
</html>
```
-4. Organize your JavaScript or CoffeeScript code into modules using `define()`:
+4. Organize your JavaScript or CoffeeScript code into modules using `define()`:
- ```coffeescript
- # app/assets/javascripts/views/tweet_view.js.coffee
+ ```coffeescript
+ # app/assets/javascripts/views/tweet_view.js.coffee
- define ['backbone'], (Backbone) ->
- class TweetView extends Backbone.View
- # ...
- ```
+ define ['backbone'], (Backbone) ->
+ class TweetView extends Backbone.View
+ # ...
+ ```
-5. Instantiate your app using `require()` from a top-level module such as `application.js`:
+5. Instantiate your app using `require()` from a top-level module such as `application.js`:
- ```coffeescript
- # app/assets/javascripts/application.js.coffee
+ ```coffeescript
+ # app/assets/javascripts/application.js.coffee
- require ['jquery', 'backbone', 'TheApp'], ($, Backbone, TheApp) ->
+ require ['jquery', 'backbone', 'TheApp'], ($, Backbone, TheApp) ->
- # Start up the app once the DOM is ready
- $ ->
- window.App = new TheApp()
- Backbone.history.start
- pushState: true
- window.App.start()
- ```
+ # Start up the app once the DOM is ready
+ $ ->
+ window.App = new TheApp()
+ Backbone.history.start
+ pushState: true
+ window.App.start()
+ ```
-6. When ready, build your assets for production deployment as usual. `requirejs-rails` defaults to a single-file build of `application.js`. Additional modules and r.js layered builds may be specified via `config\requirejs.yml`; see the Configuration section below.
+6. When ready, build your assets for production deployment as usual.
+ `requirejs-rails` defaults to a single-file build of `application.js`.
+ Additional modules and r.js layered builds may be specified via
+ `config\requirejs.yml`; see the Configuration section below.
```rake assets:precompile```
@@ -137,6 +140,30 @@ modules:
wrap: true
```
+### Build-time asset filter
+
+The `requirejs-rails` build process uses the Asset Pipeline to assemble assets
+for the `r.js` build. By default, assets ending in `.js`, `.html`, and `.txt`
+will be made available to the build. If you have other asset suffixes to
+include, use the `logical_asset_filter` config setting to add them.
+
+For example, if your templates all end in `.templ` like so...
+
+```javascript
+// in app/assets/javascripts/myapp.js
+define(function (require) {
+ var stuff = require('text!stuff.templ');
+ // ...
+});
+```
+
+... then this config setting will ensure they're picked up in the build:
+
+```ruby
+# in config/application.rb
+config.requirejs.logical_asset_filter += [/\.templ$/]
+```
+
## Advanced features
### Additional data attributes
@@ -13,6 +13,7 @@ def initialize
super
self.manifest = nil
+ self.logical_asset_filter = [/\.js$/,/\.html$/,/\.txt$/]
self.tmp_dir = Rails.root + 'tmp'
self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath
@@ -130,5 +131,11 @@ def module_path_for(mod)
def get_binding
return binding()
end
+
+ def asset_allowed?(asset)
+ self.logical_asset_filter.reduce(false) do |accum, matcher|
+ accum || (matcher =~ asset)
+ end ? true : false
+ end
end
end
@@ -1,6 +1,6 @@
module Requirejs
module Rails
- Version = "0.7.0"
+ Version = "0.7.1"
LibVersion = "1.0.7"
end
end
@@ -90,7 +90,7 @@ EOM
"requirejs:clean"] do
requirejs.config.source_dir.mkpath
requirejs.env.each_logical_path do |logical_path|
- next unless logical_path =~ /\.js$/
+ next unless requirejs.config.asset_allowed?(logical_path)
if asset = requirejs.env.find_asset(logical_path)
filename = requirejs.config.source_dir + asset.logical_path
filename.dirname.mkpath
@@ -37,6 +37,13 @@ def setup
@cfg.loader = :wombat
end
end
+
+ test "matches configured logical assets" do
+ assert_equal true, @cfg.asset_allowed?('foo.js')
+ assert_equal false, @cfg.asset_allowed?('bar.frobnitz')
+ @cfg.logical_asset_filter += [/\.frobnitz$/]
+ assert_equal true, @cfg.asset_allowed?('bar.frobnitz')
+ end
end
class RequirejsHelperTest < ActionView::TestCase