Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Support bower.json configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 24, 2013
1 parent d2b3ac0 commit 5dad425
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ submit a pull request.

## Version History ##

**2.10.0**

* Support for `bower.json`

**2.9.3** (April 20, 2013)

* Fixed sass caching bug
Expand Down
4 changes: 3 additions & 1 deletion lib/sprockets/asset_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def search_paths

path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') }

# optimization: component.json can only be nested one level deep
# optimization: bower.json can only be nested one level deep
if !path_without_extensions.to_s.index('/')
paths << path_without_extensions.join("bower.json").to_s
# DEPRECATED bower configuration file
paths << path_without_extensions.join("component.json").to_s
end

Expand Down
10 changes: 5 additions & 5 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ def resolve(logical_path, options = {})
args = attributes_for(logical_path).search_paths + [options]
@trail.find(*args) do |path|
pathname = Pathname.new(path)
if pathname.basename.to_s == 'component.json'
component = json_decode(pathname.read)
case component['main']
if %w( bower.json component.json ).include?(pathname.basename.to_s)
bower = json_decode(pathname.read)
case bower['main']
when String
yield pathname.dirname.join(component['main'])
yield pathname.dirname.join(bower['main'])
when Array
extname = File.extname(logical_path)
component['main'].each do |fn|
bower['main'].each do |fn|
if extname == "" || extname == File.extname(fn)
yield pathname.dirname.join(fn)
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_asset_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class TestAssetAttributes < Sprockets::TestCase
test "search paths" do
assert_equal ["index.js", "index/component.json"],
assert_equal ["index.js", "index/bower.json", "index/component.json"],
pathname("index.js").search_paths
assert_equal ["foo.js", "foo/component.json", "foo/index.js"],
assert_equal ["foo.js", "foo/bower.json", "foo/component.json", "foo/index.js"],
pathname("foo.js").search_paths
assert_equal ["foo/bar.js", "foo/bar/index.js"],
pathname("foo/bar.js").search_paths
Expand Down

0 comments on commit 5dad425

Please sign in to comment.