Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 177ab1b

Browse files
committed
Made it possible to use fallbacks for modules
Now configuration like this config/requirejs.yml: paths: jquery: - http://cdn1.com/jquery-1.9.1.min - http://cdn2.com/jquery-1.9.1.min - jquery-1.9.1 works as expected: replace paths array with "empty:" in build_config for such module and adds this paths directly into run_config on page. Make sure jquery-1.9.1 is precompiled on your server, when using local fallback.
1 parent d894eb3 commit 177ab1b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def requirejs_include_tag(name=nil, &block)
5656

5757
if run_config.has_key? 'paths'
5858
# Add paths for assets specified by full URL (on a CDN)
59-
run_config['paths'].each { |k, v| paths[k] = v if v =~ /^https?:/ }
59+
run_config['paths'].each do |k, v|
60+
paths[k] = v if v.is_a?(Array) || v =~ /^https?:/
61+
end
6062
end
6163

6264
# Override user paths, whose mappings are only relevant in dev mode

lib/requirejs/rails/rjs_driver.js.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ cdn_pattern = Regexp.new("\\Ahttps?://")
55
modifiedHash = build_config.select { |k, _| k != "modules" }
66
pathsHash = modifiedHash["paths"]
77
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]
8+
modifiedHash["paths"] = Hash[
9+
pathsHash.map do |k, v|
10+
[k, v.is_a?(Array) || cdn_pattern.match(v) ? "empty:" : v]
1311
end
1412
] if !pathsHash.nil?
1513

0 commit comments

Comments
 (0)