requirejs-rails 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +50 -46
- data/app/helpers/requirejs_helper.rb +13 -11
- data/bin/r.js +2226 -2045
- data/lib/requirejs/rails/config.rb +3 -6
- data/lib/requirejs/rails/engine.rb +4 -3
- data/lib/requirejs/rails/rjs_driver.js.erb +19 -40
- data/lib/requirejs/rails/version.rb +2 -2
- data/lib/tasks/requirejs-rails_tasks.rake +48 -18
- data/requirejs-rails.gemspec +1 -1
- data/vendor/assets/javascripts/require.js +48 -40
- metadata +4 -3
@@ -17,14 +17,15 @@ module Requirejs::Rails
|
|
17
17
|
self.tmp_dir = application.root + 'tmp'
|
18
18
|
self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath
|
19
19
|
|
20
|
-
self.source_dir = self.tmp_dir
|
20
|
+
self.source_dir = self.tmp_dir.join("requirejs/src")
|
21
|
+
self.build_dir = self.tmp_dir.join("requirejs/dst")
|
21
22
|
self.target_dir = application.root + 'public/assets'
|
22
23
|
self.rjs_path = self.bin_dir+'r.js'
|
23
24
|
|
24
25
|
self.loader = :requirejs
|
25
26
|
|
26
27
|
self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
|
27
|
-
self.driver_path = self.tmp_dir
|
28
|
+
self.driver_path = self.tmp_dir.join("requirejs/rjs_driver.js")
|
28
29
|
|
29
30
|
self.user_config = {}
|
30
31
|
|
@@ -142,10 +143,6 @@ module Requirejs::Rails
|
|
142
143
|
end
|
143
144
|
end
|
144
145
|
|
145
|
-
def module_path_for(mod)
|
146
|
-
self.target_dir+(module_name_for(mod)+'.js')
|
147
|
-
end
|
148
|
-
|
149
146
|
def get_binding
|
150
147
|
return binding()
|
151
148
|
end
|
@@ -20,12 +20,13 @@ module Requirejs
|
|
20
20
|
|
21
21
|
config.assets.precompile += config.requirejs.precompile
|
22
22
|
|
23
|
-
# Check for the
|
24
|
-
# compression to ensure that `r.js` gets uncompressed assets.
|
23
|
+
# Check for the `requirejs:precompile:all` top-level Rake task and run the following initialization code.
|
25
24
|
Rake.application.top_level_tasks.each do |task_name|
|
26
25
|
case task_name
|
27
26
|
when "requirejs:precompile:all"
|
28
|
-
|
27
|
+
# Enable class reloading so that Sprockets doesn't freeze the assets environment. This allows settings
|
28
|
+
# for JS compression to be changes on a per-file basis.
|
29
|
+
config.cache_classes = false
|
29
30
|
end
|
30
31
|
end if defined?(Rake.application)
|
31
32
|
|
@@ -1,46 +1,25 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
4
|
-
//common to all the optimize() calls.
|
5
|
-
baseConfig = <%=
|
6
|
-
modifiedHash = build_config.select {|k, _| k != "modules"}
|
7
|
-
pathsHash = modifiedHash["paths"]
|
8
|
-
modifiedHash["paths"] = pathsHash.select {|_, v| !v.is_a?(Array)} if !pathsHash.nil?
|
1
|
+
var requirejs = require(<%= rjs_path.to_s.dump %>)
|
2
|
+
var baseConfig = <%=
|
3
|
+
cdn_pattern = Regexp.new("\\Ahttps?://")
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
modifiedHash = build_config.select { |k, _| k != "modules" }
|
6
|
+
pathsHash = modifiedHash["paths"]
|
7
|
+
modifiedHash["dir"] = build_dir.to_s
|
8
|
+
modifiedHash["paths"] = Hash[pathsHash
|
9
|
+
.select do |_, v|
|
10
|
+
!v.is_a?(Array)
|
11
|
+
end.map do |k, v|
|
12
|
+
[k, if !cdn_pattern.match(v) then v else "empty:" end]
|
13
|
+
end
|
14
|
+
] if !pathsHash.nil?
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
for (var prop in baseConfig) {
|
16
|
-
if (baseConfig.hasOwnProperty(prop)) {
|
17
|
-
target[prop] = baseConfig[prop];
|
18
|
-
}
|
19
|
-
}
|
20
|
-
return target;
|
21
|
-
}
|
16
|
+
JSON.pretty_generate(modifiedHash)
|
17
|
+
%>;
|
22
18
|
|
23
|
-
|
24
|
-
<% build_config[
|
25
|
-
<%= JSON.pretty_generate(m
|
19
|
+
baseConfig.modules = [
|
20
|
+
<% build_config["modules"].each do |m| %>
|
21
|
+
<%= JSON.pretty_generate(m) %>,
|
26
22
|
<% end %>
|
27
23
|
];
|
28
24
|
|
29
|
-
|
30
|
-
var errback = function(error) {
|
31
|
-
process.stderr.write(error.toString());
|
32
|
-
process.exit(1);
|
33
|
-
}
|
34
|
-
|
35
|
-
// Do a series of builds of individual files, using the args suggested by:
|
36
|
-
// http://requirejs.org/docs/optimization.html#onejs
|
37
|
-
//
|
38
|
-
// r.js will eventually need a nested call idiom to handle async
|
39
|
-
// builds. Anticipating that need.
|
40
|
-
var async_runner = module_specs.reduceRight(function(prev, curr) {
|
41
|
-
return function (buildReportText) {
|
42
|
-
requirejs.optimize(mix(curr), prev, errback);
|
43
|
-
};
|
44
|
-
}, function(buildReportText) {} );
|
45
|
-
|
46
|
-
async_runner();
|
25
|
+
requirejs.optimize(baseConfig);
|
@@ -34,12 +34,12 @@ namespace :requirejs do
|
|
34
34
|
|
35
35
|
requirejs = ActiveSupport::OrderedOptions.new
|
36
36
|
|
37
|
-
task :
|
37
|
+
task clean: ["requirejs:setup"] do
|
38
38
|
FileUtils.remove_entry_secure(requirejs.config.source_dir, true)
|
39
39
|
FileUtils.remove_entry_secure(requirejs.driver_path, true)
|
40
40
|
end
|
41
41
|
|
42
|
-
task :
|
42
|
+
task setup: ["assets:environment"] do
|
43
43
|
unless defined?(Sprockets)
|
44
44
|
warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
|
45
45
|
exit
|
@@ -72,41 +72,67 @@ OS X Homebrew users can use 'brew install node'.
|
|
72
72
|
end
|
73
73
|
|
74
74
|
namespace :precompile do
|
75
|
-
task :
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
task all: ["requirejs:precompile:prepare_source",
|
76
|
+
"requirejs:precompile:generate_rjs_driver",
|
77
|
+
"requirejs:precompile:run_rjs",
|
78
|
+
"requirejs:precompile:digestify_and_compress"]
|
79
79
|
|
80
80
|
# Invoke another ruby process if we're called from inside
|
81
81
|
# assets:precompile so we don't clobber the environment
|
82
82
|
#
|
83
83
|
# We depend on test_node here so we'll fail early and hard if node
|
84
84
|
# isn't available.
|
85
|
-
task :
|
85
|
+
task external: ["requirejs:test_node"] do
|
86
86
|
ruby_rake_task "requirejs:precompile:all"
|
87
87
|
end
|
88
88
|
|
89
|
-
#
|
90
|
-
task :
|
91
|
-
|
89
|
+
# Copy all assets to the temporary staging directory.
|
90
|
+
task prepare_source: ["requirejs:setup",
|
91
|
+
"requirejs:clean"] do
|
92
|
+
bower_json_pattern = Regexp.new("\\A(.*)/bower\\.json\\z")
|
93
|
+
js_ext = requirejs.env.extension_for_mime_type("application/javascript")
|
94
|
+
|
92
95
|
requirejs.config.source_dir.mkpath
|
96
|
+
|
97
|
+
# Save the original JS compressor and cache, which will be restored later.
|
98
|
+
|
99
|
+
original_js_compressor = requirejs.env.js_compressor
|
100
|
+
requirejs.env.js_compressor = false
|
101
|
+
|
102
|
+
original_cache = requirejs.env.cache
|
103
|
+
requirejs.env.cache = nil
|
104
|
+
|
93
105
|
requirejs.env.each_logical_path do |logical_path|
|
94
|
-
|
95
|
-
|
96
|
-
|
106
|
+
m = bower_json_pattern.match(logical_path)
|
107
|
+
bower_logical_path = m && "#{m[1]}#{js_ext}"
|
108
|
+
|
109
|
+
next \
|
110
|
+
if !(requirejs.config.asset_allowed?(logical_path) || bower_logical_path)
|
111
|
+
|
112
|
+
asset = requirejs.env.find_asset(logical_path)
|
113
|
+
|
114
|
+
if asset
|
115
|
+
# If a `bower.json` was found, then substitute the logical path with the parsed module name.
|
116
|
+
filename = requirejs.config.source_dir.join(bower_logical_path || asset.logical_path)
|
97
117
|
filename.dirname.mkpath
|
98
118
|
asset.write_to(filename)
|
99
119
|
end
|
100
120
|
end
|
121
|
+
|
122
|
+
# Restore the original JS compressor and cache.
|
123
|
+
requirejs.env.js_compressor = original_js_compressor
|
124
|
+
requirejs.env.cache = original_cache
|
101
125
|
end
|
102
126
|
|
103
|
-
task :
|
127
|
+
task generate_rjs_driver: ["requirejs:setup"] do
|
104
128
|
requirejs.builder.generate_rjs_driver
|
105
129
|
end
|
106
130
|
|
107
|
-
task :
|
108
|
-
|
131
|
+
task run_rjs: ["requirejs:setup",
|
132
|
+
"requirejs:test_node"] do
|
133
|
+
requirejs.config.build_dir.mkpath
|
109
134
|
requirejs.config.target_dir.mkpath
|
135
|
+
requirejs.config.driver_path.dirname.mkpath
|
110
136
|
|
111
137
|
result = `node "#{requirejs.config.driver_path}"`
|
112
138
|
unless $?.success?
|
@@ -116,12 +142,16 @@ OS X Homebrew users can use 'brew install node'.
|
|
116
142
|
|
117
143
|
# Copy each built asset, identified by a named module in the
|
118
144
|
# build config, to its Sprockets digestified name.
|
119
|
-
task :
|
145
|
+
task digestify_and_compress: ["requirejs:setup"] do
|
120
146
|
requirejs.config.build_config['modules'].each do |m|
|
121
147
|
asset_name = "#{requirejs.config.module_name_for(m)}.js"
|
122
|
-
built_asset_path = requirejs.config.
|
148
|
+
built_asset_path = requirejs.config.build_dir.join(asset_name)
|
123
149
|
digest_name = asset_name.sub(/\.(\w+)$/) { |ext| "-#{requirejs.builder.digest_for(built_asset_path)}#{ext}" }
|
124
150
|
digest_asset_path = requirejs.config.target_dir + digest_name
|
151
|
+
|
152
|
+
# Ensure that the parent directory `a/b` for modules with names like `a/b/c` exist.
|
153
|
+
digest_asset_path.dirname.mkpath
|
154
|
+
|
125
155
|
requirejs.manifest[asset_name] = digest_name
|
126
156
|
FileUtils.cp built_asset_path, digest_asset_path
|
127
157
|
|
data/requirejs-rails.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ["John Whitley"]
|
11
11
|
s.email = ["whitley@bangpath.org"]
|
12
12
|
s.homepage = "http://github.com/jwhitley/requirejs-rails"
|
13
|
-
s.summary = "Use RequireJS with the Rails 3 Asset Pipeline"
|
13
|
+
s.summary = "Use RequireJS with the Rails 3+ Asset Pipeline"
|
14
14
|
s.description = "This gem provides RequireJS support for your Rails 3 application."
|
15
15
|
|
16
16
|
git_test_files, git_files = `git ls-files`.split("\n").partition { |f| f =~ /^test/ }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/** vim: et:ts=4:sw=4:sts=4
|
2
|
-
* @license RequireJS 2.1.
|
2
|
+
* @license RequireJS 2.1.14 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
3
3
|
* Available via the MIT or new BSD license.
|
4
4
|
* see: http://github.com/jrburke/requirejs for details
|
5
5
|
*/
|
@@ -12,7 +12,7 @@ var requirejs, require, define;
|
|
12
12
|
(function (global) {
|
13
13
|
var req, s, head, baseElement, dataMain, src,
|
14
14
|
interactiveScript, currentlyAddingScript, mainScript, subPath,
|
15
|
-
version = '2.1.
|
15
|
+
version = '2.1.14',
|
16
16
|
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
|
17
17
|
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
|
18
18
|
jsSuffixRegExp = /\.js$/,
|
@@ -180,7 +180,7 @@ var requirejs, require, define;
|
|
180
180
|
|
181
181
|
if (typeof requirejs !== 'undefined') {
|
182
182
|
if (isFunction(requirejs)) {
|
183
|
-
//Do not overwrite
|
183
|
+
//Do not overwrite an existing requirejs instance.
|
184
184
|
return;
|
185
185
|
}
|
186
186
|
cfg = requirejs;
|
@@ -232,21 +232,20 @@ var requirejs, require, define;
|
|
232
232
|
* @param {Array} ary the array of path segments.
|
233
233
|
*/
|
234
234
|
function trimDots(ary) {
|
235
|
-
var i, part
|
236
|
-
for (i = 0; i < length; i++) {
|
235
|
+
var i, part;
|
236
|
+
for (i = 0; i < ary.length; i++) {
|
237
237
|
part = ary[i];
|
238
238
|
if (part === '.') {
|
239
239
|
ary.splice(i, 1);
|
240
240
|
i -= 1;
|
241
241
|
} else if (part === '..') {
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
break;
|
242
|
+
// If at the start, or previous value is still ..,
|
243
|
+
// keep them so that when converted to a path it may
|
244
|
+
// still work when converted to a path, even though
|
245
|
+
// as an ID it is less than ideal. In larger point
|
246
|
+
// releases, may be better to just kick out an error.
|
247
|
+
if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') {
|
248
|
+
continue;
|
250
249
|
} else if (i > 0) {
|
251
250
|
ary.splice(i - 1, 2);
|
252
251
|
i -= 2;
|
@@ -267,43 +266,37 @@ var requirejs, require, define;
|
|
267
266
|
*/
|
268
267
|
function normalize(name, baseName, applyMap) {
|
269
268
|
var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
|
270
|
-
foundMap, foundI, foundStarMap, starI,
|
271
|
-
baseParts = baseName && baseName.split('/'),
|
272
|
-
normalizedBaseParts = baseParts,
|
269
|
+
foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
|
270
|
+
baseParts = (baseName && baseName.split('/')),
|
273
271
|
map = config.map,
|
274
272
|
starMap = map && map['*'];
|
275
273
|
|
276
274
|
//Adjust any relative paths.
|
277
|
-
if (name
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
275
|
+
if (name) {
|
276
|
+
name = name.split('/');
|
277
|
+
lastIndex = name.length - 1;
|
278
|
+
|
279
|
+
// If wanting node ID compatibility, strip .js from end
|
280
|
+
// of IDs. Have to do this here, and not in nameToUrl
|
281
|
+
// because node allows either .js or non .js to map
|
282
|
+
// to same file.
|
283
|
+
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
284
|
+
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
285
|
+
}
|
286
|
+
|
287
|
+
// Starts with a '.' so need the baseName
|
288
|
+
if (name[0].charAt(0) === '.' && baseParts) {
|
282
289
|
//Convert baseName to array, and lop off the last part,
|
283
290
|
//so that . matches that 'directory' and not name of the baseName's
|
284
291
|
//module. For instance, baseName of 'one/two/three', maps to
|
285
292
|
//'one/two/three.js', but we want the directory, 'one/two' for
|
286
293
|
//this normalization.
|
287
294
|
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
|
288
|
-
name = name.split('/');
|
289
|
-
lastIndex = name.length - 1;
|
290
|
-
|
291
|
-
// If wanting node ID compatibility, strip .js from end
|
292
|
-
// of IDs. Have to do this here, and not in nameToUrl
|
293
|
-
// because node allows either .js or non .js to map
|
294
|
-
// to same file.
|
295
|
-
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
296
|
-
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
297
|
-
}
|
298
|
-
|
299
295
|
name = normalizedBaseParts.concat(name);
|
300
|
-
trimDots(name);
|
301
|
-
name = name.join('/');
|
302
|
-
} else if (name.indexOf('./') === 0) {
|
303
|
-
// No baseName, so this is ID is resolved relative
|
304
|
-
// to baseUrl, pull off the leading dot.
|
305
|
-
name = name.substring(2);
|
306
296
|
}
|
297
|
+
|
298
|
+
trimDots(name);
|
299
|
+
name = name.join('/');
|
307
300
|
}
|
308
301
|
|
309
302
|
//Apply map config if available.
|
@@ -379,7 +372,13 @@ var requirejs, require, define;
|
|
379
372
|
//retry
|
380
373
|
pathConfig.shift();
|
381
374
|
context.require.undef(id);
|
382
|
-
|
375
|
+
|
376
|
+
//Custom require that does not do map translation, since
|
377
|
+
//ID is "absolute", already mapped/resolved.
|
378
|
+
context.makeRequire(null, {
|
379
|
+
skipMap: true
|
380
|
+
})([id]);
|
381
|
+
|
383
382
|
return true;
|
384
383
|
}
|
385
384
|
}
|
@@ -445,7 +444,16 @@ var requirejs, require, define;
|
|
445
444
|
return normalize(name, parentName, applyMap);
|
446
445
|
});
|
447
446
|
} else {
|
448
|
-
|
447
|
+
// If nested plugin references, then do not try to
|
448
|
+
// normalize, as it will not normalize correctly. This
|
449
|
+
// places a restriction on resourceIds, and the longer
|
450
|
+
// term solution is not to normalize until plugins are
|
451
|
+
// loaded and all normalizations to allow for async
|
452
|
+
// loading of a loader plugin. But for now, fixes the
|
453
|
+
// common uses. Details in #1131
|
454
|
+
normalizedName = name.indexOf('!') === -1 ?
|
455
|
+
normalize(name, parentName, applyMap) :
|
456
|
+
name;
|
449
457
|
}
|
450
458
|
} else {
|
451
459
|
//A regular module.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: requirejs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Whitley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -139,7 +139,7 @@ rubyforge_project:
|
|
139
139
|
rubygems_version: 2.2.2
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
|
-
summary: Use RequireJS with the Rails 3 Asset Pipeline
|
142
|
+
summary: Use RequireJS with the Rails 3+ Asset Pipeline
|
143
143
|
test_files:
|
144
144
|
- test/dummy/.rvmrc
|
145
145
|
- test/dummy/Rakefile
|
@@ -176,3 +176,4 @@ test_files:
|
|
176
176
|
- test/dummy/script/rails
|
177
177
|
- test/requirejs-rails_test.rb
|
178
178
|
- test/test_helper.rb
|
179
|
+
has_rdoc:
|