Skip to content

Commit

Permalink
Merge pull request #29 from SergeyKishenin/dsl_naming
Browse files Browse the repository at this point in the history
Naming issue in DSL
  • Loading branch information
rharriso committed Sep 23, 2013
2 parents 0c0b9d1 + dffe746 commit 763f70e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.5.0
* Jsfile was renamed to Bowerfile and BowerRails::Dsl#js to BowerRails::Dsl#asset ([discussion][])
[discussion]: https://github.com/42dev/bower-rails/pull/29
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
bower-rails
===========

rake tasks for bower on rails. Dependency file is bower.json in Rails root dir.
Bower support for Rails projects. Dependency file is bower.json in Rails root dir or Bowerfile if you use DSL.
Check out Changelog.md for the latest changes and releases.

**Requirements**

Expand Down Expand Up @@ -61,17 +62,17 @@ The bower.json file is two seperate bower [component.js](https://github.com/twit

##Ruby DSL configuration

The Ruby DSL configuration is a Jsfile with DSL syntax similar to Bundler.
The Ruby DSL configuration is a Bowerfile at the project's root with DSL syntax similar to Bundler.

**Example Jsfile**
**Example Bowerfile**

By default assets are put to `./vendor/assets/bower_components` directory:

``` ruby

# Puts to ./vendor/assets/bower_components
js "backbone"
js "moment"
asset "backbone"
asset "moment"
```

But the default value can be overridden by `assets_path` method:
Expand All @@ -80,8 +81,8 @@ But the default value can be overridden by `assets_path` method:
assets_path "assets/my_javascripts"

# Puts to ./vendor/assets/my_javascripts/bower_components
js "backbone"
js "moment"
asset "backbone"
asset "moment"
```

And finally, the `assets_path` method can be overridden by an option in a `group` call:
Expand All @@ -91,19 +92,19 @@ assets_path "assets/javascript"

# Puts files under ./vendor/assets/js/bower_components
group :vendor, :assets_path => "assets/js" do
js "jquery" # Assummes it's latests
js "backbone", "1.2"
asset "jquery" # Assummes it's latests
asset "backbone", "1.2"
end

# Puts files under ./lib/assets/javascript/bower_components
group :lib do
js "jquery"
js "backbone", "1.2"
asset "jquery"
asset "backbone", "1.2"
end
```
NOTE: All the assets should be stored in `/assets` subdirectory so putting it under `./vendor/js` directory is unavailable

**Available commands with a Jsfile**
**Available commands with a Bowerfile**

``` bash
rake bower:dsl:install #install js components
Expand Down
3 changes: 1 addition & 2 deletions lib/bower-rails/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def group(*args, &blk)
yield
end

def js(name, *args)
def asset(name, *args)
version = args.first || "latest"
@groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?

Expand Down Expand Up @@ -102,6 +102,5 @@ def assets_path(assets_path)
def normalize_location_path(loc, assets_path)
File.join(@root_path, loc.to_s, assets_path)
end

end
end
5 changes: 3 additions & 2 deletions lib/bower-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module BowerRails
class Railtie < Rails::Railtie
railtie_name :bower

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

config.before_initialize do |app|
dsl.final_assets_path.map do |assets_root, assets_path|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.source_root
def create_initializer_file
template "bower.json", 'bower.json'
end

end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/bower.rake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end
def dsl_perform_command remove_components = true
bower_root = get_bower_root_path
BowerRails::Dsl.config = {:root_path => bower_root}
dsl = BowerRails::Dsl.evalute(File.join(bower_root, "Jsfile"))
dsl = BowerRails::Dsl.evalute(File.join(bower_root, "Bowerfile"))

if remove_components
dsl.write_bower_json
Expand Down
8 changes: 4 additions & 4 deletions test/Jsfile.rb → test/Bowerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
assets_path "assets/javascript"

group :vendor, :assets_path => "assets/js" do
js "jquery"
js "backbone", "1.2"
asset "jquery"
asset "backbone", "1.2"
end

group :lib do
js "jquery"
js "backbone", "1.2"
asset "jquery"
asset "backbone", "1.2"
end
2 changes: 1 addition & 1 deletion test/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

BowerRails::Dsl.config = {:root_path => File.expand_path("./out") }

inst = BowerRails::Dsl.evalute(File.expand_path("./Jsfile.rb"))
inst = BowerRails::Dsl.evalute(File.expand_path("./Bowerfile"))

inst.write_bower_json

0 comments on commit 763f70e

Please sign in to comment.