bower-rails 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -2
- data/lib/bower-rails/dsl.rb +93 -82
- data/lib/bower-rails/performer.rb +1 -1
- data/lib/bower-rails/railtie.rb +0 -1
- data/lib/bower-rails/version.rb +1 -1
- data/lib/generators/bower_rails/initialize/templates/bower_rails.rb +4 -1
- data/lib/tasks/bower.rake +2 -1
- data/lib/tasks/helpers/before_hook.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065bcccfc41af7421a73a3dbc925806269a0c1e3
|
4
|
+
data.tar.gz: a2b254f45c3532b226c226a446abb73ca95afd63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc683b0bd9d8094ad23bb3328a60335bca99d1ff58568817bb9b76b485c4a485efb05e45d7ce7330bea94515aca55d1f784c467a6a0d136b51e690bcb8b7706b
|
7
|
+
data.tar.gz: 2be8d8141f6c6b4c1682051ea80216cb36ea954ee63d71033236448e9628294e4b2b654acba6535c579b05261c7cd7b1bf8735bd43c6a3893b6960b9fce7a446
|
data/README.md
CHANGED
@@ -4,11 +4,11 @@ bower-rails
|
|
4
4
|
[![Gem Version](http://img.shields.io/gem/v/bower-rails.svg)][gem]
|
5
5
|
[![Code Climate](http://img.shields.io/codeclimate/github/42dev/bower-rails.svg)][codeclimate]
|
6
6
|
[![Dependency Status](http://img.shields.io/gemnasium/SergeyKishenin/bower-rails.svg)][gemnasium]
|
7
|
-
[![Build Status](
|
7
|
+
[![Build Status](https://travis-ci.org/42dev/bower-rails.svg?branch=master)][travis]
|
8
8
|
[![Coverage Status](https://coveralls.io/repos/42dev/bower-rails/badge.png)][coveralls]
|
9
9
|
|
10
10
|
[gem]: https://rubygems.org/gems/bower-rails
|
11
|
-
[travis]: https://travis-ci.org/
|
11
|
+
[travis]: https://travis-ci.org/42dev/bower-rails
|
12
12
|
[gemnasium]: https://gemnasium.com/SergeyKishenin/bower-rails
|
13
13
|
[codeclimate]: https://codeclimate.com/github/42dev/bower-rails
|
14
14
|
[coveralls]: https://coveralls.io/r/42dev/bower-rails
|
@@ -157,6 +157,30 @@ results in the following bower.json file:
|
|
157
157
|
```
|
158
158
|
NOTE: Available dependency groups are `:dependencies` (default) and `:dev_dependencies`. Others are not allowed according to the Rails convention.
|
159
159
|
|
160
|
+
## Bower Resolutions
|
161
|
+
|
162
|
+
To specify a [bower resolution][] use `resolution` DSL method in your Bowerfile:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
resolution "angular", "1.2.22"
|
166
|
+
```
|
167
|
+
|
168
|
+
That will produce `bower.json` like:
|
169
|
+
|
170
|
+
``` javascript
|
171
|
+
{
|
172
|
+
"name" : "dsl-generated dependencies",
|
173
|
+
"dependencies" : {
|
174
|
+
"angular" : "1.2.22"
|
175
|
+
},
|
176
|
+
"resolutions": {
|
177
|
+
"angular": "1.2.22"
|
178
|
+
}
|
179
|
+
}
|
180
|
+
```
|
181
|
+
|
182
|
+
[#bower resolution]: http://jaketrent.com/post/bower-resolutions/
|
183
|
+
|
160
184
|
##Configuration
|
161
185
|
|
162
186
|
Change options in your `config/initializers/bower_rails.rb`:
|
data/lib/bower-rails/dsl.rb
CHANGED
@@ -17,37 +17,10 @@ module BowerRails
|
|
17
17
|
@root_path = root_path
|
18
18
|
@bower_dependencies_list = []
|
19
19
|
@dependencies = {}
|
20
|
+
@resolutions = {}
|
20
21
|
@assets_path ||= "assets"
|
21
22
|
end
|
22
23
|
|
23
|
-
def eval_file(file)
|
24
|
-
instance_eval(File.open(file, "rb") { |f| f.read }, file.to_s)
|
25
|
-
end
|
26
|
-
|
27
|
-
def directories
|
28
|
-
@dependencies.keys
|
29
|
-
end
|
30
|
-
|
31
|
-
def group(name, options = {}, &block)
|
32
|
-
options[:assets_path] ||= @assets_path
|
33
|
-
|
34
|
-
assert_asset_path options[:assets_path]
|
35
|
-
assert_group_name name
|
36
|
-
|
37
|
-
@current_group = add_group name, options
|
38
|
-
yield if block_given?
|
39
|
-
end
|
40
|
-
|
41
|
-
def dependency_group(name, options = {}, &block)
|
42
|
-
|
43
|
-
assert_dependency_group_name name
|
44
|
-
add_dependency_group name
|
45
|
-
|
46
|
-
yield if block_given?
|
47
|
-
|
48
|
-
remove_dependency_group!
|
49
|
-
end
|
50
|
-
|
51
24
|
def asset(name, *args)
|
52
25
|
group = @current_group || default_group
|
53
26
|
options = Hash === args.last ? args.pop.dup : {}
|
@@ -71,28 +44,22 @@ module BowerRails
|
|
71
44
|
@dependencies[normalized_group_path][current_dependency_group_normalized][name] = version
|
72
45
|
end
|
73
46
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
47
|
+
def dependency_group(name, options = {}, &block)
|
48
|
+
|
49
|
+
assert_dependency_group_name name
|
50
|
+
add_dependency_group name
|
51
|
+
|
52
|
+
yield if block_given?
|
53
|
+
|
54
|
+
remove_dependency_group!
|
81
55
|
end
|
82
56
|
|
83
|
-
def
|
84
|
-
|
85
|
-
contents["directory"] = "bower_components"
|
86
|
-
JSON.pretty_generate(contents)
|
57
|
+
def directories
|
58
|
+
@dependencies.keys
|
87
59
|
end
|
88
60
|
|
89
|
-
def
|
90
|
-
|
91
|
-
normalized_group_path = normalize_location_path(group.first, group_assets_path(group))
|
92
|
-
File.open(File.join(normalized_group_path, ".bowerrc"), "w") do |f|
|
93
|
-
f.write(generate_dotbowerrc)
|
94
|
-
end
|
95
|
-
end
|
61
|
+
def eval_file(file)
|
62
|
+
instance_eval(File.open(file, "rb") { |f| f.read }, file.to_s)
|
96
63
|
end
|
97
64
|
|
98
65
|
def final_assets_path
|
@@ -101,31 +68,56 @@ module BowerRails
|
|
101
68
|
end.uniq
|
102
69
|
end
|
103
70
|
|
71
|
+
def generate_dotbowerrc
|
72
|
+
contents = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {}
|
73
|
+
contents["directory"] = "bower_components"
|
74
|
+
JSON.pretty_generate(contents)
|
75
|
+
end
|
76
|
+
|
104
77
|
def group_assets_path group
|
105
78
|
group.last[:assets_path]
|
106
79
|
end
|
107
80
|
|
108
|
-
|
81
|
+
def group(name, options = {}, &block)
|
82
|
+
options[:assets_path] ||= @assets_path
|
109
83
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@
|
84
|
+
assert_asset_path options[:assets_path]
|
85
|
+
assert_group_name name
|
86
|
+
|
87
|
+
@current_group = add_group name, options
|
88
|
+
yield if block_given?
|
114
89
|
end
|
115
90
|
|
116
|
-
|
117
|
-
|
118
|
-
def current_dependency_group_normalized
|
119
|
-
normalize_dependency_group_name current_dependency_group
|
91
|
+
def resolution(name, version)
|
92
|
+
@resolutions[name] = version
|
120
93
|
end
|
121
94
|
|
122
|
-
|
123
|
-
|
124
|
-
def normalize_dependency_group_name(name)
|
125
|
-
segments = name.to_s.dup.downcase.split(/_/)
|
126
|
-
[segments.shift, *segments.map{ |word| word.capitalize }].join('').to_sym
|
95
|
+
def resolutions_with_root
|
96
|
+
{ :resolutions => @resolutions }
|
127
97
|
end
|
128
98
|
|
99
|
+
def write_bower_json
|
100
|
+
@dependencies.each do |dir, data|
|
101
|
+
|
102
|
+
FileUtils.mkdir_p dir unless File.directory? dir
|
103
|
+
File.open(File.join(dir, "bower.json"), "w") do |f|
|
104
|
+
data.merge!(resolutions_with_root)
|
105
|
+
f.write(dependencies_to_json(data))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def write_dotbowerrc
|
111
|
+
groups.map do |group|
|
112
|
+
normalized_group_path = normalize_location_path(group.first, group_assets_path(group))
|
113
|
+
File.open(File.join(normalized_group_path, ".bowerrc"), "w") do |f|
|
114
|
+
f.write(generate_dotbowerrc)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
129
121
|
# Stores the dependency group name in the stack
|
130
122
|
#
|
131
123
|
def add_dependency_group(dependency_group)
|
@@ -134,32 +126,10 @@ module BowerRails
|
|
134
126
|
dependency_group
|
135
127
|
end
|
136
128
|
|
137
|
-
# Removes the dependency group name in the stack
|
138
|
-
#
|
139
|
-
def remove_dependency_group!
|
140
|
-
@dependency_groups.pop
|
141
|
-
end
|
142
|
-
|
143
129
|
def add_group(*group)
|
144
130
|
@groups = (groups << group) and return group
|
145
131
|
end
|
146
132
|
|
147
|
-
def groups
|
148
|
-
@groups ||= [default_group]
|
149
|
-
end
|
150
|
-
|
151
|
-
def default_group
|
152
|
-
[:vendor, { :assets_path => @assets_path }]
|
153
|
-
end
|
154
|
-
|
155
|
-
# Attempts to parse data from @dependencies to JSON
|
156
|
-
#
|
157
|
-
def dependencies_to_json(data)
|
158
|
-
JSON.pretty_generate({
|
159
|
-
:name => "dsl-generated dependencies"
|
160
|
-
}.merge(data))
|
161
|
-
end
|
162
|
-
|
163
133
|
def assert_dependency_group_name(name)
|
164
134
|
unless [:dependencies, :devDependencies].include?(normalize_dependency_group_name(name))
|
165
135
|
raise ArgumentError, "Dependency group should be either dependencies or dev_dependencies, provided: #{name}"
|
@@ -181,8 +151,49 @@ module BowerRails
|
|
181
151
|
raise ArgumentError, "Group name should be :lib or :vendor only" unless [:lib, :vendor].include?(name)
|
182
152
|
end
|
183
153
|
|
154
|
+
# Returns name for the current dependency from the stack
|
155
|
+
#
|
156
|
+
def current_dependency_group
|
157
|
+
@dependency_groups.last || DEFAULT_DEPENDENCY_GROUP.to_sym
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns normalized current dependency group name
|
161
|
+
#
|
162
|
+
def current_dependency_group_normalized
|
163
|
+
normalize_dependency_group_name current_dependency_group
|
164
|
+
end
|
165
|
+
|
166
|
+
def default_group
|
167
|
+
[:vendor, { :assets_path => @assets_path }]
|
168
|
+
end
|
169
|
+
|
170
|
+
# Attempts to parse data from @dependencies to JSON
|
171
|
+
#
|
172
|
+
def dependencies_to_json(data)
|
173
|
+
JSON.pretty_generate({
|
174
|
+
:name => "dsl-generated dependencies"
|
175
|
+
}.merge(data))
|
176
|
+
end
|
177
|
+
|
178
|
+
def groups
|
179
|
+
@groups ||= [default_group]
|
180
|
+
end
|
181
|
+
|
182
|
+
# Implementing ActiveSupport::Inflector camelize(:lower)
|
183
|
+
#
|
184
|
+
def normalize_dependency_group_name(name)
|
185
|
+
segments = name.to_s.dup.downcase.split(/_/)
|
186
|
+
[segments.shift, *segments.map{ |word| word.capitalize }].join('').to_sym
|
187
|
+
end
|
188
|
+
|
184
189
|
def normalize_location_path(loc, assets_path)
|
185
190
|
File.join(root_path, loc.to_s, assets_path)
|
186
191
|
end
|
192
|
+
|
193
|
+
# Removes the dependency group name in the stack
|
194
|
+
#
|
195
|
+
def remove_dependency_group!
|
196
|
+
@dependency_groups.pop
|
197
|
+
end
|
187
198
|
end
|
188
199
|
end
|
@@ -120,7 +120,7 @@ module BowerRails
|
|
120
120
|
Dir['bower_components/**/*.css'].each do |filename|
|
121
121
|
contents = File.read(filename) if FileTest.file?(filename)
|
122
122
|
# http://www.w3.org/TR/CSS2/syndata.html#uri
|
123
|
-
url_regex = /url\(\s*['"]?(?![a-z]+:)([^'"\)]*)['"]?\s*\)/
|
123
|
+
url_regex = /url\((?!\#)\s*['"]?(?![a-z]+:)([^'"\)]*)['"]?\s*\)/
|
124
124
|
|
125
125
|
# Resolve paths in CSS file if it contains a url
|
126
126
|
if contents =~ url_regex
|
data/lib/bower-rails/railtie.rb
CHANGED
data/lib/bower-rails/version.rb
CHANGED
@@ -10,4 +10,7 @@ BowerRails.configure do |bower_rails|
|
|
10
10
|
|
11
11
|
# Invokes rake bower:clean before precompilation. Defaults to false
|
12
12
|
# bower_rails.clean_before_precompile = true
|
13
|
-
|
13
|
+
|
14
|
+
# Invokes rake bower:install:deployment instead rake bower:install. Defaults to false
|
15
|
+
# bower_rails.use_bower_install_deployment = true
|
16
|
+
end
|
data/lib/tasks/bower.rake
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'tasks/helpers/before_hook'
|
1
2
|
require 'bower-rails/performer'
|
2
3
|
|
3
4
|
include BeforeHook
|
@@ -78,7 +79,7 @@ namespace :bower do
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
|
-
|
82
|
+
before_rake_task 'assets:precompile' do
|
82
83
|
BowerRails.tasks.map do |task|
|
83
84
|
Rake::Task[task].invoke
|
84
85
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module BeforeHook
|
2
|
-
# The `before` hook for rake tasks.
|
2
|
+
# The `before` hook for rake tasks.
|
3
3
|
# The code was taken from https://github.com/guillermo/rake-hooks/blob/master/lib/rake/hooks.rb#L2
|
4
|
-
def
|
4
|
+
def before_rake_task(*task_names, &new_task)
|
5
5
|
task_names.each do |task_name|
|
6
6
|
old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
|
7
7
|
return unless old_task
|