bagger 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +8 -6
- data/ROADMAP.md +0 -39
- data/lib/bagger/packager.rb +27 -3
- data/lib/bagger/version.rb +1 -1
- data/test/bagger_test.rb +45 -0
- data/tests.watchr +1 -1
- metadata +16 -16
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
# v 0.5.0
|
4
|
+
|
5
|
+
* gzip support for stylesheets and javascripts (Christian Lundgren)
|
6
|
+
* Extended manifest with info file size (Christian Lundgren)
|
7
|
+
* verbose option
|
8
|
+
|
3
9
|
# v 0.4.0
|
4
10
|
|
5
11
|
* Support for css_path_prefix allows rewritten urls in stylesheets to
|
data/README.md
CHANGED
@@ -56,14 +56,16 @@ on the client side by using the following techniques:
|
|
56
56
|
|
57
57
|
# define the options hash
|
58
58
|
options = {
|
59
|
-
:source_dir =>
|
60
|
-
:target_dir =>
|
59
|
+
:source_dir => source_dir,
|
60
|
+
:target_dir => target_dir,
|
61
61
|
:manifest_path => manifest_path,
|
62
|
+
:gzip => false,
|
63
|
+
:verbose => false,
|
62
64
|
:cache_manifest_path => cache_manifest_path,
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
:path_prefix => '',
|
66
|
+
:css_path_prefix => '',
|
67
|
+
:exclude_pattern => /.*\.less/,
|
68
|
+
:exclude_files => [ 'css/main.sass', 'css/style.sass' ]
|
67
69
|
:combine => {
|
68
70
|
:stylesheets => [
|
69
71
|
{
|
data/ROADMAP.md
CHANGED
@@ -1,46 +1,7 @@
|
|
1
1
|
# ROADMAP
|
2
2
|
|
3
|
-
## v 0.0.1
|
4
|
-
|
5
|
-
* Combines javascript
|
6
|
-
* Minfies javascript with [UglifyJS](https://github.com/mishoo/UglifyJS)
|
7
|
-
* Combines stylesheets
|
8
|
-
* Rewrites urls in stylesheets
|
9
|
-
* Minfies stylesheets with [rainpress](https://rubygems.org/gems/rainpress)
|
10
|
-
* Generates versioned file names e.g /images/logo.19db9a16e2b73017c575570de577d103.png
|
11
|
-
* Generates a manifest file in JSON
|
12
|
-
* Generates an HTML 5 cache manifest
|
13
|
-
|
14
|
-
## v 0.0.2
|
15
|
-
|
16
|
-
* allow to specify the the paths for cache.manifest and manifest.json
|
17
|
-
* better validation
|
18
|
-
|
19
|
-
## v 0.1.0
|
20
|
-
|
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
|
29
|
-
|
30
|
-
* Support for multiple cache manifests (useful if you have different
|
31
|
-
resources for different devices)
|
32
|
-
|
33
3
|
## v 1.0.0
|
34
4
|
|
35
|
-
* generate custom manifest files e.g with support for file size.
|
36
|
-
This can be useful for preloaders
|
37
|
-
|
38
|
-
{
|
39
|
-
'/myfile.txt' => {
|
40
|
-
:path => '/myfile.19db9a16e2b73017c575570de577d103.txt'
|
41
|
-
:size => '391'
|
42
|
-
}
|
43
|
-
}
|
44
5
|
* Support for lesscss as a preprocessor
|
45
6
|
* Support for sass as a preprocessor
|
46
7
|
* Support for gzipping files
|
data/lib/bagger/packager.rb
CHANGED
@@ -4,6 +4,7 @@ require 'digest/md5'
|
|
4
4
|
require 'addressable/uri'
|
5
5
|
require 'uglifier'
|
6
6
|
require 'rainpress'
|
7
|
+
require 'zlib'
|
7
8
|
|
8
9
|
module Bagger
|
9
10
|
class Packager
|
@@ -12,8 +13,6 @@ module Bagger
|
|
12
13
|
@options = options
|
13
14
|
@source_dir = @options[:source_dir]
|
14
15
|
@target_dir = @options[:target_dir]
|
15
|
-
@source_dir = @options[:source_dir]
|
16
|
-
@target_dir = @options[:target_dir]
|
17
16
|
@manifest_path = @options[:manifest_path] || File.join(@source_dir, 'manifest.json')
|
18
17
|
@cache_manifest_path = @options[:cache_manifest_path] || 'cache.manifest'
|
19
18
|
@path_prefix = @options[:path_prefix] || ''
|
@@ -24,10 +23,18 @@ module Bagger
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def add_to_manifest(key, path)
|
27
|
-
@
|
26
|
+
if @options[:extended_manifest]
|
27
|
+
@manifest[key] = {
|
28
|
+
:path => File.expand_path(@path_prefix + "/" + path),
|
29
|
+
:size => File.size(File.join(@target_dir, path))
|
30
|
+
}
|
31
|
+
else
|
32
|
+
@manifest[key] = File.expand_path(@path_prefix + "/" + path)
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
def to_manifest(path, keep_original = true)
|
37
|
+
debug "adding: #{path}"
|
31
38
|
content = File.open(File.join(@target_dir, path)) { |f| f.read }
|
32
39
|
extension = File.extname(path)
|
33
40
|
basename = File.basename(path, extension)
|
@@ -51,12 +58,14 @@ module Bagger
|
|
51
58
|
end
|
52
59
|
|
53
60
|
def run
|
61
|
+
debug "reading files from #{@source_dir}"
|
54
62
|
validate
|
55
63
|
version_files
|
56
64
|
combine_css
|
57
65
|
combine_js
|
58
66
|
generate_cache_manifests
|
59
67
|
write_manifest
|
68
|
+
debug "files written to #{@target_dir}"
|
60
69
|
end
|
61
70
|
|
62
71
|
def write_manifest
|
@@ -85,6 +94,7 @@ module Bagger
|
|
85
94
|
rewrite_urls_in_css(config[:target_path])
|
86
95
|
compress_css(config[:target_path])
|
87
96
|
to_manifest(config[:target_path], false)
|
97
|
+
gzip_target(config[:target_path]) if @options[:gzip]
|
88
98
|
end
|
89
99
|
end
|
90
100
|
|
@@ -125,6 +135,7 @@ module Bagger
|
|
125
135
|
combine_files(config[:files], config[:target_path])
|
126
136
|
compress_js(config[:target_path])
|
127
137
|
to_manifest(config[:target_path], false)
|
138
|
+
gzip_target(config[:target_path]) if @options[:gzip]
|
128
139
|
end
|
129
140
|
end
|
130
141
|
|
@@ -181,6 +192,15 @@ module Bagger
|
|
181
192
|
File.open(target_path, "w") { |f| f.write(output) }
|
182
193
|
end
|
183
194
|
|
195
|
+
def gzip_target(target_path)
|
196
|
+
versioned_path = @manifest[File.join('/', target_path)]
|
197
|
+
versioned_path.sub!(@path_prefix, '')
|
198
|
+
gz_path = File.join(@target_dir, "#{versioned_path}.gz")
|
199
|
+
Zlib::GzipWriter.open(gz_path) do |gz|
|
200
|
+
gz << File.open(File.join(@target_dir, versioned_path)) { |f| f.read }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
184
204
|
def calculate_stylesheets
|
185
205
|
if @options[:combine] && @options[:combine][:stylesheets]
|
186
206
|
@options[:combine][:stylesheets]
|
@@ -208,5 +228,9 @@ module Bagger
|
|
208
228
|
def exclude_file?(path)
|
209
229
|
path =~ /\.(css|js)$/ || @exclude_files.include?(path) || (@exclude_pattern && path =~ @exclude_pattern)
|
210
230
|
end
|
231
|
+
|
232
|
+
def debug(message)
|
233
|
+
STDOUT.puts message if @options[:verbose]
|
234
|
+
end
|
211
235
|
end
|
212
236
|
end
|
data/lib/bagger/version.rb
CHANGED
data/test/bagger_test.rb
CHANGED
@@ -91,6 +91,15 @@ class BaggerTest < Test::Unit::TestCase
|
|
91
91
|
Bagger.bagit!(default_options.merge(:exclude_pattern => /.*\.txt/))
|
92
92
|
assert_nil manifest['/test.txt']
|
93
93
|
end
|
94
|
+
|
95
|
+
should 'support file sizes in an extended manifest' do
|
96
|
+
path = File.join(@source_dir, 'test.txt')
|
97
|
+
write_file(path, 'foo')
|
98
|
+
file_size = File.size(path)
|
99
|
+
Bagger.bagit!(default_options.merge(:extended_manifest => true))
|
100
|
+
assert_match /\/test\..*\.txt/, manifest['/test.txt']['path']
|
101
|
+
assert_equal file_size, manifest['/test.txt']['size']
|
102
|
+
end
|
94
103
|
end
|
95
104
|
|
96
105
|
context 'html 5 cache manifest' do
|
@@ -219,6 +228,24 @@ class BaggerTest < Test::Unit::TestCase
|
|
219
228
|
assert_equal '//super minified css', compressed_content , 'combined css not found'
|
220
229
|
end
|
221
230
|
|
231
|
+
should 'support gzipping css targets' do
|
232
|
+
Rainpress.stubs(:compress).returns('//minified css');
|
233
|
+
Bagger.bagit!(
|
234
|
+
:source_dir => @source_dir,
|
235
|
+
:target_dir => @target_dir,
|
236
|
+
:gzip => true,
|
237
|
+
:combine => @config
|
238
|
+
)
|
239
|
+
|
240
|
+
expected_file_path = File.join(@target_dir, manifest['/css/combined.css'])
|
241
|
+
assert File.exists?(expected_file_path), 'original target does not exist'
|
242
|
+
assert_nil manifest['/css/combined.css.gz'], 'gzipped copy should not be in manifest'
|
243
|
+
expected_file_path << '.gz'
|
244
|
+
assert File.exists?(expected_file_path), 'gzipped copy does not exist'
|
245
|
+
gz_content = Zlib::GzipReader.open(expected_file_path){|gz| gz.read}
|
246
|
+
assert_equal '//minified css', gz_content, 'gzipped copy does not match original'
|
247
|
+
end
|
248
|
+
|
222
249
|
context 'url rewriting' do
|
223
250
|
setup do
|
224
251
|
css = <<-EOF
|
@@ -389,6 +416,24 @@ class BaggerTest < Test::Unit::TestCase
|
|
389
416
|
expected_file_path = File.join(@target_dir, manifest['/js/combined.js'])
|
390
417
|
assert_equal '//minified javascript', File.open(expected_file_path){|f| f.read}
|
391
418
|
end
|
419
|
+
|
420
|
+
should 'support gzipping js targets' do
|
421
|
+
Uglifier.expects(:compile).returns('//minified js')
|
422
|
+
Bagger.bagit!(
|
423
|
+
:source_dir => @source_dir,
|
424
|
+
:target_dir => @target_dir,
|
425
|
+
:gzip => true,
|
426
|
+
:combine => @config
|
427
|
+
)
|
428
|
+
|
429
|
+
expected_file_path = File.join(@target_dir, manifest['/js/combined.js'])
|
430
|
+
assert File.exists?(expected_file_path), 'original target does not exist'
|
431
|
+
assert_nil manifest['/js/combined.js.gz'], 'gzipped copy should not be in manifest'
|
432
|
+
expected_file_path << '.gz'
|
433
|
+
assert File.exists?(expected_file_path), 'gzipped copy does not exist'
|
434
|
+
gz_content = Zlib::GzipReader.open(expected_file_path){|gz| gz.read}
|
435
|
+
assert_equal '//minified js', gz_content, 'gzipped copy does not match original'
|
436
|
+
end
|
392
437
|
end
|
393
438
|
|
394
439
|
context 'packages' do
|
data/tests.watchr
CHANGED
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.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70159436784000 !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: *70159436784000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: addressable
|
27
|
-
requirement: &
|
27
|
+
requirement: &70159436783540 !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: *70159436783540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: uglifier
|
38
|
-
requirement: &
|
38
|
+
requirement: &70159436783080 !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: *70159436783080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rainpress
|
49
|
-
requirement: &
|
49
|
+
requirement: &70159436782300 !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: *70159436782300
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70159436781580 !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: *70159436781580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda-context
|
71
|
-
requirement: &
|
71
|
+
requirement: &70159436781140 !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: *70159436781140
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mocha
|
82
|
-
requirement: &
|
82
|
+
requirement: &70159436780460 !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: *70159436780460
|
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:
|