Skip to content

Commit 3966a3a

Browse files
Additional fixes
- using .bowerrc for managing bower directories with plain bower.json - using before_initialize instead of after_initialize at bower-rails/railties.rb - group.last instead of group.pop
1 parent 2305665 commit 3966a3a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

lib/bower-rails/dsl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def final_assets_path
8181
end
8282

8383
def group_assets_path group
84-
group_options = Hash === group.last ? group.pop : {}
85-
group_options[:assets_path] || @assets_path
84+
group_options = Hash === group.last ? group.last : {:assets_path => @assets_path}
85+
group_options[:assets_path]
8686
end
8787

8888
private

lib/bower-rails/railtie.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ module BowerRails
66
class Railtie < Rails::Railtie
77
railtie_name :bower
88

9-
BowerRails::Dsl.config = {:root_path => Rails.root}
10-
dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))
9+
if File.exist?(File.join("Jsfile"))
10+
BowerRails::Dsl.config = {:root_path => Rails.root}
11+
dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))
1112

12-
config.after_initialize do |app|
13-
dsl.final_assets_path.map do |assets_root, assets_path|
14-
app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
13+
config.before_initialize do |app|
14+
dsl.final_assets_path.map do |assets_root, assets_path|
15+
app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
16+
end
17+
end
18+
else
19+
config.before_initialize do |app|
20+
["lib", "vendor"].each do |dir|
21+
app.config.assets.paths << Rails.root.join(dir, 'assets', 'bower_components')
22+
end
1523
end
1624
end
1725

lib/tasks/bower.rake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,23 @@ def perform_command remove_components = true
8484
FileUtils.rm_rf("bower_components") if remove_components
8585

8686
#create bower json
87-
File.open("bower.json","w") do |f|
87+
File.open("bower.json", "w") do |f|
8888
f.write(data.to_json)
8989
end
9090

91+
#create .bowerrc
92+
File.open(".bowerrc", "w") do |f|
93+
f.write(JSON.pretty_generate({:directory => "bower_components"}))
94+
end
95+
9196
#run command
9297
yield
9398

9499
#remove bower file
95100
FileUtils.rm("bower.json")
96101

97-
end if data
98-
102+
#remove .bowerrc
103+
FileUtils.rm(".bowerrc")
104+
end if data && !data["dependencies"].empty?
99105
end
100106
end

0 commit comments

Comments
 (0)