bagger 0.0.2 → 0.1.0
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.
- data/CHANGELOG.md +6 -0
- data/README.md +12 -4
- data/ROADMAP.md +12 -9
- data/lib/bagger/packager.rb +49 -23
- data/lib/bagger/version.rb +1 -1
- data/test/bagger_test.rb +90 -9
- metadata +15 -15
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## v 0.1.0
|
4
|
+
|
5
|
+
* Combine javascript and stylesheets into several packages
|
6
|
+
* Change of configuration API. The javascript and stylesheets are now
|
7
|
+
defined as an array. See the updated README.md for an example
|
8
|
+
|
3
9
|
## v 0.0.2
|
4
10
|
|
5
11
|
* Make file and cache manifest path configurable
|
data/README.md
CHANGED
@@ -55,10 +55,18 @@ cache.manifest
|
|
55
55
|
:manifest_path => manifest_path,
|
56
56
|
:cache_manifest_path => cache_manifest_path,
|
57
57
|
:combine => {
|
58
|
-
:stylesheets =>
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
:stylesheets => [
|
59
|
+
{
|
60
|
+
:target_path => 'css/all.css',
|
61
|
+
:files => stylesheets
|
62
|
+
}
|
63
|
+
],
|
64
|
+
:javascripts => [
|
65
|
+
{
|
66
|
+
:target_path => 'js/combined.js',
|
67
|
+
:files => javascripts
|
68
|
+
}
|
69
|
+
]
|
62
70
|
}
|
63
71
|
}
|
64
72
|
|
data/ROADMAP.md
CHANGED
@@ -18,18 +18,21 @@
|
|
18
18
|
|
19
19
|
## v 0.1.0
|
20
20
|
|
21
|
-
*
|
21
|
+
* support for packages. e.g
|
22
|
+
|
23
|
+
:stylesheets => {
|
24
|
+
:common => ['main.css', 'fonts.css'],
|
25
|
+
:dialogs => ['modal.css', 'info_box.css']
|
26
|
+
}
|
27
|
+
|
28
|
+
## v 0.2.0
|
22
29
|
|
23
|
-
|
30
|
+
* generate custom manifest files e.g with support for file size.
|
31
|
+
This can be useful for preloaders
|
32
|
+
|
33
|
+
{
|
24
34
|
'/myfile.txt' => {
|
25
35
|
:path => '/myfile.19db9a16e2b73017c575570de577d103.txt'
|
26
36
|
:size => '391'
|
27
37
|
}
|
28
38
|
}
|
29
|
-
|
30
|
-
* support for packages. e.g
|
31
|
-
|
32
|
-
:stylesheets => {
|
33
|
-
:common => ['main.css', 'fonts.css'],
|
34
|
-
:dialogs => ['modal.css', 'info_box.css']
|
35
|
-
}
|
data/lib/bagger/packager.rb
CHANGED
@@ -10,14 +10,12 @@ module Bagger
|
|
10
10
|
|
11
11
|
def initialize(options)
|
12
12
|
@options = options
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@source_dir = @options[:source_dir]
|
14
|
+
@target_dir = @options[:target_dir]
|
15
15
|
@source_dir = @options[:source_dir]
|
16
16
|
@target_dir = @options[:target_dir]
|
17
17
|
@manifest_path = @options[:manifest_path] || File.join(@source_dir, 'manifest.json')
|
18
18
|
@cache_manifest_path = @options[:cache_manifest_path] || 'cache.manifest'
|
19
|
-
@stylesheet_path = (@options[:combine] || {})[:stylesheet_path] || 'combined.css'
|
20
|
-
@javascript_path = (@options[:combine] || {})[:javascript_path] || 'combined.js'
|
21
19
|
@path_prefix = @options[:path_prefix] || ''
|
22
20
|
@manifest = {}
|
23
21
|
end
|
@@ -38,16 +36,19 @@ module Bagger
|
|
38
36
|
@manifest[manifest_key_path] = effective_path
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
39
|
+
def stylesheets
|
40
|
+
@stylesheets ||= calculate_stylesheets
|
41
|
+
end
|
42
|
+
|
43
|
+
def javascripts
|
44
|
+
@javascripts ||= calculate_javascripts
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
42
48
|
validate
|
49
|
+
version_files
|
43
50
|
combine_css
|
44
51
|
combine_js
|
45
|
-
version_files
|
46
|
-
rewrite_urls_in_css
|
47
|
-
compress_css
|
48
|
-
to_manifest(@stylesheet_path, false)
|
49
|
-
compress_js
|
50
|
-
to_manifest(@javascript_path, false)
|
51
52
|
generate_and_version_cache_manifest
|
52
53
|
write_manifest
|
53
54
|
end
|
@@ -72,14 +73,19 @@ module Bagger
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def combine_css
|
75
|
-
|
76
|
+
stylesheets.each do |config|
|
77
|
+
combine_files(config[:files], config[:target_path])
|
78
|
+
rewrite_urls_in_css(config[:target_path])
|
79
|
+
compress_css(config[:target_path])
|
80
|
+
to_manifest(config[:target_path], false)
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
|
-
def rewrite_urls_in_css
|
84
|
+
def rewrite_urls_in_css(stylesheet_path)
|
79
85
|
url_regex = /(^|[{;])(.*?url\(\s*['"]?)(.*?)(['"]?\s*\).*?)([;}]|$)/ui
|
80
86
|
behavior_regex = /behavior:\s*url/ui
|
81
87
|
data_regex = /^\s*data:/ui
|
82
|
-
input = File.open(File.join(@target_dir,
|
88
|
+
input = File.open(File.join(@target_dir, stylesheet_path)){|f| f.read}
|
83
89
|
output = input.gsub(url_regex) do |full_match|
|
84
90
|
pre, url_match, post = ($1 + $2), $3, ($4 + $5)
|
85
91
|
if behavior_regex.match(pre) || data_regex.match(url_match)
|
@@ -94,27 +100,31 @@ module Bagger
|
|
94
100
|
end
|
95
101
|
end
|
96
102
|
end
|
97
|
-
File.open(File.join(@target_dir,
|
103
|
+
File.open(File.join(@target_dir, stylesheet_path), 'w') do |f|
|
98
104
|
f.write output
|
99
105
|
end
|
100
106
|
end
|
101
107
|
|
102
|
-
def compress_css
|
103
|
-
css = File.open(File.join(@target_dir,
|
108
|
+
def compress_css(stylesheet_path)
|
109
|
+
css = File.open(File.join(@target_dir, stylesheet_path)){|f| f.read}
|
104
110
|
compressed = Rainpress.compress(css)
|
105
|
-
File.open(File.join(@target_dir,
|
111
|
+
File.open(File.join(@target_dir, stylesheet_path), 'w') do |f|
|
106
112
|
f.write compressed
|
107
113
|
end
|
108
114
|
end
|
109
115
|
|
110
116
|
def combine_js
|
111
|
-
|
117
|
+
javascripts.each do |config|
|
118
|
+
combine_files(config[:files], config[:target_path])
|
119
|
+
compress_js(config[:target_path])
|
120
|
+
to_manifest(config[:target_path], false)
|
121
|
+
end
|
112
122
|
end
|
113
123
|
|
114
|
-
def compress_js
|
115
|
-
javascript = File.open(File.join(@target_dir,
|
124
|
+
def compress_js(javascript_path)
|
125
|
+
javascript = File.open(File.join(@target_dir, javascript_path)){|f| f.read}
|
116
126
|
compressed = Uglifier.compile(javascript)
|
117
|
-
File.open(File.join(@target_dir,
|
127
|
+
File.open(File.join(@target_dir, javascript_path), 'w'){|f| f.write compressed}
|
118
128
|
end
|
119
129
|
|
120
130
|
def generate_and_version_cache_manifest
|
@@ -132,7 +142,7 @@ module Bagger
|
|
132
142
|
to_manifest(@cache_manifest_path)
|
133
143
|
end
|
134
144
|
|
135
|
-
|
145
|
+
protected
|
136
146
|
|
137
147
|
def combine_files(files, path)
|
138
148
|
output = ''
|
@@ -145,6 +155,22 @@ module Bagger
|
|
145
155
|
File.open(target_path, "w") { |f| f.write(output) }
|
146
156
|
end
|
147
157
|
|
158
|
+
def calculate_stylesheets
|
159
|
+
if @options[:combine] && @options[:combine][:stylesheets]
|
160
|
+
@options[:combine][:stylesheets]
|
161
|
+
else
|
162
|
+
[]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def calculate_javascripts
|
167
|
+
if @options[:combine] && @options[:combine][:javascripts]
|
168
|
+
@options[:combine][:javascripts]
|
169
|
+
else
|
170
|
+
[]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
148
174
|
def validate
|
149
175
|
raise_error "Source directory does not exist: #{@source_dir}" unless File.exists?(@source_dir)
|
150
176
|
end
|
data/lib/bagger/version.rb
CHANGED
data/test/bagger_test.rb
CHANGED
@@ -6,7 +6,7 @@ class BaggerTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
@source_dir = Dir.mktmpdir
|
8
8
|
@target_dir = Dir.mktmpdir
|
9
|
-
Uglifier.stubs(:compile).returns('//
|
9
|
+
Uglifier.stubs(:compile).returns('//minified js');
|
10
10
|
end
|
11
11
|
|
12
12
|
def teardown
|
@@ -110,8 +110,10 @@ class BaggerTest < Test::Unit::TestCase
|
|
110
110
|
context 'css files' do
|
111
111
|
setup do
|
112
112
|
@config = {
|
113
|
-
:stylesheets => [
|
114
|
-
|
113
|
+
:stylesheets => [{
|
114
|
+
:target_path => 'css/combined.css',
|
115
|
+
:files => []
|
116
|
+
}]
|
115
117
|
}
|
116
118
|
@css_dir = File.join(@source_dir, 'css')
|
117
119
|
FileUtils.mkdir_p(@css_dir)
|
@@ -120,7 +122,7 @@ class BaggerTest < Test::Unit::TestCase
|
|
120
122
|
File.join(@css_dir, "#{file}.css"),
|
121
123
|
".#{file}{}"
|
122
124
|
)
|
123
|
-
@config[:stylesheets] << "css/#{file}.css"
|
125
|
+
@config[:stylesheets][0][:files] << "css/#{file}.css"
|
124
126
|
end
|
125
127
|
end
|
126
128
|
|
@@ -153,7 +155,7 @@ class BaggerTest < Test::Unit::TestCase
|
|
153
155
|
assert !File.exists?(File.join(@target_dir, 'css', 'one.css'))
|
154
156
|
end
|
155
157
|
|
156
|
-
should '
|
158
|
+
should 'minify it' do
|
157
159
|
Rainpress.stubs(:compress).returns('//super minified css');
|
158
160
|
Bagger.bagit!(
|
159
161
|
:source_dir => @source_dir,
|
@@ -179,7 +181,7 @@ class BaggerTest < Test::Unit::TestCase
|
|
179
181
|
}
|
180
182
|
EOF
|
181
183
|
write_file(File.join(@css_dir, "urled.css"), css)
|
182
|
-
@config[:stylesheets] << 'css/urled.css'
|
184
|
+
@config[:stylesheets][0][:files] << 'css/urled.css'
|
183
185
|
FileUtils.mkdir_p(File.join(@source_dir, 'images'))
|
184
186
|
%w(root relative absolute).each do |type|
|
185
187
|
FileUtils.touch(File.join(@source_dir, 'images', "#{type}.png"))
|
@@ -233,8 +235,12 @@ class BaggerTest < Test::Unit::TestCase
|
|
233
235
|
context 'combine javascript' do
|
234
236
|
setup do
|
235
237
|
@config = {
|
236
|
-
:javascripts => [
|
237
|
-
|
238
|
+
:javascripts => [
|
239
|
+
{
|
240
|
+
:target_path => 'js/combined.js',
|
241
|
+
:files => []
|
242
|
+
}
|
243
|
+
]
|
238
244
|
}
|
239
245
|
@js_dir = File.join(@source_dir, 'js')
|
240
246
|
FileUtils.mkdir_p(@js_dir)
|
@@ -243,7 +249,7 @@ class BaggerTest < Test::Unit::TestCase
|
|
243
249
|
File.join(@js_dir, "#{file}.js"),
|
244
250
|
"var #{file} = 1;"
|
245
251
|
)
|
246
|
-
@config[:javascripts] << "js/#{file}.js"
|
252
|
+
@config[:javascripts][0][:files] << "js/#{file}.js"
|
247
253
|
end
|
248
254
|
end
|
249
255
|
|
@@ -288,4 +294,79 @@ class BaggerTest < Test::Unit::TestCase
|
|
288
294
|
assert_equal '//minified javascript', File.open(expected_file_path){|f| f.read}
|
289
295
|
end
|
290
296
|
end
|
297
|
+
|
298
|
+
context 'packages' do
|
299
|
+
|
300
|
+
setup do
|
301
|
+
@config = {
|
302
|
+
:javascripts => [
|
303
|
+
{
|
304
|
+
:target_path => 'js/common.js',
|
305
|
+
:files => []
|
306
|
+
},
|
307
|
+
{
|
308
|
+
:target_path => 'js/navigation.js',
|
309
|
+
:files => []
|
310
|
+
}
|
311
|
+
],
|
312
|
+
:stylesheets => [
|
313
|
+
{
|
314
|
+
:target_path => 'css/common.css',
|
315
|
+
:files => []
|
316
|
+
},
|
317
|
+
{
|
318
|
+
:target_path => 'css/navigation.css',
|
319
|
+
:files => []
|
320
|
+
}
|
321
|
+
]
|
322
|
+
}
|
323
|
+
@js_dir = File.join(@source_dir, 'js')
|
324
|
+
FileUtils.mkdir_p(@js_dir)
|
325
|
+
@css_dir = File.join(@source_dir, 'css')
|
326
|
+
FileUtils.mkdir_p(@css_dir)
|
327
|
+
|
328
|
+
%w(one two).each do |file|
|
329
|
+
write_file(
|
330
|
+
File.join(@js_dir, "#{file}.js"),
|
331
|
+
"var #{file} = 1;"
|
332
|
+
)
|
333
|
+
write_file(
|
334
|
+
File.join(@css_dir, "#{file}.css"),
|
335
|
+
"##{file} { color : black }"
|
336
|
+
)
|
337
|
+
end
|
338
|
+
@config[:javascripts][0][:files] << 'js/one.js';
|
339
|
+
@config[:javascripts][1][:files] << 'js/two.js';
|
340
|
+
@config[:stylesheets][0][:files] << 'css/one.css';
|
341
|
+
@config[:stylesheets][1][:files] << 'css/two.css';
|
342
|
+
|
343
|
+
Rainpress.stubs(:compress).returns('//minified css');
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
should 'allow to bundle javascript into packages' do
|
348
|
+
Bagger.bagit!(
|
349
|
+
:source_dir => @source_dir,
|
350
|
+
:target_dir => @target_dir,
|
351
|
+
:combine => @config
|
352
|
+
)
|
353
|
+
expected_file_path = File.join(@target_dir, manifest['/js/common.js'])
|
354
|
+
assert_equal '//minified js', File.open(expected_file_path){|f| f.read}
|
355
|
+
expected_file_path = File.join(@target_dir, manifest['/js/navigation.js'])
|
356
|
+
assert_equal '//minified js', File.open(expected_file_path){|f| f.read}
|
357
|
+
end
|
358
|
+
|
359
|
+
should 'allow to bundle stylesheets into packages' do
|
360
|
+
Bagger.bagit!(
|
361
|
+
:source_dir => @source_dir,
|
362
|
+
:target_dir => @target_dir,
|
363
|
+
:combine => @config
|
364
|
+
)
|
365
|
+
expected_file_path = File.join(@target_dir, manifest['/css/common.css'])
|
366
|
+
assert_equal '//minified css', File.open(expected_file_path){|f| f.read}
|
367
|
+
expected_file_path = File.join(@target_dir, manifest['/css/navigation.css'])
|
368
|
+
assert_equal '//minified css', File.open(expected_file_path){|f| f.read}
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
291
372
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-08-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70153224223720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70153224223720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: addressable
|
27
|
-
requirement: &
|
27
|
+
requirement: &70153224223120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70153224223120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: uglifier
|
38
|
-
requirement: &
|
38
|
+
requirement: &70153224222560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70153224222560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rainpress
|
49
|
-
requirement: &
|
49
|
+
requirement: &70153224221960 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70153224221960
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70153224221440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70153224221440
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda-context
|
71
|
-
requirement: &
|
71
|
+
requirement: &70153224220920 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70153224220920
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mocha
|
82
|
-
requirement: &
|
82
|
+
requirement: &70153224220300 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70153224220300
|
91
91
|
description: ! 'A framework agnostic packaging solution for your assets: version files,
|
92
92
|
combine them, minify them and create a manifest'
|
93
93
|
email:
|