diff --git a/.gitignore b/.gitignore index debb1b9..40d162b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _yardoc doc/ rails-test-app +/.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 04950dd..95c2cd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Edge version +* Add configurable `root_path` option for `bower-rails` * Add `rake bower:install:deployment` which installs from generated bower.json without generating it first, keeping any additions (like dependency conflict resolutions) intact [#89][] and [#92][] [#89]: https://github.com/42dev/bower-rails/pull/89 diff --git a/README.md b/README.md index 27ba847..d900a17 100644 --- a/README.md +++ b/README.md @@ -130,10 +130,17 @@ Change options in your `config/initializers/bower_rails.rb`: ``` ruby BowerRails.configure do |bower_rails| - # By default options are false - bower_rails.install_before_precompile = true # invokes rake bower:install before precompilation - bower_rails.resolve_before_precompile = true # invokes rake bower:resolve before precompilation - bower_rails.clean_before_precompile = true # invokes rake bower:clean before precompilation + # Tell bower-rails what path should be considered as root. Defaults to Dir.pwd + bower_rails.root_path = Dir.pwd + + # Invokes rake bower:install before precompilation. Defaults to false + bower_rails.install_before_precompile = true + + # Invokes rake bower:resolve before precompilation. Defaults to false + bower_rails.resolve_before_precompile = true + + # Invokes rake bower:clean before precompilation. Defaults to false + bower_rails.clean_before_precompile = true end ``` diff --git a/lib/bower-rails.rb b/lib/bower-rails.rb index 19eab93..8928261 100644 --- a/lib/bower-rails.rb +++ b/lib/bower-rails.rb @@ -5,6 +5,9 @@ module BowerRails extend self class << self + # The root path of the project + attr_accessor :root_path + # An array of tasks to enhance `rake assets:precompile` attr_reader :tasks @@ -35,10 +38,10 @@ def collect_tasks end end - # By default tasks are empty - @tasks = [] # Set default values for options + @root_path = Dir.pwd + @tasks = [] @install_before_precompile = false @resolve_before_precompile = false @clean_before_precompile = false diff --git a/lib/bower-rails/performer.rb b/lib/bower-rails/performer.rb index 3fd5cf2..d35b353 100644 --- a/lib/bower-rails/performer.rb +++ b/lib/bower-rails/performer.rb @@ -38,7 +38,7 @@ def perform(remove_components = true) end def bower_root_path - Dir.pwd + BowerRails.root_path end def dsl @@ -46,7 +46,6 @@ def dsl end def dsl_perform_command(remove_components = true, &block) - if remove_components dsl.write_bower_json dsl.write_dotbowerrc @@ -63,7 +62,7 @@ def dsl_perform_command(remove_components = true, &block) end #run the passed bower block in appropriate folders - def perform_command remove_components = true, &block + def perform_command(remove_components = true, &block) bower_root = bower_root_path #load in bower json file txt = File.read(File.join(bower_root, "bower.json")) @@ -194,6 +193,5 @@ def find_command(cmd, paths = []) nil end - end end \ No newline at end of file diff --git a/lib/bower-rails/railtie.rb b/lib/bower-rails/railtie.rb index 6d98856..f2bb292 100644 --- a/lib/bower-rails/railtie.rb +++ b/lib/bower-rails/railtie.rb @@ -9,8 +9,8 @@ class Railtie < Rails::Railtie if File.exist?(@@bowerfile) config.before_initialize do |app| - @dsl = BowerRails::Dsl.evalute(Dir.pwd, @@bowerfile) - + @dsl = BowerRails::Dsl.evalute(BowerRails.root_path, @@bowerfile) +r @dsl.final_assets_path.map do |assets_root, assets_path| app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components") end diff --git a/lib/generators/bower_rails/initialize/templates/bower_rails.rb b/lib/generators/bower_rails/initialize/templates/bower_rails.rb index f641437..79d2ecb 100644 --- a/lib/generators/bower_rails/initialize/templates/bower_rails.rb +++ b/lib/generators/bower_rails/initialize/templates/bower_rails.rb @@ -1,10 +1,13 @@ BowerRails.configure do |bower_rails| - # Invoke `rake bower:install` automatically before the `rake assets:precompile` task. + # Tell bower-rails what path should be considered as root. Defaults to Dir.pwd + # bower_rails.root_path = Dir.pwd + + # Invokes rake bower:install before precompilation. Defaults to false # bower_rails.install_before_precompile = true - # Invoke `rake bower:resolve` automatically before the `rake assets:precompile` task. + # Invokes rake bower:resolve before precompilation. Defaults to false # bower_rails.resolve_before_precompile = true - # Invoke `rake bower:clean` automatically before the `rake assets:precompile` task. + # Invokes rake bower:clean before precompilation. Defaults to false # bower_rails.clean_before_precompile = true -end +end \ No newline at end of file diff --git a/lib/tasks/bower.rake b/lib/tasks/bower.rake index 86f793f..d6f5412 100644 --- a/lib/tasks/bower.rake +++ b/lib/tasks/bower.rake @@ -65,5 +65,4 @@ before 'assets:precompile' do BowerRails.tasks.map do |task| Rake::Task[task].invoke end -end - +end \ No newline at end of file diff --git a/spec/bower-rails/bower-rails_spec.rb b/spec/bower-rails/bower-rails_spec.rb index aa91d11..855146e 100644 --- a/spec/bower-rails/bower-rails_spec.rb +++ b/spec/bower-rails/bower-rails_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe BowerRails do + it 'should set default value for root_path option' do + expect(BowerRails.root_path).to eq(Dir.pwd) + end + it 'should set default value for install_before_precompile option' do expect(BowerRails.install_before_precompile).to eq(false) end @@ -21,12 +25,19 @@ before :each do BowerRails.instance_variable_set(:@tasks, []) BowerRails.configure do |bower_rails| + bower_rails.root_path = '/home/username/dirname' bower_rails.install_before_precompile = false bower_rails.resolve_before_precompile = false bower_rails.clean_before_precompile = false end end + describe '#root_path' do + it 'should set root_path option' do + expect(BowerRails.root_path).to eq('/home/username/dirname') + end + end + describe '#install_before_precompile' do before do BowerRails.configure do |bower_rails|