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

Commit 1132b3d

Browse files
committed
Enable use of protocol relative urls
1 parent dd10bdb commit 1132b3d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def requirejs_include_tag(name = nil, &block)
4949
if run_config.has_key? 'paths'
5050
# Add paths for assets specified by full URL (on a CDN)
5151
run_config['paths'].each do |k, v|
52-
paths[k] = v if v.is_a?(Array) || v =~ /^https?:/
52+
paths[k] = v if v.is_a?(Array) || v =~ /^(https?:|\/\/)/
53+
5354
end
5455
end
5556

test/requirejs-rails_test.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def setup
110110
Rails.application.config.requirejs.delete(:build_config)
111111
end
112112

113-
def with_cdn
113+
def with_cdn(protocol_relative = false)
114114
Rails.application.config.requirejs.user_config = {
115115
"paths" => {
116-
"jquery" => "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
116+
"jquery" => "#{ protocol_relative ? '' : 'http:' }//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
117117
}
118118
}
119119
end
@@ -195,4 +195,13 @@ def wrap(tag)
195195
Rails.application.config.assets.digest = saved_digest
196196
end
197197
end
198+
199+
test "requirejs_include_tag with protocol relative CDN asset in paths" do
200+
with_cdn(true)
201+
202+
render text: wrap(requirejs_include_tag)
203+
204+
assert_select "script:last-of-type",
205+
text: Regexp.new("\\Arequire\\.config\\({.*\"paths\":{.*\"//ajax\\..*\".*}.*}\\);\\z")
206+
end
198207
end

0 commit comments

Comments
 (0)