Skip to content

Commit

Permalink
Merge branch 'upstream/issue-94'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/bower-rails/dsl.rb
	lib/tasks/bower.rake
  • Loading branch information
Melanitski committed Jul 19, 2014
2 parents 95cdec0 + 6676f46 commit 0babdaf
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ _yardoc
doc/

rails-test-app
/.idea/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
7 changes: 5 additions & 2 deletions lib/bower-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/bower-rails/performer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ def perform(remove_components = true)
end

def bower_root_path
Dir.pwd
BowerRails.root_path
end

def dsl
@dsl ||= BowerRails::Dsl.evalute(bower_root_path, "Bowerfile")
end

def dsl_perform_command(remove_components = true, &block)

if remove_components
dsl.write_bower_json
dsl.write_dotbowerrc
Expand All @@ -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"))
Expand Down Expand Up @@ -194,6 +193,5 @@ def find_command(cmd, paths = [])
nil
end


end
end
4 changes: 2 additions & 2 deletions lib/bower-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions lib/generators/bower_rails/initialize/templates/bower_rails.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions lib/tasks/bower.rake
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ before 'assets:precompile' do
BowerRails.tasks.map do |task|
Rake::Task[task].invoke
end
end

end
11 changes: 11 additions & 0 deletions spec/bower-rails/bower-rails_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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|
Expand Down

0 comments on commit 0babdaf

Please sign in to comment.