bower-rails 0.4.4 → 0.5.0

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: 11f1465332da4588fdbf82ba6ac1baf8ac6af36d
4
- data.tar.gz: 58b9f18ebe219e4e94ccad4e1b00a4201d38d1cf
3
+ metadata.gz: 16fcf55d5a780de4c4ae812c3f56174cdc3db86b
4
+ data.tar.gz: 874ce01615f934ea561b4c6eb5c8209b2c59205b
5
5
  SHA512:
6
- metadata.gz: 9faedd78286fb6e4197f2e8551ef9eebc74f862ede75f6a53742307ba4600c77e1d560f5567d5c46e16d7b23ef6ae2d76f28920b129e9c8c74c34cab3b8f89dd
7
- data.tar.gz: 480e4ad3a2cdee80ee0b6b4fac2515ddebb20f17cf9d053f1d1e926a3f4d5c307a0eeb3c4e1c2e90fe441a8e3b867b1b3ad86e89e2d92bcd67403ed3c96fc08d
6
+ metadata.gz: 852c5924db1d15a70a3bf45cd90cab5a700180efa52c6257acc8e36ae924e58e29d8b9bc7a7ebb256f872b129ffc3f325934b85b1f1cd002ae96188335cde921
7
+ data.tar.gz: db064ec965fbe7fa76069997576a763ed3d91a16754efe02c4533201a1b6f61bce21533dc24eb59568f9073de0b69341bcbad3b1b922c642252fd29ccea21415
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  bower-rails
2
2
  ===========
3
3
 
4
- rake tasks for bower on rails. Dependency file is bower.json in Rails root dir.
4
+ Bower support for Rails projects. Dependency file is bower.json in Rails root dir or Bowerfile if you use DSL.
5
+ Check out Changelog.md for the latest changes and releases.
5
6
 
6
7
  **Requirements**
7
8
 
@@ -48,30 +49,19 @@ The bower.json file is two seperate bower [component.js](https://github.com/twit
48
49
  }
49
50
  ```
50
51
 
51
-
52
- **Available commands**
53
-
54
- ``` bash
55
- rake bower:install #install js components
56
- rake bower:install:force #install with force option
57
- rake bower:update #update js components
58
- rake bower:update:prune #update components and uninstall extraneous packages
59
- ```
60
-
61
-
62
52
  ##Ruby DSL configuration
63
53
 
64
- The Ruby DSL configuration is a Jsfile with DSL syntax similar to Bundler.
54
+ The Ruby DSL configuration is a Bowerfile at the project's root with DSL syntax similar to Bundler.
65
55
 
66
- **Example Jsfile**
56
+ **Example Bowerfile**
67
57
 
68
58
  By default assets are put to `./vendor/assets/bower_components` directory:
69
59
 
70
60
  ``` ruby
71
61
 
72
62
  # Puts to ./vendor/assets/bower_components
73
- js "backbone"
74
- js "moment"
63
+ asset "backbone"
64
+ asset "moment"
75
65
  ```
76
66
 
77
67
  But the default value can be overridden by `assets_path` method:
@@ -80,8 +70,8 @@ But the default value can be overridden by `assets_path` method:
80
70
  assets_path "assets/my_javascripts"
81
71
 
82
72
  # Puts to ./vendor/assets/my_javascripts/bower_components
83
- js "backbone"
84
- js "moment"
73
+ asset "backbone"
74
+ asset "moment"
85
75
  ```
86
76
 
87
77
  And finally, the `assets_path` method can be overridden by an option in a `group` call:
@@ -91,28 +81,24 @@ assets_path "assets/javascript"
91
81
 
92
82
  # Puts files under ./vendor/assets/js/bower_components
93
83
  group :vendor, :assets_path => "assets/js" do
94
- js "jquery" # Assummes it's latests
95
- js "backbone", "1.2"
84
+ asset "jquery" # Assummes it's latests
85
+ asset "backbone", "1.2"
96
86
  end
97
87
 
98
88
  # Puts files under ./lib/assets/javascript/bower_components
99
89
  group :lib do
100
- js "jquery"
101
- js "backbone", "1.2"
90
+ asset "jquery"
91
+ asset "backbone", "1.2"
102
92
  end
103
93
  ```
104
94
  NOTE: All the assets should be stored in `/assets` subdirectory so putting it under `./vendor/js` directory is unavailable
105
95
 
106
- **Available commands with a Jsfile**
107
-
108
- ``` bash
109
- rake bower:dsl:install #install js components
110
- rake bower:dsl:install:force #install with force option
111
- rake bower:dsl:update #update js components
112
- rake bower:dsl:update:prune #update components and uninstall extraneous packages
113
- ```
114
-
115
-
116
-
96
+ ##Rake tasks
117
97
 
98
+ Once you are done with `bower.json` or `Bowerfile` you can run
118
99
 
100
+ * `rake bower:install` to install js components
101
+ * `rake bower:install:force` to install with force option
102
+ * `rake bower:update` to update js components
103
+ * `rake bower:update:prune` to update components and uninstall extraneous packages
104
+ * `rake bower:list` to list all packages
@@ -3,20 +3,19 @@ require 'fileutils'
3
3
 
4
4
  module BowerRails
5
5
  class Dsl
6
- cattr_accessor :config
7
- attr_reader :dependencies
8
-
9
- def self.evalute(file)
6
+ def self.evalute(filename)
10
7
  instance = new
11
- instance.eval_file(file)
8
+ instance.eval_file(File.join(instance.root_path, filename))
12
9
  instance
13
10
  end
14
11
 
12
+ attr_reader :dependencies, :root_path
13
+
15
14
  def initialize
16
15
  @dependencies = {}
17
- @groups = []
18
- @root_path = BowerRails::Dsl.config[:root_path] || File.expand_path("./")
19
- @assets_path = BowerRails::Dsl.config[:assets_path] || "assets"
16
+ @root_path ||= defined?(Rails) ? Rails.root : Dir.pwd
17
+ @assets_path ||= "assets"
18
+ @groups ||= [[:vendor, { assets_path: @assets_path }]]
20
19
  end
21
20
 
22
21
  def eval_file(file)
@@ -27,25 +26,25 @@ module BowerRails
27
26
  @dependencies.keys
28
27
  end
29
28
 
30
- def group(*args, &blk)
29
+ def group(*args, &block)
31
30
  if args[1]
32
31
  custom_assets_path = args[1][:assets_path]
33
- raise ArgumentError, "Assets should be stored in /assets directory, try :assets_path => 'assets/#{custom_assets_path}' instead" if custom_assets_path.match(/assets/).nil?
32
+ raise ArgumentError, "Assets should be stored in /assets directory, try :assets_path => 'assets/#{custom_assets_path}' instead" unless custom_assets_path.start_with?('assets', '/assets')
34
33
  new_group = [args[0], args[1]]
35
34
  else
36
35
  new_group = [args[0]]
37
36
  end
38
-
37
+
39
38
  @groups << new_group
40
- yield
39
+
40
+ yield if block_given?
41
41
  end
42
42
 
43
- def js(name, *args)
43
+ def asset(name, *args)
44
44
  version = args.first || "latest"
45
- @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
46
45
 
47
46
  @groups.each do |g|
48
- g_norm = normalize_location_path(g.first.to_s, group_assets_path(g))
47
+ g_norm = normalize_location_path(g.first, group_assets_path(g))
49
48
  @dependencies[g_norm] ||= {}
50
49
  @dependencies[g_norm][name] = version
51
50
  end
@@ -65,7 +64,6 @@ module BowerRails
65
64
  end
66
65
 
67
66
  def write_dotbowerrc
68
- @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
69
67
  @groups.map do |g|
70
68
  File.open(File.join(g.first.to_s, group_assets_path(g), ".bowerrc"), "w") do |f|
71
69
  f.write(JSON.pretty_generate({:directory => "bower_components"}))
@@ -74,7 +72,6 @@ module BowerRails
74
72
  end
75
73
 
76
74
  def final_assets_path
77
- @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
78
75
  @groups.map do |g|
79
76
  [g.first.to_s, group_assets_path(g)]
80
77
  end
@@ -95,13 +92,12 @@ module BowerRails
95
92
  end
96
93
 
97
94
  def assets_path(assets_path)
98
- raise ArgumentError, "Assets should be stored in /assets directory, try assets_path 'assets/#{assets_path}' instead" if assets_path.match(/assets/).nil?
95
+ raise ArgumentError, "Assets should be stored in /assets directory, try assets_path 'assets/#{assets_path}' instead" unless assets_path.start_with?('assets', '/assets')
99
96
  @assets_path = assets_path
100
97
  end
101
98
 
102
99
  def normalize_location_path(loc, assets_path)
103
100
  File.join(@root_path, loc.to_s, assets_path)
104
101
  end
105
-
106
102
  end
107
103
  end
@@ -5,13 +5,13 @@ require 'rails'
5
5
  module BowerRails
6
6
  class Railtie < Rails::Railtie
7
7
  railtie_name :bower
8
+ @@bowerfile = File.join("Bowerfile")
8
9
 
9
- if File.exist?(File.join("Jsfile"))
10
- BowerRails::Dsl.config = {:root_path => Rails.root}
11
- dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))
12
-
10
+ if File.exist?(@@bowerfile)
13
11
  config.before_initialize do |app|
14
- dsl.final_assets_path.map do |assets_root, assets_path|
12
+ @dsl = BowerRails::Dsl.evalute(@@bowerfile)
13
+
14
+ @dsl.final_assets_path.map do |assets_root, assets_path|
15
15
  app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
16
16
  end
17
17
  end
@@ -10,7 +10,6 @@ module BowerRails
10
10
  def create_initializer_file
11
11
  template "bower.json", 'bower.json'
12
12
  end
13
-
14
13
  end
15
14
  end
16
15
  end
data/lib/tasks/bower.rake CHANGED
@@ -2,78 +2,56 @@ require 'json'
2
2
  require 'pp'
3
3
 
4
4
  namespace :bower do
5
-
6
- desc "install components from bower"
5
+ desc "Install components from bower"
7
6
  task :install do
8
- #install to corresponding directories
9
- perform_command do
7
+ perform do
10
8
  sh 'bower install'
11
9
  end
12
10
  end
13
11
 
14
12
  namespace :install do
15
- desc "install components with -F option"
13
+ desc "Install components with -F option"
16
14
  task :force do
17
- perform_command do
15
+ perform do
18
16
  sh 'bower install -F'
19
17
  end
20
18
  end
21
19
  end
22
20
 
23
- desc "update bower components"
21
+ desc "Update bower components"
24
22
  task :update do
25
- #install to corresponding directories
26
- perform_command false do
23
+ perform do
27
24
  sh 'bower update'
28
25
  end
29
26
  end
30
27
 
28
+ desc "List bower components"
29
+ task :list do
30
+ perform false do
31
+ sh 'bower list'
32
+ end
33
+ end
34
+
31
35
  namespace :update do
32
- desc "update existing components and uninstalls extraneous components"
36
+ desc "Update existing components and uninstalls extraneous components"
33
37
  task :prune do
34
- perform_command false do
38
+ perform do
35
39
  sh 'bower update && bower prune'
36
40
  end
37
41
  end
38
42
  end
43
+ end
39
44
 
40
- namespace :dsl do
41
- desc "install components from bower"
42
- task :install do
43
- #install to corresponding directories
44
- dsl_perform_command do
45
- sh 'bower install'
46
- end
47
- end
48
-
49
- namespace :install do
50
- desc "install components with -F option"
51
- task :force do
52
- dsl_perform_command do
53
- sh 'bower install -F'
54
- end
55
- end
56
- end
45
+ def perform remove_components = true, &block
46
+ entries = Dir.entries(get_bower_root_path)
57
47
 
58
- desc "update bower components"
59
- task :update do
60
- #install to corresponding directories
61
- dsl_perform_command false do
62
- sh 'bower update'
63
- end
64
- end
65
-
66
- namespace :update do
67
- desc "update existing components and uninstalls extraneous components"
68
- task :prune do
69
- dsl_perform_command false do
70
- sh 'bower update && bower prune'
71
- end
72
- end
73
- end
74
-
48
+ if entries.include?('Bowerfile')
49
+ dsl_perform_command remove_components, &block
50
+ elsif entries.include?('bower.json')
51
+ perform_command remove_components, &block
52
+ else
53
+ raise LoadError, "No Bowerfile or bower.json file found. Make sure you have it at the root of your project"
75
54
  end
76
-
77
55
  end
78
56
 
79
57
  def get_bower_root_path
@@ -84,10 +62,8 @@ def get_bower_root_path
84
62
  end
85
63
  end
86
64
 
87
- def dsl_perform_command remove_components = true
88
- bower_root = get_bower_root_path
89
- BowerRails::Dsl.config = {:root_path => bower_root}
90
- dsl = BowerRails::Dsl.evalute(File.join(bower_root, "Jsfile"))
65
+ def dsl_perform_command remove_components = true, &block
66
+ dsl = BowerRails::Dsl.evalute("Bowerfile")
91
67
 
92
68
  if remove_components
93
69
  dsl.write_bower_json
@@ -95,15 +71,17 @@ def dsl_perform_command remove_components = true
95
71
  puts "bower.js files generated"
96
72
  end
97
73
 
98
- dsl.directories.each do |dir|
99
- Dir.chdir(dir) do
100
- yield
74
+ if block_given?
75
+ dsl.directories.each do |dir|
76
+ Dir.chdir(dir) do
77
+ yield
78
+ end
101
79
  end
102
80
  end
103
81
  end
104
82
 
105
83
  #run the passed bower block in appropriate folders
106
- def perform_command remove_components = true
84
+ def perform_command remove_components = true, &block
107
85
  bower_root = get_bower_root_path
108
86
  #load in bower json file
109
87
  txt = File.read(File.join(bower_root, "bower.json"))
@@ -133,7 +111,7 @@ def perform_command remove_components = true
133
111
  end
134
112
 
135
113
  #run command
136
- yield
114
+ yield if block_given?
137
115
 
138
116
  #remove bower file
139
117
  FileUtils.rm("bower.json")
metadata CHANGED
@@ -1,31 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bower-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Harrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: Rails integration for bower.
14
42
  email: rtharrison86@gmail.com
15
43
  executables: []
16
44
  extensions: []
17
45
  extra_rdoc_files: []
18
46
  files:
19
- - lib/bower-rails/dsl.rb
20
47
  - lib/bower-rails/railtie.rb
48
+ - lib/bower-rails/dsl.rb
21
49
  - lib/bower-rails.rb
22
- - lib/generators/bower_rails/initialize/initialize_generator.rb
23
50
  - lib/generators/bower_rails/initialize/templates/bower.json
51
+ - lib/generators/bower_rails/initialize/initialize_generator.rb
24
52
  - lib/tasks/bower.rake
25
53
  - MIT-LICENSE
26
54
  - README.md
27
55
  homepage: https://github.com/rharriso/bower-rails
28
- licenses: []
56
+ licenses:
57
+ - MIT
29
58
  metadata: {}
30
59
  post_install_message:
31
60
  rdoc_options: []
@@ -48,3 +77,4 @@ signing_key:
48
77
  specification_version: 4
49
78
  summary: Bower for Rails
50
79
  test_files: []
80
+ has_rdoc: