Skip to content

Commit

Permalink
Rewrite urls in paths to 'empty:' during build
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitley committed Apr 30, 2012
1 parent 6b4c964 commit ec67111
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/requirejs/rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def build_config
mod['name'] = 'almond'
mod['include'] = name
end
self.rewrite_urls_in_paths self[:build_config]
end
self[:build_config]
end
Expand Down Expand Up @@ -146,5 +147,13 @@ def asset_allowed?(asset)
accum || (matcher =~ asset)
end ? true : false
end

def rewrite_urls_in_paths(cfg)
if cfg.has_key? 'paths'
cfg['paths'] = cfg['paths'].each_with_object({}) do |(k, v), h|
h[k] = (v =~ /^https?:/) ? 'empty:' : v
end
end
end
end
end
22 changes: 21 additions & 1 deletion test/requirejs-rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,27 @@ def setup
assert_nil @cfg.build_config['priority']
end

## Almond tests
test "build config should replace urls in paths with 'empty:'" do
@cfg.user_config = { 'paths' =>
{
'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
'jqueryssl' => 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'
}
}
assert_equal 'empty:', @cfg.build_config['paths']['jquery']
assert_equal 'empty:', @cfg.build_config['paths']['jqueryssl']
end

test "build_config should not modify non-urls in paths" do
@cfg.user_config = { 'paths' =>
{
'foo' => 'components/foo'
}
}
assert_equal 'components/foo', @cfg.build_config['paths']['foo']
end

## Almond-specific tests
test "build_config with almond should accept one module" do
@cfg.loader = :almond
@cfg.user_config = { 'modules' => [ { 'name' => 'foo' } ] }
Expand Down

0 comments on commit ec67111

Please sign in to comment.