Skip to content

Commit

Permalink
Additional fixes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
SergeyKishenin committed Jul 29, 2013
1 parent 2305665 commit 3966a3a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/bower-rails/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def final_assets_path
end

def group_assets_path group
group_options = Hash === group.last ? group.pop : {}
group_options[:assets_path] || @assets_path
group_options = Hash === group.last ? group.last : {:assets_path => @assets_path}
group_options[:assets_path]
end

private
Expand Down
18 changes: 13 additions & 5 deletions lib/bower-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ module BowerRails
class Railtie < Rails::Railtie
railtie_name :bower

BowerRails::Dsl.config = {:root_path => Rails.root}
dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))
if File.exist?(File.join("Jsfile"))
BowerRails::Dsl.config = {:root_path => Rails.root}
dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))

config.after_initialize do |app|
dsl.final_assets_path.map do |assets_root, assets_path|
app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
config.before_initialize do |app|
dsl.final_assets_path.map do |assets_root, assets_path|
app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
end
end
else
config.before_initialize do |app|
["lib", "vendor"].each do |dir|
app.config.assets.paths << Rails.root.join(dir, 'assets', 'bower_components')
end
end
end

Expand Down
12 changes: 9 additions & 3 deletions lib/tasks/bower.rake
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,23 @@ def perform_command remove_components = true
FileUtils.rm_rf("bower_components") if remove_components

#create bower json
File.open("bower.json","w") do |f|
File.open("bower.json", "w") do |f|
f.write(data.to_json)
end

#create .bowerrc
File.open(".bowerrc", "w") do |f|
f.write(JSON.pretty_generate({:directory => "bower_components"}))
end

#run command
yield

#remove bower file
FileUtils.rm("bower.json")

end if data

#remove .bowerrc
FileUtils.rm(".bowerrc")
end if data && !data["dependencies"].empty?
end
end

0 comments on commit 3966a3a

Please sign in to comment.