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

Commit ec67111

Browse files
committed
Rewrite urls in paths to 'empty:' during build
1 parent 6b4c964 commit ec67111

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/requirejs/rails/config.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def build_config
108108
mod['name'] = 'almond'
109109
mod['include'] = name
110110
end
111+
self.rewrite_urls_in_paths self[:build_config]
111112
end
112113
self[:build_config]
113114
end
@@ -146,5 +147,13 @@ def asset_allowed?(asset)
146147
accum || (matcher =~ asset)
147148
end ? true : false
148149
end
150+
151+
def rewrite_urls_in_paths(cfg)
152+
if cfg.has_key? 'paths'
153+
cfg['paths'] = cfg['paths'].each_with_object({}) do |(k, v), h|
154+
h[k] = (v =~ /^https?:/) ? 'empty:' : v
155+
end
156+
end
157+
end
149158
end
150159
end

test/requirejs-rails_test.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,27 @@ def setup
8080
assert_nil @cfg.build_config['priority']
8181
end
8282

83-
## Almond tests
83+
test "build config should replace urls in paths with 'empty:'" do
84+
@cfg.user_config = { 'paths' =>
85+
{
86+
'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
87+
'jqueryssl' => 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'
88+
}
89+
}
90+
assert_equal 'empty:', @cfg.build_config['paths']['jquery']
91+
assert_equal 'empty:', @cfg.build_config['paths']['jqueryssl']
92+
end
93+
94+
test "build_config should not modify non-urls in paths" do
95+
@cfg.user_config = { 'paths' =>
96+
{
97+
'foo' => 'components/foo'
98+
}
99+
}
100+
assert_equal 'components/foo', @cfg.build_config['paths']['foo']
101+
end
102+
103+
## Almond-specific tests
84104
test "build_config with almond should accept one module" do
85105
@cfg.loader = :almond
86106
@cfg.user_config = { 'modules' => [ { 'name' => 'foo' } ] }

0 commit comments

Comments
 (0)