requirejs-rails 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.7.1
2
+
3
+ - Liberalize asset path filtering. `0.7.0` added filtering on the logical
4
+ asset path which was too aggressive in that only `.js` files were allowed in
5
+ builds. The RequireJS config variable `logical_asset_filter` has been
6
+ added, which allows `.js`, `.html`, `.txt` files by default and is user
7
+ configurable.
8
+
1
9
  # v0.7.0
2
10
 
3
11
  - Support for [almond](https://github.com/jrburke/almond) via
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- requirejs-rails (0.7.0)
4
+ requirejs-rails (0.7.1)
5
5
  railties (>= 3.1.1, < 3.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -6,15 +6,15 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
6
6
 
7
7
  ## Usage
8
8
 
9
- 1. Add this to your Rails app's `Gemfile`:
9
+ 1. Add this to your Rails app's `Gemfile`:
10
10
 
11
11
  ```
12
12
  gem 'requirejs-rails'
13
13
  ```
14
14
 
15
- 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.
15
+ 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.
16
16
 
17
- 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`:
17
+ 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`:
18
18
 
19
19
  ```erb
20
20
  <!DOCTYPE html>
@@ -34,32 +34,35 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
34
34
  </html>
35
35
  ```
36
36
 
37
- 4. Organize your JavaScript or CoffeeScript code into modules using `define()`:
37
+ 4. Organize your JavaScript or CoffeeScript code into modules using `define()`:
38
38
 
39
- ```coffeescript
40
- # app/assets/javascripts/views/tweet_view.js.coffee
39
+ ```coffeescript
40
+ # app/assets/javascripts/views/tweet_view.js.coffee
41
41
 
42
- define ['backbone'], (Backbone) ->
43
- class TweetView extends Backbone.View
44
- # ...
45
- ```
42
+ define ['backbone'], (Backbone) ->
43
+ class TweetView extends Backbone.View
44
+ # ...
45
+ ```
46
46
 
47
- 5. Instantiate your app using `require()` from a top-level module such as `application.js`:
47
+ 5. Instantiate your app using `require()` from a top-level module such as `application.js`:
48
48
 
49
- ```coffeescript
50
- # app/assets/javascripts/application.js.coffee
49
+ ```coffeescript
50
+ # app/assets/javascripts/application.js.coffee
51
51
 
52
- require ['jquery', 'backbone', 'TheApp'], ($, Backbone, TheApp) ->
52
+ require ['jquery', 'backbone', 'TheApp'], ($, Backbone, TheApp) ->
53
53
 
54
- # Start up the app once the DOM is ready
55
- $ ->
56
- window.App = new TheApp()
57
- Backbone.history.start
58
- pushState: true
59
- window.App.start()
60
- ```
54
+ # Start up the app once the DOM is ready
55
+ $ ->
56
+ window.App = new TheApp()
57
+ Backbone.history.start
58
+ pushState: true
59
+ window.App.start()
60
+ ```
61
61
 
62
- 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.
62
+ 6. When ready, build your assets for production deployment as usual.
63
+ `requirejs-rails` defaults to a single-file build of `application.js`.
64
+ Additional modules and r.js layered builds may be specified via
65
+ `config\requirejs.yml`; see the Configuration section below.
63
66
 
64
67
  ```rake assets:precompile```
65
68
 
@@ -137,6 +140,30 @@ modules:
137
140
  wrap: true
138
141
  ```
139
142
 
143
+ ### Build-time asset filter
144
+
145
+ The `requirejs-rails` build process uses the Asset Pipeline to assemble assets
146
+ for the `r.js` build. By default, assets ending in `.js`, `.html`, and `.txt`
147
+ will be made available to the build. If you have other asset suffixes to
148
+ include, use the `logical_asset_filter` config setting to add them.
149
+
150
+ For example, if your templates all end in `.templ` like so...
151
+
152
+ ```javascript
153
+ // in app/assets/javascripts/myapp.js
154
+ define(function (require) {
155
+ var stuff = require('text!stuff.templ');
156
+ // ...
157
+ });
158
+ ```
159
+
160
+ ... then this config setting will ensure they're picked up in the build:
161
+
162
+ ```ruby
163
+ # in config/application.rb
164
+ config.requirejs.logical_asset_filter += [/\.templ$/]
165
+ ```
166
+
140
167
  ## Advanced features
141
168
 
142
169
  ### Additional data attributes
@@ -189,7 +216,7 @@ the [amdjs fork of Underscore](https://github.com/amdjs/underscore).
189
216
  ## 0.x API Changes
190
217
 
191
218
  Usage changes that may break functionality for those upgrading along the 0.x
192
- series are documented here. See [the Changelog](CHANGELOG.md) for the full
219
+ series are documented here. See [the Changelog](https://github.com/jwhitley/requirejs-rails/blob/master/CHANGELOG.md) for the full
193
220
  list of feature additions, bugfixes, etc.
194
221
 
195
222
  ### v0.5.1
@@ -13,6 +13,7 @@ module Requirejs::Rails
13
13
  super
14
14
  self.manifest = nil
15
15
 
16
+ self.logical_asset_filter = [/\.js$/,/\.html$/,/\.txt$/]
16
17
  self.tmp_dir = Rails.root + 'tmp'
17
18
  self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath
18
19
 
@@ -130,5 +131,11 @@ module Requirejs::Rails
130
131
  def get_binding
131
132
  return binding()
132
133
  end
134
+
135
+ def asset_allowed?(asset)
136
+ self.logical_asset_filter.reduce(false) do |accum, matcher|
137
+ accum || (matcher =~ asset)
138
+ end ? true : false
139
+ end
133
140
  end
134
141
  end
@@ -1,6 +1,6 @@
1
1
  module Requirejs
2
2
  module Rails
3
- Version = "0.7.0"
3
+ Version = "0.7.1"
4
4
  LibVersion = "1.0.7"
5
5
  end
6
6
  end
@@ -90,7 +90,7 @@ EOM
90
90
  "requirejs:clean"] do
91
91
  requirejs.config.source_dir.mkpath
92
92
  requirejs.env.each_logical_path do |logical_path|
93
- next unless logical_path =~ /\.js$/
93
+ next unless requirejs.config.asset_allowed?(logical_path)
94
94
  if asset = requirejs.env.find_asset(logical_path)
95
95
  filename = requirejs.config.source_dir + asset.logical_path
96
96
  filename.dirname.mkpath
@@ -37,6 +37,13 @@ class RequirejsRailsConfigTest < ActiveSupport::TestCase
37
37
  @cfg.loader = :wombat
38
38
  end
39
39
  end
40
+
41
+ test "matches configured logical assets" do
42
+ assert_equal true, @cfg.asset_allowed?('foo.js')
43
+ assert_equal false, @cfg.asset_allowed?('bar.frobnitz')
44
+ @cfg.logical_asset_filter += [/\.frobnitz$/]
45
+ assert_equal true, @cfg.asset_allowed?('bar.frobnitz')
46
+ end
40
47
  end
41
48
 
42
49
  class RequirejsHelperTest < ActionView::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requirejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70126226567640 !ruby/object:Gem::Requirement
16
+ requirement: &70315835618680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '3.3'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70126226567640
27
+ version_requirements: *70315835618680
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rails
30
- requirement: &70126226564660 !ruby/object:Gem::Requirement
30
+ requirement: &70315835617880 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '3.3'
39
39
  type: :development
40
40
  prerelease: false
41
- version_requirements: *70126226564660
41
+ version_requirements: *70315835617880
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: sqlite3
44
- requirement: &70126226563180 !ruby/object:Gem::Requirement
44
+ requirement: &70315835617240 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ! '>='
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
- version_requirements: *70126226563180
52
+ version_requirements: *70315835617240
53
53
  description: This gem provides RequireJS support for your Rails 3 application.
54
54
  email:
55
55
  - whitley@bangpath.org
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: 950199913290344440
132
+ hash: -430483900364221763
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: 950199913290344440
141
+ hash: -430483900364221763
142
142
  requirements:
143
143
  - node.js is required for 'rake assets:precompile', used to run the r.js build
144
144
  - If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17).