requirejs-rails 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -3
- data/app/helpers/requirejs_helper.rb +12 -2
- data/lib/requirejs/error.rb +3 -1
- data/lib/requirejs/rails/config.rb +43 -18
- data/lib/requirejs/rails/engine.rb +28 -17
- data/lib/requirejs/rails/rjs_driver.js.erb +9 -19
- data/lib/requirejs/rails/version.rb +2 -1
- data/lib/tasks/requirejs-rails_tasks.rake +42 -85
- data/requirejs-rails.gemspec +1 -1
- data/test/requirejs-rails_test.rb +23 -1
- data/vendor/assets/javascripts/almond.js +277 -0
- metadata +11 -10
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# v0.7.0
|
2
|
+
|
3
|
+
- Support for [almond](https://github.com/jrburke/almond) via
|
4
|
+
`config.requirejs.loader = :almond` in application.rb.
|
5
|
+
- Builds with `config.assets.initialize_on_precompile = false` now work.
|
6
|
+
This supports building on Heroku, builds with Devise, etc. all of
|
7
|
+
which require that setting.
|
8
|
+
- We should now play much better with existing Rails Engines that
|
9
|
+
leverage the asset pipeline for their needs. Thanks to @hollow for the
|
10
|
+
patch.
|
11
|
+
|
1
12
|
# v0.6.1
|
2
13
|
|
3
14
|
- Fix regression in production env when `paths` specified in requirejs.yml.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -118,6 +118,25 @@ the configuration should be referenced by one of:
|
|
118
118
|
- Be a common library module like `appcommon`, listed in the `priority` config
|
119
119
|
option.
|
120
120
|
|
121
|
+
### Almond support
|
122
|
+
|
123
|
+
This gem supports single-file builds with
|
124
|
+
[almond](https://github.com/jrburke/almond). Use the following setting in
|
125
|
+
`application.rb` to enable it:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
config.requirejs.loader = :almond
|
129
|
+
```
|
130
|
+
|
131
|
+
Almond builds have the restriction that there must be exactly one modules entry in
|
132
|
+
`requirejs.yml`. Typically the [wrap option](https://github.com/jrburke/r.js/blob/master/build/example.build.js#L275) will be used to create a self-contained build:
|
133
|
+
|
134
|
+
```yaml
|
135
|
+
modules:
|
136
|
+
- name: 'main'
|
137
|
+
wrap: true
|
138
|
+
```
|
139
|
+
|
121
140
|
## Advanced features
|
122
141
|
|
123
142
|
### Additional data attributes
|
@@ -167,10 +186,11 @@ support and actively tracks mainline.
|
|
167
186
|
Underscore 1.3.x likewise doesn't have AMD support. Again, see
|
168
187
|
the [amdjs fork of Underscore](https://github.com/amdjs/underscore).
|
169
188
|
|
170
|
-
## Changes
|
189
|
+
## 0.x API Changes
|
171
190
|
|
172
|
-
Usage changes that
|
173
|
-
documented here. See [the Changelog](CHANGELOG.md) for
|
191
|
+
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
|
193
|
+
list of feature additions, bugfixes, etc.
|
174
194
|
|
175
195
|
### v0.5.1
|
176
196
|
|
@@ -24,9 +24,15 @@ module RequirejsHelper
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def requirejs_include_tag(name=nil, &block)
|
27
|
-
html = ""
|
28
27
|
requirejs = Rails.application.config.requirejs
|
29
28
|
|
29
|
+
if requirejs.loader == :almond
|
30
|
+
name = requirejs.module_name_for(requirejs.build_config['modules'][0])
|
31
|
+
return _almond_include_tag(name, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
html = ""
|
35
|
+
|
30
36
|
if controller.requirejs_included
|
31
37
|
raise Requirejs::MultipleIncludeError, "Only one requirejs_include_tag allowed per page."
|
32
38
|
end
|
@@ -34,7 +40,7 @@ module RequirejsHelper
|
|
34
40
|
unless requirejs.run_config.empty?
|
35
41
|
run_config = requirejs.run_config
|
36
42
|
if Rails.application.config.assets.digest
|
37
|
-
modules = requirejs.build_config['modules'].map { |m| m
|
43
|
+
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }
|
38
44
|
|
39
45
|
# Generate digestified paths from the modules spec
|
40
46
|
paths = {}
|
@@ -56,4 +62,8 @@ module RequirejsHelper
|
|
56
62
|
controller.requirejs_included = true
|
57
63
|
html.html_safe
|
58
64
|
end
|
65
|
+
|
66
|
+
def _almond_include_tag(name, &block)
|
67
|
+
"<script src='#{javascript_path name}'></script>\n".html_safe
|
68
|
+
end
|
59
69
|
end
|
data/lib/requirejs/error.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'requirejs/rails'
|
2
|
+
require 'requirejs/error'
|
2
3
|
|
3
4
|
require 'active_support/ordered_options'
|
4
5
|
require 'erubis'
|
@@ -6,8 +7,9 @@ require 'pathname'
|
|
6
7
|
|
7
8
|
module Requirejs::Rails
|
8
9
|
class Config < ::ActiveSupport::OrderedOptions
|
10
|
+
LOADERS = [ :requirejs, :almond ]
|
9
11
|
|
10
|
-
def initialize
|
12
|
+
def initialize
|
11
13
|
super
|
12
14
|
self.manifest = nil
|
13
15
|
|
@@ -18,18 +20,11 @@ module Requirejs::Rails
|
|
18
20
|
self.target_dir = Rails.root + 'public/assets'
|
19
21
|
self.rjs_path = self.bin_dir+'r.js'
|
20
22
|
|
23
|
+
self.loader = :requirejs
|
24
|
+
|
21
25
|
self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
|
22
26
|
self.driver_path = self.tmp_dir + 'rjs_driver.js'
|
23
27
|
|
24
|
-
# The user-supplied config parameters, to be merged with the default params.
|
25
|
-
# This file must contain a single JavaScript object.
|
26
|
-
self.user_config_file = Pathname.new(app.paths["config"].first)+'requirejs.yml'
|
27
|
-
if self.user_config_file.exist?
|
28
|
-
self.user_config = YAML.load(self.user_config_file.read)
|
29
|
-
else
|
30
|
-
self.user_config = {}
|
31
|
-
end
|
32
|
-
|
33
28
|
self.run_config_whitelist = %w{
|
34
29
|
baseUrl
|
35
30
|
callback
|
@@ -85,21 +80,51 @@ module Requirejs::Rails
|
|
85
80
|
}
|
86
81
|
end
|
87
82
|
|
83
|
+
def loader=(sym)
|
84
|
+
unless LOADERS.include?(sym)
|
85
|
+
raise Requirejs::ConfigError, "Attempt to set unknown loader: #{sym}"
|
86
|
+
end
|
87
|
+
self[:loader] = sym
|
88
|
+
end
|
89
|
+
|
88
90
|
def build_config
|
89
|
-
|
90
|
-
|
91
|
+
unless self.has_key?(:build_config)
|
92
|
+
self[:build_config] = self.run_config.merge "baseUrl" => source_dir.to_s,
|
93
|
+
"modules" => [ { 'name' => 'application' } ]
|
94
|
+
self[:build_config].merge!(self.user_config).slice!(*self.build_config_whitelist)
|
95
|
+
case self.loader
|
96
|
+
when :requirejs
|
97
|
+
# nothing to do
|
98
|
+
when :almond
|
99
|
+
mods = self[:build_config]['modules']
|
100
|
+
unless mods.length == 1
|
101
|
+
raise Requirejs::ConfigError, "Almond build requires exactly one module, config has #{mods.length}."
|
102
|
+
end
|
103
|
+
mod = mods[0]
|
104
|
+
name = mod['name']
|
105
|
+
mod['name'] = 'almond'
|
106
|
+
mod['include'] = name
|
107
|
+
end
|
108
|
+
end
|
109
|
+
self[:build_config]
|
91
110
|
end
|
92
111
|
|
93
112
|
def run_config
|
94
|
-
run_config = {
|
95
|
-
"baseUrl" => "/assets",
|
96
|
-
"modules" => [ { 'name' => 'application' } ]
|
97
|
-
}
|
113
|
+
run_config = { "baseUrl" => "/assets" }
|
98
114
|
run_config.merge!(self.user_config).slice(*self.run_config_whitelist)
|
99
115
|
end
|
100
116
|
|
101
|
-
def
|
102
|
-
self.
|
117
|
+
def module_name_for(mod)
|
118
|
+
case self.loader
|
119
|
+
when :almond
|
120
|
+
return mod['include']
|
121
|
+
when :requirejs
|
122
|
+
return mod['name']
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def module_path_for(mod)
|
127
|
+
self.target_dir+(module_name_for(mod)+'.js')
|
103
128
|
end
|
104
129
|
|
105
130
|
def get_binding
|
@@ -6,31 +6,42 @@ module Requirejs
|
|
6
6
|
module Rails
|
7
7
|
class Engine < ::Rails::Engine
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
9
|
+
### Configuration setup
|
10
|
+
config.before_configuration do |app|
|
11
|
+
config.requirejs = Requirejs::Rails::Config.new
|
12
|
+
config.requirejs.precompile = [/require\.js$/]
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
# Location of the user-supplied config parameters, which will be
|
15
|
+
# merged with the default params. It should be a YAML file with
|
16
|
+
# a single top-level hash, keys/values corresponding to require.js
|
17
|
+
# config parameters.
|
18
|
+
config.requirejs.user_config_file = Pathname.new(app.paths["config"].first)+'requirejs.yml'
|
19
|
+
if config.requirejs.user_config_file.exist?
|
20
|
+
config.requirejs.user_config = YAML.load(config.requirejs.user_config_file.read)
|
22
21
|
else
|
23
|
-
|
22
|
+
config.requirejs.user_config = {}
|
24
23
|
end
|
25
|
-
|
26
|
-
|
27
|
-
config.requirejs.precompile = [/require\.js$/]
|
24
|
+
end
|
28
25
|
|
26
|
+
config.before_initialize do |app|
|
27
|
+
config = app.config
|
29
28
|
if ::Rails.env == "production"
|
30
29
|
config.assets.precompile += config.requirejs.precompile
|
31
30
|
end
|
31
|
+
|
32
|
+
manifest_path = File.join(::Rails.public_path, config.assets.prefix, "rjs_manifest.yml")
|
33
|
+
config.requirejs.manifest_path = Pathname.new(manifest_path)
|
32
34
|
end
|
33
|
-
|
35
|
+
|
36
|
+
### Initializers
|
37
|
+
initializer "requirejs.tag_included_state" do |app|
|
38
|
+
ActiveSupport.on_load(:action_controller) do
|
39
|
+
::ActionController::Base.class_eval do
|
40
|
+
attr_accessor :requirejs_included
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
34
45
|
initializer "requirejs.manifest", :after => "sprockets.environment" do |app|
|
35
46
|
config = app.config
|
36
47
|
if config.requirejs.manifest_path.exist? && config.assets.digests
|
@@ -1,32 +1,22 @@
|
|
1
1
|
//Load the requirejs optimizer
|
2
2
|
var requirejs = require('<%= rjs_path %>'),
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
//Set up basic config, include config that is
|
4
|
+
//common to all the optimize() calls.
|
5
|
+
basConfig = <%= JSON.pretty_generate(build_config.reject {|k,v| k == 'modules'}) %>;
|
6
6
|
|
7
7
|
// Function used to mix in baseConfig to a new config target
|
8
8
|
function mix(target) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
9
|
+
for (var prop in basConfig) {
|
10
|
+
if (basConfig.hasOwnProperty(prop)) {
|
11
|
+
target[prop] = basConfig[prop];
|
13
12
|
}
|
14
|
-
|
13
|
+
}
|
14
|
+
return target;
|
15
15
|
}
|
16
16
|
|
17
17
|
var module_specs = [
|
18
18
|
<% build_config['modules'].each do |m| %>
|
19
|
-
|
20
|
-
name: "<%= m['name'] %>",
|
21
|
-
<% if m['include'] %>
|
22
|
-
include: [<%= m['include'].map {|i| "'#{i}'" }.join(", ") %>],
|
23
|
-
<% end %>
|
24
|
-
<% if m['exclude'] %>
|
25
|
-
exclude: [<%= m['exclude'].map {|i| "'#{i}'" }.join(", ") %>],
|
26
|
-
<% end %>
|
27
|
-
|
28
|
-
out: '<%= module_path_for m['name'] %>'
|
29
|
-
},
|
19
|
+
<%= JSON.pretty_generate(m.merge 'out' => module_path_for(m).to_s ) %>,
|
30
20
|
<% end %>
|
31
21
|
];
|
32
22
|
|
@@ -9,34 +9,8 @@ require 'tempfile'
|
|
9
9
|
|
10
10
|
require 'active_support/ordered_options'
|
11
11
|
|
12
|
-
# Prevent Sprockets::Bootstrap from making the environment immutable,
|
13
|
-
# as we need to manipulate the environment paths before the asset build.
|
14
|
-
#
|
15
|
-
# Without this, task requirejs:assets:purge_js throws an exception from
|
16
|
-
# Sprockets::Index#expire_index!, which is in response to any mutating
|
17
|
-
# method call.
|
18
|
-
#
|
19
|
-
if Rails.env == "production"
|
20
|
-
require 'sprockets/bootstrap'
|
21
|
-
module ::Sprockets
|
22
|
-
class Bootstrap
|
23
|
-
alias_method :orig_run, :run
|
24
|
-
def run(*args)
|
25
|
-
config = @app.config
|
26
|
-
saved_config_assets_digest = config.assets.digest
|
27
|
-
begin
|
28
|
-
config.assets.digest = false
|
29
|
-
orig_run(*args)
|
30
|
-
ensure
|
31
|
-
config.assets.digest = saved_config_assets_digest
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
12
|
namespace :requirejs do
|
39
|
-
|
13
|
+
|
40
14
|
# From Rails 3 assets.rake; we have the same problem:
|
41
15
|
#
|
42
16
|
# We are currently running with no explicit bundler group
|
@@ -49,38 +23,33 @@ namespace :requirejs do
|
|
49
23
|
Rake::Task[task].invoke
|
50
24
|
end
|
51
25
|
end
|
52
|
-
|
53
|
-
class String
|
54
|
-
def unindent
|
55
|
-
gsub /^#{self[/\A\s*/]}/, ''
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
26
|
+
|
59
27
|
requirejs = ActiveSupport::OrderedOptions.new
|
60
|
-
|
28
|
+
|
61
29
|
task :clean => ["requirejs:setup"] do
|
62
30
|
FileUtils.remove_entry_secure(requirejs.config.source_dir, true)
|
63
31
|
FileUtils.remove_entry_secure(requirejs.driver_path, true)
|
64
32
|
end
|
65
33
|
|
66
|
-
task :setup => ["environment"] do
|
34
|
+
task :setup => ["assets:environment"] do
|
67
35
|
unless Rails.application.config.assets.enabled
|
68
36
|
warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
|
69
37
|
exit
|
70
38
|
end
|
71
|
-
|
39
|
+
|
72
40
|
# Ensure that action view is loaded and the appropriate
|
73
41
|
# sprockets hooks get executed
|
74
42
|
_ = ActionView::Base
|
75
43
|
|
76
44
|
requirejs.env = Rails.application.assets
|
45
|
+
|
77
46
|
# Preserve the original asset paths, as we'll be manipulating them later
|
78
47
|
requirejs.env_paths = requirejs.env.paths.dup
|
79
48
|
requirejs.config = Rails.application.config.requirejs
|
80
49
|
requirejs.builder = Requirejs::Rails::Builder.new(requirejs.config)
|
81
50
|
requirejs.manifest = {}
|
82
51
|
end
|
83
|
-
|
52
|
+
|
84
53
|
task :test_node do
|
85
54
|
begin
|
86
55
|
`node -v`
|
@@ -93,38 +62,48 @@ EOM
|
|
93
62
|
exit 1
|
94
63
|
end
|
95
64
|
end
|
96
|
-
|
65
|
+
|
97
66
|
namespace :precompile do
|
98
|
-
|
67
|
+
task :all => ["requirejs:precompile:prepare_source",
|
68
|
+
"requirejs:precompile:generate_rjs_driver",
|
69
|
+
"requirejs:precompile:run_rjs",
|
70
|
+
"requirejs:precompile:digestify_and_compress"]
|
71
|
+
|
72
|
+
task :disable_js_compressor do
|
73
|
+
# Ensure that Sprockets doesn't try to compress assets before they hit
|
74
|
+
# r.js. Failure to do this can cause a build which works in dev, but
|
75
|
+
# emits require.js "notloaded" errors, etc. in production.
|
76
|
+
Rails.application.config.assets.js_compressor = false
|
77
|
+
end
|
78
|
+
|
79
|
+
# Invoke another ruby process if we're called from inside
|
80
|
+
# assets:precompile so we don't clobber the environment
|
99
81
|
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
task :
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
task :prepare_source => ["requirejs:setup",
|
110
|
-
"requirejs:clean",
|
111
|
-
"requirejs:assets:keep_js"] do
|
82
|
+
# We depend on test_node here so we'll fail early and hard if node
|
83
|
+
# isn't available.
|
84
|
+
task :external => ["requirejs:test_node"] do
|
85
|
+
ruby_rake_task "requirejs:precompile:all"
|
86
|
+
end
|
87
|
+
|
88
|
+
# copy all assets to tmp/assets
|
89
|
+
task :prepare_source => ["requirejs:setup",
|
90
|
+
"requirejs:clean"] do
|
112
91
|
requirejs.config.source_dir.mkpath
|
113
92
|
requirejs.env.each_logical_path do |logical_path|
|
93
|
+
next unless logical_path =~ /\.js$/
|
114
94
|
if asset = requirejs.env.find_asset(logical_path)
|
115
95
|
filename = requirejs.config.source_dir + asset.logical_path
|
116
96
|
filename.dirname.mkpath
|
117
|
-
|
118
97
|
asset.write_to(filename)
|
119
98
|
end
|
120
99
|
end
|
121
100
|
end
|
122
|
-
|
101
|
+
|
123
102
|
task :generate_rjs_driver => ["requirejs:setup"] do
|
124
103
|
requirejs.builder.generate_rjs_driver
|
125
104
|
end
|
126
105
|
|
127
|
-
task :run_rjs => ["requirejs:setup",
|
106
|
+
task :run_rjs => ["requirejs:setup",
|
128
107
|
"requirejs:test_node"] do
|
129
108
|
requirejs.config.target_dir.mkpath
|
130
109
|
|
@@ -133,12 +112,12 @@ EOM
|
|
133
112
|
raise RuntimeError, "Asset compilation with node failed."
|
134
113
|
end
|
135
114
|
end
|
136
|
-
|
137
|
-
# Copy each built asset, identified by a named module in the
|
115
|
+
|
116
|
+
# Copy each built asset, identified by a named module in the
|
138
117
|
# build config, to its Sprockets digestified name.
|
139
118
|
task :digestify_and_compress => ["requirejs:setup"] do
|
140
119
|
requirejs.config.build_config['modules'].each do |m|
|
141
|
-
asset_name = "#{m
|
120
|
+
asset_name = "#{requirejs.config.module_name_for(m)}.js"
|
142
121
|
built_asset_path = requirejs.config.target_dir + asset_name
|
143
122
|
digest_name = asset_name.sub(/\.(\w+)$/) { |ext| "-#{requirejs.builder.digest_for(built_asset_path)}#{ext}" }
|
144
123
|
digest_asset_path = requirejs.config.target_dir + digest_name
|
@@ -156,7 +135,7 @@ EOM
|
|
156
135
|
requirejs.config.manifest_path.open('wb') do |f|
|
157
136
|
YAML.dump(requirejs.manifest,f)
|
158
137
|
end
|
159
|
-
end
|
138
|
+
end
|
160
139
|
end
|
161
140
|
end
|
162
141
|
|
@@ -164,31 +143,9 @@ EOM
|
|
164
143
|
task :precompile do
|
165
144
|
invoke_or_reboot_rake_task "requirejs:precompile:all"
|
166
145
|
end
|
167
|
-
|
168
|
-
# We remove all .js assets from the Rails Asset Pipeline when
|
169
|
-
# precompiling, as those are handled by r.js. Conversely, r.js
|
170
|
-
# only sees .js assets. For now, this is by path convention; any
|
171
|
-
# asset path ending in "javascript". If you've got javascripts in
|
172
|
-
# your stylesheets directory, then heaven help you. You've got bigger
|
173
|
-
# problems.
|
174
|
-
namespace :assets do
|
175
|
-
# Purge all ".../javascripts" directories from the asset paths
|
176
|
-
task :purge_js => ["requirejs:setup"] do
|
177
|
-
new_paths = requirejs.env_paths.dup.delete_if { |p| p =~ /javascripts$/ && p !~ /requirejs-rails/ }
|
178
|
-
requirejs.env.clear_paths
|
179
|
-
new_paths.each { |p| requirejs.env.append_path(p) }
|
180
|
-
end
|
181
|
-
|
182
|
-
# Preserve only ".../javascripts" directories
|
183
|
-
task :keep_js => ["requirejs:setup"] do
|
184
|
-
new_paths = requirejs.env_paths.dup.keep_if { |p| p =~ /javascripts$/ }
|
185
|
-
requirejs.env.clear_paths
|
186
|
-
new_paths.each { |p| requirejs.env.append_path(p) }
|
187
|
-
end
|
188
|
-
end
|
189
146
|
end
|
190
147
|
|
191
|
-
task "assets:precompile
|
192
|
-
|
193
|
-
task "assets:
|
194
|
-
|
148
|
+
task "assets:precompile" => ["requirejs:precompile:external"]
|
149
|
+
if ARGV[0] == "requirejs:precompile:all"
|
150
|
+
task "assets:environment" => ["requirejs:precompile:disable_js_compressor"]
|
151
|
+
end
|
data/requirejs-rails.gemspec
CHANGED
@@ -6,7 +6,7 @@ require "requirejs/rails/version"
|
|
6
6
|
# Describe your gem and declare its dependencies:
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "requirejs-rails"
|
9
|
-
s.version = Requirejs::Rails::
|
9
|
+
s.version = Requirejs::Rails::Version
|
10
10
|
s.authors = ["John Whitley"]
|
11
11
|
s.email = ["whitley@bangpath.org"]
|
12
12
|
s.homepage = "http://github.com/jwhitley/requirejs-rails"
|
@@ -13,7 +13,29 @@ class RequirejsRailsTest < ActiveSupport::TestCase
|
|
13
13
|
test "require.js version" do
|
14
14
|
require_js = Pathname.new(__FILE__+'/../../vendor/assets/javascripts/require.js').cleanpath.read
|
15
15
|
context = ExecJS.compile(require_js)
|
16
|
-
assert_equal
|
16
|
+
assert_equal Requirejs::Rails::LibVersion, context.eval("require.version")
|
17
|
+
end
|
18
|
+
|
19
|
+
test "CHANGELOG up to date" do
|
20
|
+
changelog_match = (/^# v#{Requirejs::Rails::Version}/ =~ Pathname.new(__FILE__+'/../../CHANGELOG.md').cleanpath.read)
|
21
|
+
assert changelog_match, "CHANGELOG has no section for v#{Requirejs::Rails::Version}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class RequirejsRailsConfigTest < ActiveSupport::TestCase
|
26
|
+
def setup
|
27
|
+
@cfg = Requirejs::Rails::Config.new
|
28
|
+
end
|
29
|
+
|
30
|
+
test "config accepts known loaders" do
|
31
|
+
@cfg.loader = :almond
|
32
|
+
assert_equal :almond, @cfg.loader
|
33
|
+
end
|
34
|
+
|
35
|
+
test "config rejects bad loaders" do
|
36
|
+
assert_raises Requirejs::ConfigError do
|
37
|
+
@cfg.loader = :wombat
|
38
|
+
end
|
17
39
|
end
|
18
40
|
end
|
19
41
|
|
@@ -0,0 +1,277 @@
|
|
1
|
+
/**
|
2
|
+
* almond 0.0.3 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
|
3
|
+
* Available via the MIT or new BSD license.
|
4
|
+
* see: http://github.com/jrburke/almond for details
|
5
|
+
*/
|
6
|
+
/*jslint strict: false, plusplus: false */
|
7
|
+
/*global setTimeout: false */
|
8
|
+
|
9
|
+
var requirejs, require, define;
|
10
|
+
(function (undef) {
|
11
|
+
|
12
|
+
var defined = {},
|
13
|
+
waiting = {},
|
14
|
+
aps = [].slice,
|
15
|
+
main, req;
|
16
|
+
|
17
|
+
if (typeof define === "function") {
|
18
|
+
//If a define is already in play via another AMD loader,
|
19
|
+
//do not overwrite.
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Given a relative module name, like ./something, normalize it to
|
25
|
+
* a real name that can be mapped to a path.
|
26
|
+
* @param {String} name the relative name
|
27
|
+
* @param {String} baseName a real name that the name arg is relative
|
28
|
+
* to.
|
29
|
+
* @returns {String} normalized name
|
30
|
+
*/
|
31
|
+
function normalize(name, baseName) {
|
32
|
+
//Adjust any relative paths.
|
33
|
+
if (name && name.charAt(0) === ".") {
|
34
|
+
//If have a base name, try to normalize against it,
|
35
|
+
//otherwise, assume it is a top-level require that will
|
36
|
+
//be relative to baseUrl in the end.
|
37
|
+
if (baseName) {
|
38
|
+
//Convert baseName to array, and lop off the last part,
|
39
|
+
//so that . matches that "directory" and not name of the baseName's
|
40
|
+
//module. For instance, baseName of "one/two/three", maps to
|
41
|
+
//"one/two/three.js", but we want the directory, "one/two" for
|
42
|
+
//this normalization.
|
43
|
+
baseName = baseName.split("/");
|
44
|
+
baseName = baseName.slice(0, baseName.length - 1);
|
45
|
+
|
46
|
+
name = baseName.concat(name.split("/"));
|
47
|
+
|
48
|
+
//start trimDots
|
49
|
+
var i, part;
|
50
|
+
for (i = 0; (part = name[i]); i++) {
|
51
|
+
if (part === ".") {
|
52
|
+
name.splice(i, 1);
|
53
|
+
i -= 1;
|
54
|
+
} else if (part === "..") {
|
55
|
+
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
56
|
+
//End of the line. Keep at least one non-dot
|
57
|
+
//path segment at the front so it can be mapped
|
58
|
+
//correctly to disk. Otherwise, there is likely
|
59
|
+
//no path mapping for a path starting with '..'.
|
60
|
+
//This can still fail, but catches the most reasonable
|
61
|
+
//uses of ..
|
62
|
+
break;
|
63
|
+
} else if (i > 0) {
|
64
|
+
name.splice(i - 1, 2);
|
65
|
+
i -= 2;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
//end trimDots
|
70
|
+
|
71
|
+
name = name.join("/");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return name;
|
75
|
+
}
|
76
|
+
|
77
|
+
function makeRequire(relName, forceSync) {
|
78
|
+
return function () {
|
79
|
+
//A version of a require function that passes a moduleName
|
80
|
+
//value for items that may need to
|
81
|
+
//look up paths relative to the moduleName
|
82
|
+
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
83
|
+
};
|
84
|
+
}
|
85
|
+
|
86
|
+
function makeNormalize(relName) {
|
87
|
+
return function (name) {
|
88
|
+
return normalize(name, relName);
|
89
|
+
};
|
90
|
+
}
|
91
|
+
|
92
|
+
function makeLoad(depName) {
|
93
|
+
return function (value) {
|
94
|
+
defined[depName] = value;
|
95
|
+
};
|
96
|
+
}
|
97
|
+
|
98
|
+
function callDep(name) {
|
99
|
+
if (waiting.hasOwnProperty(name)) {
|
100
|
+
var args = waiting[name];
|
101
|
+
delete waiting[name];
|
102
|
+
main.apply(undef, args);
|
103
|
+
}
|
104
|
+
return defined[name];
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Makes a name map, normalizing the name, and using a plugin
|
109
|
+
* for normalization if necessary. Grabs a ref to plugin
|
110
|
+
* too, as an optimization.
|
111
|
+
*/
|
112
|
+
function makeMap(name, relName) {
|
113
|
+
var prefix, plugin,
|
114
|
+
index = name.indexOf('!');
|
115
|
+
|
116
|
+
if (index !== -1) {
|
117
|
+
prefix = normalize(name.slice(0, index), relName);
|
118
|
+
name = name.slice(index + 1);
|
119
|
+
plugin = callDep(prefix);
|
120
|
+
|
121
|
+
//Normalize according
|
122
|
+
if (plugin && plugin.normalize) {
|
123
|
+
name = plugin.normalize(name, makeNormalize(relName));
|
124
|
+
} else {
|
125
|
+
name = normalize(name, relName);
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
name = normalize(name, relName);
|
129
|
+
}
|
130
|
+
|
131
|
+
//Using ridiculous property names for space reasons
|
132
|
+
return {
|
133
|
+
f: prefix ? prefix + '!' + name : name, //fullName
|
134
|
+
n: name,
|
135
|
+
p: plugin
|
136
|
+
};
|
137
|
+
}
|
138
|
+
|
139
|
+
main = function (name, deps, callback, relName) {
|
140
|
+
var args = [],
|
141
|
+
usingExports,
|
142
|
+
cjsModule, depName, i, ret, map;
|
143
|
+
|
144
|
+
//Use name if no relName
|
145
|
+
if (!relName) {
|
146
|
+
relName = name;
|
147
|
+
}
|
148
|
+
|
149
|
+
//Call the callback to define the module, if necessary.
|
150
|
+
if (typeof callback === 'function') {
|
151
|
+
|
152
|
+
//Default to require, exports, module if no deps if
|
153
|
+
//the factory arg has any arguments specified.
|
154
|
+
if (!deps.length && callback.length) {
|
155
|
+
deps = ['require', 'exports', 'module'];
|
156
|
+
}
|
157
|
+
|
158
|
+
//Pull out the defined dependencies and pass the ordered
|
159
|
+
//values to the callback.
|
160
|
+
for (i = 0; i < deps.length; i++) {
|
161
|
+
map = makeMap(deps[i], relName);
|
162
|
+
depName = map.f;
|
163
|
+
|
164
|
+
//Fast path CommonJS standard dependencies.
|
165
|
+
if (depName === "require") {
|
166
|
+
args[i] = makeRequire(name);
|
167
|
+
} else if (depName === "exports") {
|
168
|
+
//CommonJS module spec 1.1
|
169
|
+
args[i] = defined[name] = {};
|
170
|
+
usingExports = true;
|
171
|
+
} else if (depName === "module") {
|
172
|
+
//CommonJS module spec 1.1
|
173
|
+
cjsModule = args[i] = {
|
174
|
+
id: name,
|
175
|
+
uri: '',
|
176
|
+
exports: defined[name]
|
177
|
+
};
|
178
|
+
} else if (defined.hasOwnProperty(depName) || waiting.hasOwnProperty(depName)) {
|
179
|
+
args[i] = callDep(depName);
|
180
|
+
} else if (map.p) {
|
181
|
+
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
182
|
+
args[i] = defined[depName];
|
183
|
+
} else {
|
184
|
+
throw name + ' missing ' + depName;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
ret = callback.apply(defined[name], args);
|
189
|
+
|
190
|
+
if (name) {
|
191
|
+
//If setting exports via "module" is in play,
|
192
|
+
//favor that over return value and exports. After that,
|
193
|
+
//favor a non-undefined return value over exports use.
|
194
|
+
if (cjsModule && cjsModule.exports !== undef) {
|
195
|
+
defined[name] = cjsModule.exports;
|
196
|
+
} else if (!usingExports) {
|
197
|
+
//Use the return value from the function.
|
198
|
+
defined[name] = ret;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
} else if (name) {
|
202
|
+
//May just be an object definition for the module. Only
|
203
|
+
//worry about defining if have a module name.
|
204
|
+
defined[name] = callback;
|
205
|
+
}
|
206
|
+
};
|
207
|
+
|
208
|
+
requirejs = req = function (deps, callback, relName, forceSync) {
|
209
|
+
if (typeof deps === "string") {
|
210
|
+
|
211
|
+
//Just return the module wanted. In this scenario, the
|
212
|
+
//deps arg is the module name, and second arg (if passed)
|
213
|
+
//is just the relName.
|
214
|
+
//Normalize module name, if it contains . or ..
|
215
|
+
return callDep(makeMap(deps, callback).f);
|
216
|
+
} else if (!deps.splice) {
|
217
|
+
//deps is a config object, not an array.
|
218
|
+
//Drop the config stuff on the ground.
|
219
|
+
if (callback.splice) {
|
220
|
+
//callback is an array, which means it is a dependency list.
|
221
|
+
//Adjust args if there are dependencies
|
222
|
+
deps = callback;
|
223
|
+
callback = arguments[2];
|
224
|
+
} else {
|
225
|
+
deps = [];
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
//Simulate async callback;
|
230
|
+
if (forceSync) {
|
231
|
+
main(undef, deps, callback, relName);
|
232
|
+
} else {
|
233
|
+
setTimeout(function () {
|
234
|
+
main(undef, deps, callback, relName);
|
235
|
+
}, 15);
|
236
|
+
}
|
237
|
+
|
238
|
+
return req;
|
239
|
+
};
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Just drops the config on the floor, but returns req in case
|
243
|
+
* the config return value is used.
|
244
|
+
*/
|
245
|
+
req.config = function () {
|
246
|
+
return req;
|
247
|
+
};
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Export require as a global, but only if it does not already exist.
|
251
|
+
*/
|
252
|
+
if (!require) {
|
253
|
+
require = req;
|
254
|
+
}
|
255
|
+
|
256
|
+
define = function (name, deps, callback) {
|
257
|
+
|
258
|
+
//This module may not have dependencies
|
259
|
+
if (!deps.splice) {
|
260
|
+
//deps is not an array, so probably means
|
261
|
+
//an object literal or factory function for
|
262
|
+
//the value. Adjust args.
|
263
|
+
callback = deps;
|
264
|
+
deps = [];
|
265
|
+
}
|
266
|
+
|
267
|
+
if (define.unordered) {
|
268
|
+
waiting[name] = [name, deps, callback];
|
269
|
+
} else {
|
270
|
+
main(name, deps, callback);
|
271
|
+
}
|
272
|
+
};
|
273
|
+
|
274
|
+
define.amd = {
|
275
|
+
jQuery: true
|
276
|
+
};
|
277
|
+
}());
|
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.
|
4
|
+
version: 0.7.0
|
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-
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70126226567640 !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: *
|
27
|
+
version_requirements: *70126226567640
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rails
|
30
|
-
requirement: &
|
30
|
+
requirement: &70126226564660 !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: *
|
41
|
+
version_requirements: *70126226564660
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: sqlite3
|
44
|
-
requirement: &
|
44
|
+
requirement: &70126226563180 !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: *
|
52
|
+
version_requirements: *70126226563180
|
53
53
|
description: This gem provides RequireJS support for your Rails 3 application.
|
54
54
|
email:
|
55
55
|
- whitley@bangpath.org
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/requirejs/rails/version.rb
|
78
78
|
- lib/tasks/requirejs-rails_tasks.rake
|
79
79
|
- requirejs-rails.gemspec
|
80
|
+
- vendor/assets/javascripts/almond.js
|
80
81
|
- vendor/assets/javascripts/order.js
|
81
82
|
- vendor/assets/javascripts/require.js
|
82
83
|
- test/dummy/.rvmrc
|
@@ -128,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
129
|
version: '0'
|
129
130
|
segments:
|
130
131
|
- 0
|
131
|
-
hash:
|
132
|
+
hash: 950199913290344440
|
132
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
134
|
none: false
|
134
135
|
requirements:
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
segments:
|
139
140
|
- 0
|
140
|
-
hash:
|
141
|
+
hash: 950199913290344440
|
141
142
|
requirements:
|
142
143
|
- node.js is required for 'rake assets:precompile', used to run the r.js build
|
143
144
|
- If needed, jQuery should be v1.7 or greater (jquery-rails >= 1.0.17).
|