bower-rails 0.4.0 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3abd7258ac3490088ec6235eb38f8dcf9841e184
4
- data.tar.gz: c4c9518aef2efb9ad170d117ff9326025f00797f
3
+ metadata.gz: 11f1465332da4588fdbf82ba6ac1baf8ac6af36d
4
+ data.tar.gz: 58b9f18ebe219e4e94ccad4e1b00a4201d38d1cf
5
5
  SHA512:
6
- metadata.gz: 2367658e828a6c11ea6438228fff3dc814ce3cc1b25ed3a3f57558afa67bada7fb221a4c6b844630bc4bafacc3faa220163e0f61322312b81754d89a72f492c1
7
- data.tar.gz: 587ad05a7ba55e22a21d59749258f9a98dfdfc9176e9cfddb6effce400a8b044f3603309d1ab3cb8116fc8e31cc8ec324eebf115609275a161c8712450145da8
6
+ metadata.gz: 9faedd78286fb6e4197f2e8551ef9eebc74f862ede75f6a53742307ba4600c77e1d560f5567d5c46e16d7b23ef6ae2d76f28920b129e9c8c74c34cab3b8f89dd
7
+ data.tar.gz: 480e4ad3a2cdee80ee0b6b4fac2515ddebb20f17cf9d053f1d1e926a3f4d5c307a0eeb3c4e1c2e90fe441a8e3b867b1b3ad86e89e2d92bcd67403ed3c96fc08d
data/README.md CHANGED
@@ -13,7 +13,7 @@ rake tasks for bower on rails. Dependency file is bower.json in Rails root dir.
13
13
  in Gemfile
14
14
 
15
15
  ``` Ruby
16
- gem "bower-rails", "~> 0.4.0"
16
+ gem "bower-rails", "~> 0.4.4"
17
17
  ```
18
18
 
19
19
  **Initialize**
@@ -53,38 +53,63 @@ The bower.json file is two seperate bower [component.js](https://github.com/twit
53
53
 
54
54
  ``` bash
55
55
  rake bower:install #install js components
56
- rake bower:update #update 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
57
59
  ```
58
60
 
59
61
 
60
62
  ##Ruby DSL configuration
61
63
 
62
- The Ruby DSL configuration is a Jsfile with DSL syntax similar to Bundler
63
-
64
+ The Ruby DSL configuration is a Jsfile with DSL syntax similar to Bundler.
64
65
 
65
66
  **Example Jsfile**
66
67
 
68
+ By default assets are put to `./vendor/assets/bower_components` directory:
69
+
70
+ ``` ruby
71
+
72
+ # Puts to ./vendor/assets/bower_components
73
+ js "backbone"
74
+ js "moment"
75
+ ```
76
+
77
+ But the default value can be overridden by `assets_path` method:
78
+
79
+ ``` ruby
80
+ assets_path "assets/my_javascripts"
81
+
82
+ # Puts to ./vendor/assets/my_javascripts/bower_components
83
+ js "backbone"
84
+ js "moment"
85
+ ```
86
+
87
+ And finally, the `assets_path` method can be overridden by an option in a `group` call:
88
+
67
89
  ``` ruby
68
90
  assets_path "assets/javascript"
69
91
 
70
- # Puts files under ./vendor/assets/js
92
+ # Puts files under ./vendor/assets/js/bower_components
71
93
  group :vendor, :assets_path => "assets/js" do
72
94
  js "jquery" # Assummes it's latests
73
95
  js "backbone", "1.2"
74
96
  end
75
97
 
76
- # Puts files under ./lib/assets/javascript
98
+ # Puts files under ./lib/assets/javascript/bower_components
77
99
  group :lib do
78
100
  js "jquery"
79
101
  js "backbone", "1.2"
80
102
  end
81
103
  ```
104
+ NOTE: All the assets should be stored in `/assets` subdirectory so putting it under `./vendor/js` directory is unavailable
82
105
 
83
106
  **Available commands with a Jsfile**
84
107
 
85
108
  ``` bash
86
109
  rake bower:dsl:install #install js components
87
- rake bower:dsl:update #update 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
88
113
  ```
89
114
 
90
115
 
@@ -1,61 +1,51 @@
1
- require "json"
1
+ require 'json'
2
2
  require 'fileutils'
3
3
 
4
4
  module BowerRails
5
5
  class Dsl
6
-
7
- def self.config=(conf)
8
- @config = conf
9
- end
10
-
11
- def self.config
12
- @config
13
- end
6
+ cattr_accessor :config
7
+ attr_reader :dependencies
14
8
 
15
9
  def self.evalute(file)
16
- inst = new
17
- inst.eval_file(file)
18
- inst
10
+ instance = new
11
+ instance.eval_file(file)
12
+ instance
19
13
  end
20
14
 
21
15
  def initialize
22
16
  @dependencies = {}
23
17
  @groups = []
24
18
  @root_path = BowerRails::Dsl.config[:root_path] || File.expand_path("./")
25
- @assets_path = BowerRails::Dsl.config[:assets_path] || "/assets/javascripts"
19
+ @assets_path = BowerRails::Dsl.config[:assets_path] || "assets"
26
20
  end
27
21
 
28
22
  def eval_file(file)
29
- contents = File.open(file,"r").read
30
- instance_eval(contents, file.to_s, 1)
23
+ instance_eval(File.open(file, "rb") { |f| f.read }, file.to_s)
31
24
  end
32
25
 
33
26
  def directories
34
27
  @dependencies.keys
35
28
  end
36
29
 
37
- def dependencies
38
- @dependencies
39
- end
40
-
41
30
  def group(*args, &blk)
42
- @groups.concat [args]
31
+ if args[1]
32
+ 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?
34
+ new_group = [args[0], args[1]]
35
+ else
36
+ new_group = [args[0]]
37
+ end
38
+
39
+ @groups << new_group
43
40
  yield
44
- ensure
45
- args.each { @groups.pop }
46
41
  end
47
42
 
48
43
  def js(name, *args)
49
- options = Hash === args.last ? args.pop : {}
50
44
  version = args.first || "latest"
51
-
52
- @groups = ["lib"] if @groups.empty?
45
+ @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
53
46
 
54
47
  @groups.each do |g|
55
- g_options = Hash === g.last ? g.pop : {}
56
- assets_path = g_options[:assets_path] || @assets_path
57
-
58
- g_norm = normalize_location_path(g.first,assets_path)
48
+ g_norm = normalize_location_path(g.first.to_s, group_assets_path(g))
59
49
  @dependencies[g_norm] ||= {}
60
50
  @dependencies[g_norm][name] = version
61
51
  end
@@ -68,26 +58,49 @@ module BowerRails
68
58
  def write_bower_json
69
59
  @dependencies.each do |dir,data|
70
60
  FileUtils.mkdir_p dir unless File.directory? dir
71
- File.open(File.join(dir,"bower.json"),"w") do |f|
61
+ File.open(File.join(dir,"bower.json"), "w") do |f|
72
62
  f.write(dependencies_to_json(data))
73
63
  end
74
64
  end
75
65
  end
76
66
 
67
+ def write_dotbowerrc
68
+ @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
69
+ @groups.map do |g|
70
+ File.open(File.join(g.first.to_s, group_assets_path(g), ".bowerrc"), "w") do |f|
71
+ f.write(JSON.pretty_generate({:directory => "bower_components"}))
72
+ end
73
+ end
74
+ end
75
+
76
+ def final_assets_path
77
+ @groups = [[:vendor, { assets_path: @assets_path }]] if @groups.empty?
78
+ @groups.map do |g|
79
+ [g.first.to_s, group_assets_path(g)]
80
+ end
81
+ end
82
+
83
+ def group_assets_path group
84
+ group_options = Hash === group.last ? group.last : {:assets_path => @assets_path}
85
+ group_options[:assets_path]
86
+ end
87
+
77
88
  private
78
89
 
79
90
  def dependencies_to_json(data)
80
- JSON.pretty_generate({
81
- :dependencies => data
82
- })
91
+ JSON.pretty_generate({
92
+ :name => "dsl-generated dependencies",
93
+ :dependencies => data
94
+ })
83
95
  end
84
96
 
85
97
  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?
86
99
  @assets_path = assets_path
87
100
  end
88
101
 
89
- def normalize_location_path(loc,assets_path)
90
- File.join(@root_path,loc.to_s,assets_path)
102
+ def normalize_location_path(loc, assets_path)
103
+ File.join(@root_path, loc.to_s, assets_path)
91
104
  end
92
105
 
93
106
  end
@@ -1,12 +1,25 @@
1
1
  require 'bower-rails'
2
+ require 'bower-rails/dsl'
2
3
  require 'rails'
4
+
3
5
  module BowerRails
4
6
  class Railtie < Rails::Railtie
5
7
  railtie_name :bower
6
8
 
7
- config.after_initialize do |app|
8
- ["lib", "vendor"].each do |dir|
9
- app.config.assets.paths << Rails.root.join(dir, 'assets', 'bower_components')
9
+ if File.exist?(File.join("Jsfile"))
10
+ BowerRails::Dsl.config = {:root_path => Rails.root}
11
+ dsl = BowerRails::Dsl.evalute(File.join("Jsfile"))
12
+
13
+ config.before_initialize do |app|
14
+ dsl.final_assets_path.map do |assets_root, assets_path|
15
+ app.config.assets.paths << Rails.root.join(assets_root, assets_path, "bower_components")
16
+ end
17
+ end
18
+ else
19
+ config.before_initialize do |app|
20
+ ["lib", "vendor"].each do |dir|
21
+ app.config.assets.paths << Rails.root.join(dir, 'assets', 'bower_components')
22
+ end
10
23
  end
11
24
  end
12
25
 
@@ -1,8 +1,9 @@
1
1
  require 'json'
2
2
  require 'pp'
3
+
3
4
  namespace :bower do
4
5
 
5
- desc "install files from bower"
6
+ desc "install components from bower"
6
7
  task :install do
7
8
  #install to corresponding directories
8
9
  perform_command do
@@ -10,7 +11,16 @@ namespace :bower do
10
11
  end
11
12
  end
12
13
 
13
- desc "update bower packages"
14
+ namespace :install do
15
+ desc "install components with -F option"
16
+ task :force do
17
+ perform_command do
18
+ sh 'bower install -F'
19
+ end
20
+ end
21
+ end
22
+
23
+ desc "update bower components"
14
24
  task :update do
15
25
  #install to corresponding directories
16
26
  perform_command false do
@@ -18,8 +28,17 @@ namespace :bower do
18
28
  end
19
29
  end
20
30
 
31
+ namespace :update do
32
+ desc "update existing components and uninstalls extraneous components"
33
+ task :prune do
34
+ perform_command false do
35
+ sh 'bower update && bower prune'
36
+ end
37
+ end
38
+ end
39
+
21
40
  namespace :dsl do
22
- desc "install files from bower"
41
+ desc "install components from bower"
23
42
  task :install do
24
43
  #install to corresponding directories
25
44
  dsl_perform_command do
@@ -27,14 +46,34 @@ namespace :bower do
27
46
  end
28
47
  end
29
48
 
30
- desc "update bower packages"
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
57
+
58
+ desc "update bower components"
31
59
  task :update do
32
60
  #install to corresponding directories
33
61
  dsl_perform_command false do
34
62
  sh 'bower update'
35
63
  end
36
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
+
37
75
  end
76
+
38
77
  end
39
78
 
40
79
  def get_bower_root_path
@@ -52,6 +91,7 @@ def dsl_perform_command remove_components = true
52
91
 
53
92
  if remove_components
54
93
  dsl.write_bower_json
94
+ dsl.write_dotbowerrc
55
95
  puts "bower.js files generated"
56
96
  end
57
97
 
@@ -83,17 +123,23 @@ def perform_command remove_components = true
83
123
  FileUtils.rm_rf("bower_components") if remove_components
84
124
 
85
125
  #create bower json
86
- File.open("bower.json","w") do |f|
126
+ File.open("bower.json", "w") do |f|
87
127
  f.write(data.to_json)
88
128
  end
89
129
 
130
+ #create .bowerrc
131
+ File.open(".bowerrc", "w") do |f|
132
+ f.write(JSON.pretty_generate({:directory => "bower_components"}))
133
+ end
134
+
90
135
  #run command
91
136
  yield
92
137
 
93
138
  #remove bower file
94
139
  FileUtils.rm("bower.json")
95
140
 
96
- end if data
97
-
141
+ #remove .bowerrc
142
+ FileUtils.rm(".bowerrc")
143
+ end if data && !data["dependencies"].empty?
98
144
  end
99
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bower-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Harrison
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-05-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Bower for Rails
13
+ description: Rails integration for bower.
14
14
  email: rtharrison86@gmail.com
15
15
  executables: []
16
16
  extensions: []