requirejs-rails 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +12 -3
- data/app/helpers/requirejs_helper.rb +11 -6
- data/lib/requirejs/rails/version.rb +1 -1
- data/test/requirejs-rails_test.rb +1 -2
- metadata +9 -9
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
|
|
14
14
|
|
15
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).
|
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>
|
@@ -22,8 +22,7 @@ Integrates [RequireJS](http://requirejs.org/) into the Rails 3 Asset Pipeline.
|
|
22
22
|
<head>
|
23
23
|
<title>Frobnitz Online</title>
|
24
24
|
<%= stylesheet_link_tag "application" %>
|
25
|
-
<%= requirejs_include_tag %>
|
26
|
-
<%= javascript_include_tag "application" %>
|
25
|
+
<%= requirejs_include_tag "application" %>
|
27
26
|
<%= csrf_meta_tags %>
|
28
27
|
<meta charset="utf-8">
|
29
28
|
</head>
|
@@ -122,6 +121,16 @@ Underscore version 1.2.2 or later has integrated AMD support. Get it from [Unde
|
|
122
121
|
|
123
122
|
Usage changes that impact folks upgrading along the 0.x series are documented here.
|
124
123
|
|
124
|
+
### v0.5.1
|
125
|
+
|
126
|
+
- `requirejs_include_tag` now generates a data-main attribute if given an argument, ala:
|
127
|
+
|
128
|
+
```erb
|
129
|
+
<%= requirejs_include_tag "application" %>
|
130
|
+
```
|
131
|
+
|
132
|
+
This usage is preferred to using a separate `javascript_include_tag`, which will produce errors from require.js or r.js if the included script uses define anonymously, or not at all.
|
133
|
+
|
125
134
|
### v0.5.0
|
126
135
|
|
127
136
|
- `application.js` is configured as the default top-level module for r.js builds.
|
@@ -1,7 +1,16 @@
|
|
1
1
|
require 'requirejs/error'
|
2
2
|
|
3
3
|
module RequirejsHelper
|
4
|
-
def
|
4
|
+
def _data_main(name)
|
5
|
+
if name
|
6
|
+
name += ".js" unless name =~ /\.js$/
|
7
|
+
%Q{data-main="#{javascript_path(name)}"}
|
8
|
+
else
|
9
|
+
""
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def requirejs_include_tag(name=nil)
|
5
14
|
html = ""
|
6
15
|
|
7
16
|
if controller.requirejs_included
|
@@ -11,13 +20,9 @@ module RequirejsHelper
|
|
11
20
|
<script>
|
12
21
|
var require = #{Rails.application.config.requirejs.run_config_json};
|
13
22
|
</script>
|
14
|
-
#{
|
23
|
+
<script #{_data_main name} src="#{javascript_path 'require.js'}"></script>
|
15
24
|
HTML
|
16
25
|
controller.requirejs_included = true
|
17
|
-
|
18
|
-
if tag
|
19
|
-
html << javascript_include_tag(tag)
|
20
|
-
end
|
21
26
|
html.html_safe
|
22
27
|
end
|
23
28
|
end
|
@@ -35,8 +35,7 @@ class RequirejsHelperTest < ActionView::TestCase
|
|
35
35
|
|
36
36
|
test "requirejs_include_tag_with_param" do
|
37
37
|
render :text => wrap(requirejs_include_tag("application"))
|
38
|
-
assert_select "script:
|
39
|
-
assert_select "script:last-of-type[src^=/javascripts/application.js]", :count => 1
|
38
|
+
assert_select "script:last-of-type[src^=/javascripts/require.js][data-main^=/javascripts/application.js]", :count => 1
|
40
39
|
end
|
41
40
|
|
42
41
|
test "requirejs_include_tag can appear only once" do
|
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70364520699460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70364520699460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70364520698260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.1
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70364520698260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70364520696860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70364520696860
|
47
47
|
description: This gem provides RequireJS support for your Rails 3 application.
|
48
48
|
email:
|
49
49
|
- whitley@bangpath.org
|
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
segments:
|
124
124
|
- 0
|
125
|
-
hash:
|
125
|
+
hash: -660159137027217743
|
126
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: -660159137027217743
|
135
135
|
requirements:
|
136
136
|
- node.js is required for 'rake assets:precompile', used to run the r.js build
|
137
137
|
- If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17).
|