bundler-bower 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12b871ccc9ca1ac06ece906a8c49d7d0d44a421e
4
- data.tar.gz: ac02c42269b8081cd3d0bf109e374c7ca693856a
3
+ metadata.gz: dab3062b273a3559721269ab8a2040de70845b62
4
+ data.tar.gz: 6fdafce4ee50981b672e248f393a0b083cb315c2
5
5
  SHA512:
6
- metadata.gz: 8770cf4e380fd5a72816bb518fccda9d4e119551a556aacc364e91ef7f0cd1c64fa442f35739e9f831d8c7bd1441e1c59884712d667e3f83384fb0c1eb53ae05
7
- data.tar.gz: 4ed73de006241580beffe12cc3f1daad527ad4bd6ab063076e429324939ada5049b52fd4e0240beb5bcc4cd1264d480fc6a66e7de4a4411edb9bc640e863d7da
6
+ metadata.gz: ca0e3e5c8a39656cb37e2909840a45aae104b55691f880513241bdb09d8a9f4bf005e2ecb369caee39f6d29085e4bc4fcd05d2875465487f4789eca6e3fd8d86
7
+ data.tar.gz: 3a620311a687aadefa967187e2262c969a33bc1bb6ecfc044f34646cd9f914d032f3bcbc694bd78f72e31a1963c1e6bb7ca8d29a53b3fcefe99f3de442bd8720
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ before_script:
2
2
  - npm install -g bower
3
3
  rvm:
4
4
  - 2.0.0
5
+ - 1.9
5
6
  - ruby-head
6
7
  - jruby-head
7
8
  - jruby-19mode
data/README.md CHANGED
@@ -11,8 +11,9 @@ Bower support for bundler. You can use assets from bower directly in `Gemfile`
11
11
 
12
12
  ### Requirements
13
13
 
14
- * bower
15
- * ruby 2.0 (or with `Module#prepend` support)
14
+ * [node](http://nodejs.org)
15
+ * [bower](https://github.com/bower/bower) (>= 0.10.0) installed with npm
16
+ * ruby >= 1.9
16
17
 
17
18
  ## Installation
18
19
 
@@ -37,39 +38,116 @@ Add to your Gemfile require method.
37
38
  source 'https://rubygems.org'
38
39
  require 'bundler/bower'
39
40
 
40
- gem 'rake'
41
+ # ...
42
+ ```
43
+
44
+ You can use DSL from [bower-rails](https://github.com/42dev/bower-rails). Click [here](https://github.com/42dev/bower-rails#ruby-dsl-configuration) for details.
45
+
46
+ ### Usage with Gemfile
47
+
48
+ You can use `asset` method directly in your Gemfile.
49
+
50
+ ```ruby
51
+ # Gemfile
52
+ source 'https://rubygems.org'
53
+ require 'bundler/bower'
54
+
55
+ gem 'rails'
56
+ asset 'backbone', '0.9'
57
+ ```
58
+
59
+ ### Usage with Bowerfile
60
+
61
+ You can use `Bowerfile` from [bower-rails](https://github.com/42dev/bower-rails). This file should be in the same directory as the `Gemfile`.
62
+
63
+ ```ruby
64
+ # Gemfile
65
+ source 'https://rubygems.org'
66
+ require 'bundler/bower'
67
+
68
+ gem 'rails'
69
+ ```
70
+
71
+ And `Bowerfile`
72
+
73
+ ```ruby
74
+ # Bowerfile
75
+
76
+ asset 'backbone', '0.9'
77
+ ```
41
78
 
42
- asset 'backbone', "0.9"
43
- asset 'moment'
79
+ ### Usage with bower.json
80
+
81
+ You can use `bower.json` from [bower-rails](https://github.com/42dev/bower-rails). This file should be in the same directory as the `Gemfile`.
82
+
83
+ ```ruby
84
+ # Gemfile
85
+ source 'https://rubygems.org'
86
+ require 'bundler/bower'
87
+
88
+ gem 'rails'
44
89
  ```
45
90
 
46
- You can use DSL from [bower-rails](https://github.com/42dev/bower-rails). Click [here](https://github.com/42dev/bower-rails#ruby-dsl-configuration) for details. Only `group` method is not supported.
91
+ And `bower.json`
47
92
 
48
- And just execute `bundle install`.
93
+ ```ruby
94
+ # bower.json
95
+ {
96
+ "vendor": {
97
+ "name": "bower-rails generated vendor assets",
98
+ "dependencies": {
99
+ "backbone" : "0.9"
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## Install dependencies
106
+
107
+ Just execute `bundle install`.
49
108
 
50
109
  ```
51
110
  Using rake (10.1.0)
52
111
  Using bundler (1.3.5)
53
112
  bower backbone#0.9 cached git://github.com/jashkenas/backbone.git#0.9.10
54
113
  bower backbone#0.9 validate 0.9.10 against git://github.com/jashkenas/backbone.git#0.9
55
- bower moment#* cached git://github.com/timrwood/moment.git#2.4.0
56
- bower moment#* validate 2.4.0 against git://github.com/timrwood/moment.git#*
57
- bower moment#* install moment#2.4.0
58
114
  bower backbone#0.9 install backbone#0.9.10
59
115
 
60
- moment#2.4.0 bower_components/moment
61
-
62
116
  backbone#0.9.10 bower_components/backbone
63
117
  bower check-new Checking for new versions of the project dependencies..
64
118
  dsl-generated dependencies /home/lite/work/bundler-bower/spec/dummy/vendor/assets
65
119
  ├── backbone#0.9.10 (latest is 1.1.0)
66
- └── moment#2.4.0
67
120
  Your bundle is complete!
68
121
  Use `bundle show [gemname]` to see where a bundled gem is installed.
69
122
  ```
70
123
 
71
124
  When you execute `bundle` or `bundle install` bundler-bower will execute `bower install`. But when you execute `bundle update` bundler-bower will execute `bower update`. When bundler quits you can find your assets in `vendor/assets/bower_components`. Of course you can change this directory by `assets_path` method.
72
125
 
126
+ ## Configure asset pipeline
127
+
128
+ ```ruby
129
+ # config/application.rb
130
+
131
+ # include Bower components in compiled assets
132
+ config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
133
+ ```
134
+
135
+ Update your `application.js` file
136
+
137
+ ```
138
+ // app/assets/javascripts/application.js
139
+ //
140
+ // Bower packages
141
+ //= require backbone/backbone
142
+ //
143
+ // Other components
144
+ //= require jquery
145
+ //= require jquery_ujs
146
+ // ...
147
+ ```
148
+
149
+ ENJOY!
150
+
73
151
  ## Contributing
74
152
 
75
153
  1. Fork it
@@ -77,3 +155,7 @@ When you execute `bundle` or `bundle install` bundler-bower will execute `bower
77
155
  3. Commit your changes (`git commit -am 'Add some feature'`)
78
156
  4. Push to the branch (`git push origin my-new-feature`)
79
157
  5. Create new Pull Request
158
+
159
+
160
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/LTe/bundler-bower/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
161
+
data/lib/bundler/bower.rb CHANGED
@@ -6,5 +6,5 @@ require "bundler/bower/fake_dsl/bower-rails"
6
6
  require "bundler/bower/bundler_installer"
7
7
 
8
8
  Bundler::Dsl.send(:include, Bundler::Bower::FakeDsl::Bundler)
9
- BowerRails::Dsl.send(:prepend, Bundler::Bower::FakeDsl::BowerRails)
10
- Bundler::Installer.send(:prepend, Bundler::Bower::BundlerInstaller)
9
+ BowerRails::Dsl.send(:include, Bundler::Bower::FakeDsl::BowerRails)
10
+ Bundler::Installer.send(:include, Bundler::Bower::BundlerInstaller)
@@ -3,10 +3,16 @@ require 'bundler/bower/rake'
3
3
  module Bundler
4
4
  module Bower
5
5
  module BundlerInstaller
6
- def run(options)
7
- result = super
8
- Bundler::Bower::Rake.new(options).perform
9
- result
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias :old_run :run
9
+
10
+ def run(options)
11
+ result = old_run(options)
12
+ Bundler::Bower::Rake.new(options).perform
13
+ result
14
+ end
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -4,12 +4,27 @@ require 'bower-rails'
4
4
  module Bundler
5
5
  module Bower
6
6
  class Rake
7
+ DEPENDENCY_FILES = %w{bower.json Bowerfile Gemfile}.freeze
8
+
7
9
  def initialize(options)
8
10
  @options = options
9
11
  end
10
12
 
13
+ def dependency_file
14
+ entries = Dir.entries(Dir.pwd)
15
+ DEPENDENCY_FILES.detect { |file| entries.include?(file) }
16
+ end
17
+
11
18
  def perform
12
- dsl = BowerRails::Dsl.evalute("Gemfile")
19
+ case dependency_file
20
+ when "Gemfile" then perform_dsl("Gemfile")
21
+ when "Bowerfile" then perform_dsl("Bowerfile")
22
+ when "bower.json" then perform_json
23
+ end
24
+ end
25
+
26
+ def perform_dsl(file)
27
+ dsl = BowerRails::Dsl.evalute(file)
13
28
 
14
29
  dsl.write_bower_json
15
30
  dsl.write_dotbowerrc
@@ -22,6 +37,42 @@ module Bundler
22
37
  end
23
38
  end
24
39
 
40
+ def perform_json(remove_components = true)
41
+ bower_root = Dir.pwd
42
+ json = JSON.parse(File.read(File.join(bower_root, "bower.json")))
43
+ dot_bowerrc = JSON.parse(File.read(File.join(bower_root, '.bowerrc'))) rescue {}
44
+
45
+ dot_bowerrc["directory"] = "bower_components"
46
+
47
+ if (json.keys - ['lib', 'vendor']).empty?
48
+ folders = json.keys
49
+ else
50
+ raise "Assuming a standard bower package but cannot find the required 'name' key" unless !!json['name']
51
+ folders = ['vendor']
52
+ end
53
+
54
+ folders.each do |dir|
55
+ puts "\nInstalling dependencies into #{dir}"
56
+ data = json[dir]
57
+ data = json if data.nil?
58
+
59
+ dir = File.join(bower_root, dir, "assets")
60
+ FileUtils.mkdir_p dir unless File.directory? dir
61
+
62
+ Dir.chdir(dir) do
63
+ FileUtils.rm_rf("bower_components") if remove_components
64
+ File.open("bower.json", "w") { |f| f.write(data.to_json) }
65
+ File.open(".bowerrc", "w") { |f| f.write(JSON.pretty_generate(dot_bowerrc)) }
66
+
67
+ system(command)
68
+ system('bower list')
69
+
70
+ FileUtils.rm("bower.json")
71
+ FileUtils.rm(".bowerrc")
72
+ end if data && !data["dependencies"].empty?
73
+ end
74
+ end
75
+
25
76
  def update?
26
77
  @options["update"]
27
78
  end
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Bower
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,13 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Integration test" do
4
- let(:directory) { File.join(File.dirname(__FILE__), "../../dummy") }
5
4
  let(:test_node) { TestNode.new(:gemfile => "#{directory}/Gemfile", :type => "install") }
6
5
 
7
6
  before { Dir.chdir(directory) { test_node.spawn } }
8
7
  after { FileUtils.rm_rf("#{ directory}/vendor") }
9
8
 
10
- it "download backbone" do
11
- File.exist?("#{directory}/vendor/assets/bower_components/backbone/backbone.js").should be_true
9
+ describe "Gemfile" do
10
+ let(:directory) { File.join(File.dirname(__FILE__), "../../dummy") }
11
+
12
+ it "download backbone" do
13
+ File.exist?("#{directory}/vendor/assets/bower_components/backbone/backbone.js").should be_true
14
+ end
15
+ end
16
+
17
+ describe "Bowerfile" do
18
+ let(:directory) { File.join(File.dirname(__FILE__), "../../dummy_bowerfile") }
19
+
20
+ it "download backbone" do
21
+ File.exist?("#{directory}/vendor/assets/bower_components/backbone/backbone.js").should be_true
22
+ end
23
+ end
24
+
25
+ describe "bower.json" do
26
+ let(:directory) { File.join(File.dirname(__FILE__), "../../dummy_bower_json") }
27
+
28
+ it "download backbone" do
29
+ File.exist?("#{directory}/vendor/assets/bower_components/backbone/backbone.js").should be_true
30
+ end
12
31
  end
13
32
  end
@@ -5,6 +5,60 @@ module Bundler::Bower
5
5
  let(:options) { {} }
6
6
  subject { Rake.new(options) }
7
7
 
8
+ describe "recognize dependency file" do
9
+ before { stub(Dir).entries(any_args) { files } }
10
+
11
+ context "only Gemfile" do
12
+ let(:files) { ["Gemfile", "other-file" ].shuffle }
13
+
14
+ it "returns Gemfile as dependency file" do
15
+ subject.dependency_file.should == "Gemfile"
16
+ end
17
+ end
18
+
19
+ context "Bowerfile and Gemfile" do
20
+ let(:files) { ["Gemfile", "Bowerfile", "other-file" ].shuffle }
21
+
22
+ it "returns Bowerfile" do
23
+ subject.dependency_file.should == "Bowerfile"
24
+ end
25
+ end
26
+
27
+ context "bower.json, Bowerfile and Gemfile" do
28
+ let(:files) { ["Gemfile", "Bowerfile", "bower.json", "other-file" ].shuffle }
29
+
30
+ it "returns bower.json" do
31
+ subject.dependency_file.should == "bower.json"
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "stategy for DSL and .json format" do
37
+ describe "for DSL" do
38
+ ["Gemfile", "Bowerfile"].each do |file|
39
+ describe file do
40
+ before { stub(subject).dependency_file { file } }
41
+
42
+ it "execute DSL strategy for #{file}" do
43
+ mock(subject).perform_dsl(file)
44
+ subject.perform
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "for .json file" do
51
+ describe "bower.json" do
52
+ before { stub(subject).dependency_file { "bower.json" } }
53
+
54
+ it "execute standard strategy for bower.json" do
55
+ mock(subject).perform_json
56
+ subject.perform
57
+ end
58
+ end
59
+ end
60
+ end
61
+
8
62
  describe "during bundle (install)" do
9
63
  describe "#update?" do
10
64
  it "returns false" do
@@ -0,0 +1 @@
1
+ asset 'moment'
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH << File.dirname(__FILE__) + '/../../lib'
2
+ require 'bundler/bower'
3
+
4
+ gem 'rake'
@@ -0,0 +1,8 @@
1
+ {
2
+ "vendor": {
3
+ "name": "bower-rails generated vendor assets",
4
+ "dependencies": {
5
+ "backbone" : "0.9"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ asset 'backbone', "0.9"
2
+ asset 'moment'
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH << File.dirname(__FILE__) + '/../../lib'
2
+ require 'bundler/bower'
3
+
4
+ gem 'rake'
data/spec/spec_helper.rb CHANGED
@@ -13,4 +13,5 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
13
 
14
14
  Bogus.configure do |c|
15
15
  c.search_modules << BowerRails
16
+ c.search_modules << Bundler::Bower
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-bower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Niełacny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bower-rails
@@ -75,6 +75,11 @@ files:
75
75
  - spec/bundler/bower/integration_spec.rb
76
76
  - spec/bundler/bower/rake_spec.rb
77
77
  - spec/dummy/Gemfile
78
+ - spec/dummy_bower_json/Bowerfile
79
+ - spec/dummy_bower_json/Gemfile
80
+ - spec/dummy_bower_json/bower.json
81
+ - spec/dummy_bowerfile/Bowerfile
82
+ - spec/dummy_bowerfile/Gemfile
78
83
  - spec/spec_helper.rb
79
84
  - spec/support/test_node.rb
80
85
  homepage: https://github.com/LTe/bundler-bower
@@ -97,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
102
  version: '0'
98
103
  requirements: []
99
104
  rubyforge_project:
100
- rubygems_version: 2.0.3
105
+ rubygems_version: 2.1.11
101
106
  signing_key:
102
107
  specification_version: 4
103
108
  summary: integration bundler with bower
@@ -105,5 +110,10 @@ test_files:
105
110
  - spec/bundler/bower/integration_spec.rb
106
111
  - spec/bundler/bower/rake_spec.rb
107
112
  - spec/dummy/Gemfile
113
+ - spec/dummy_bower_json/Bowerfile
114
+ - spec/dummy_bower_json/Gemfile
115
+ - spec/dummy_bower_json/bower.json
116
+ - spec/dummy_bowerfile/Bowerfile
117
+ - spec/dummy_bowerfile/Gemfile
108
118
  - spec/spec_helper.rb
109
119
  - spec/support/test_node.rb