bagger 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ # v 0.3.1
4
+
5
+ * Support for exclude_files and exclude_pattern. For times when you
6
+ don't want certain files to be processed by bagger
7
+
3
8
  ## v 0.2.1
4
9
 
5
10
  * Updating this particular roadmap
data/README.md CHANGED
@@ -32,12 +32,11 @@ on the client side by using the following techniques:
32
32
  target_dir = "/tmp/bundled_assets"
33
33
  source_dir = "/applications/my_app/public"
34
34
 
35
- # customize paths for file and cache manifest
36
- manifest_path = File.join(target_dir, 'file_manifest.json') #defaults
37
- to manifest.json
35
+ # customize paths for file and cache manifest
36
+ manifest_path = File.join(target_dir, 'file_manifest.json') #defaults
37
+ to manifest.json
38
38
 
39
- cache_manifest_path = 'cache/cache.manifest' # defaults to
40
- cache.manifest
39
+ cache_manifest_path = 'cache/cache.manifest' # defaults to cache.manifest
41
40
 
42
41
  # list the stylesheets and javascripts to be combined
43
42
  # and minified. The order is important, because otherwhise
@@ -45,50 +44,52 @@ cache.manifest
45
44
  stylesheets = ["css/style.css", "css/reset.css"]
46
45
  javascripts = ["js/app.js", "js/utils.js"]
47
46
 
48
- # define cache manifest bundles for different devices
49
- # for convencien, the manfiest defined with `cache_manifest_path`
50
- # will always contain all resources
51
- ipad_resources = ["images/troll-big.png"]
52
- iphone_retina_resources = ["images/troll-retina.png"]
53
- desktop_browser_resources = ["images/troll.png"]
47
+ # define cache manifest bundles for directorfferent devices
48
+ # for convencien, the manfiest defined with `cache_manifest_path`
49
+ # will always contain all resources
50
+ ipad_resources = ["images/troll-big.png"]
51
+ iphone_retina_resources = ["images/troll-retina.png"]
52
+ desktop_browser_resources = ["images/troll.png"]
54
53
 
55
54
  # make sure the target directory exists
56
55
  FileUtils.mkdir_p target_dir
57
56
 
58
57
  # define the options hash
59
58
  options = {
60
- :source_dir => target_dir,
61
- :target_dir => source_dir,
62
- :manifest_path => manifest_path,
63
- :cache_manifest_path => cache_manifest_path,
64
- :combine => {
65
- :stylesheets => [
66
- {
67
- :target_path => 'css/all.css',
68
- :files => stylesheets
69
- }
70
- ],
71
- :javascripts => [
72
- {
73
- :target_path => 'js/combined.js',
74
- :files => javascripts
75
- }
76
- ]
77
- },
78
- :cache_manifests => [
79
- {
80
- :target_path => 'cache/ipad-cache.manifest',
81
- :files => ipad_resources
82
- },
83
- {
84
- :target_path => 'cache/retina-cache.manifest',
85
- :files => iphone_retina_resources
86
- },
87
- {
88
- :target_path => 'cache/desktop.manifest',
89
- :files => desktop_browser_resources
90
- }
91
- ]
59
+ :source_dir => target_dir,
60
+ :target_dir => source_dir,
61
+ :manifest_path => manifest_path,
62
+ :cache_manifest_path => cache_manifest_path,
63
+ :exclude_pattern => /.*\.less/,
64
+ :exclude_files => [ 'css/main.sass', 'css/style.sass' ]
65
+ :combine => {
66
+ :stylesheets => [
67
+ {
68
+ :target_path => 'css/all.css',
69
+ :files => stylesheets
70
+ }
71
+ ],
72
+ :javascripts => [
73
+ {
74
+ :target_path => 'js/combined.js',
75
+ :files => javascripts
76
+ }
77
+ ]
78
+ },
79
+ :cache_manifests => [
80
+ {
81
+ :target_path => 'cache/ipad-cache.manifest',
82
+ :files => ipad_resources
83
+ },
84
+ {
85
+ :target_path => 'cache/retina-cache.manifest',
86
+ :files => iphone_retina_resources
87
+ },
88
+ {
89
+ :target_path => 'cache/desktop.manifest',
90
+ :files => desktop_browser_resources
91
+ }
92
+ ]
92
93
  }
93
94
 
94
95
  # run it
@@ -17,6 +17,8 @@ module Bagger
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
19
  @path_prefix = @options[:path_prefix] || ''
20
+ @exclude_files = Array(@options[:exclude_files])
21
+ @exclude_pattern = @options[:exclude_pattern]
20
22
  @manifest = {}
21
23
  end
22
24
 
@@ -64,11 +66,12 @@ module Bagger
64
66
 
65
67
  def version_files
66
68
  FileUtils.cd(@source_dir) do
67
- Dir["**/*"].reject{ |f| f =~ /\.(css|js)$/ }.each do |path|
69
+ Dir["**/*"].reject{ |f| exclude_file?(f) }.each do |path|
68
70
  if File.directory? path
69
71
  FileUtils.mkdir_p(File.join(@target_dir, path))
70
72
  next
71
73
  end
74
+
72
75
  FileUtils.cp(path, File.join(@target_dir, path))
73
76
  to_manifest(path, false)
74
77
  end
@@ -200,5 +203,9 @@ module Bagger
200
203
  def raise_error(message)
201
204
  raise ValidationError.new(message)
202
205
  end
206
+
207
+ def exclude_file?(path)
208
+ path =~ /\.(css|js)$/ || @exclude_files.include?(path) || (@exclude_pattern && path =~ @exclude_pattern)
209
+ end
203
210
  end
204
211
  end
@@ -1,3 +1,3 @@
1
1
  module Bagger
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
data/test/bagger_test.rb CHANGED
@@ -79,6 +79,18 @@ class BaggerTest < Test::Unit::TestCase
79
79
  Bagger.bagit!(default_options.merge(:manifest_path => manifest_path))
80
80
  assert File.exists?(manifest_path), 'custom manifest path not found'
81
81
  end
82
+
83
+ should 'support an exclude file list' do
84
+ write_file(File.join(@source_dir, 'test.txt'), 'foo')
85
+ Bagger.bagit!(default_options.merge(:exclude_files => 'test.txt'))
86
+ assert_nil manifest['/test.txt']
87
+ end
88
+
89
+ should 'support an exclude file pattern' do
90
+ write_file(File.join(@source_dir, 'test.txt'), 'foo')
91
+ Bagger.bagit!(default_options.merge(:exclude_pattern => /.*\.txt/))
92
+ assert_nil manifest['/test.txt']
93
+ end
82
94
  end
83
95
 
84
96
  context 'html 5 cache manifest' do
@@ -225,11 +237,15 @@ class BaggerTest < Test::Unit::TestCase
225
237
  #absoluteUrl {
226
238
  background: url('http://localhost/absolute.png') top center;
227
239
  }
240
+
241
+ #webkitSpecials {
242
+ -webkit-border-image: url("/images/dash.png") 8 0 8 0 repeat;
243
+ }
228
244
  EOF
229
245
  write_file(File.join(@css_dir, "urled.css"), css)
230
246
  @config[:stylesheets][0][:files] << 'css/urled.css'
231
247
  FileUtils.mkdir_p(File.join(@source_dir, 'images'))
232
- %w(root relative multiple absolute).each do |type|
248
+ %w(root relative multiple absolute dash).each do |type|
233
249
  FileUtils.touch(File.join(@source_dir, 'images', "#{type}.png"))
234
250
  end
235
251
  end
@@ -265,6 +281,16 @@ class BaggerTest < Test::Unit::TestCase
265
281
  assert combined_css.include?(manifest['/images/multiple.png'])
266
282
  end
267
283
 
284
+ should 'rewrite directives that start with a -' do
285
+ Bagger.bagit!(
286
+ :source_dir => @source_dir,
287
+ :target_dir => @target_dir,
288
+ :combine => @config
289
+ )
290
+ combined_css = File.open(File.join(@target_dir, manifest['/css/combined.css'])){|f| f.read}
291
+ assert combined_css.include?(manifest['/images/dash.png'])
292
+ end
293
+
268
294
  should 'not rewrite absolute urls' do
269
295
  Bagger.bagit!(
270
296
  :source_dir => @source_dir,
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.2.1
4
+ version: 0.3.1
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: 2011-09-14 00:00:00.000000000 Z
12
+ date: 2011-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70289388150660 !ruby/object:Gem::Requirement
16
+ requirement: &70222468280260 !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: *70289388150660
24
+ version_requirements: *70222468280260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: addressable
27
- requirement: &70289388150240 !ruby/object:Gem::Requirement
27
+ requirement: &70222468279480 !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: *70289388150240
35
+ version_requirements: *70222468279480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: uglifier
38
- requirement: &70289388149820 !ruby/object:Gem::Requirement
38
+ requirement: &70222468278640 !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: *70289388149820
46
+ version_requirements: *70222468278640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rainpress
49
- requirement: &70289388149360 !ruby/object:Gem::Requirement
49
+ requirement: &70222468278220 !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: *70289388149360
57
+ version_requirements: *70222468278220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70289388148940 !ruby/object:Gem::Requirement
60
+ requirement: &70222468277720 !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: *70289388148940
68
+ version_requirements: *70222468277720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: shoulda-context
71
- requirement: &70289388148520 !ruby/object:Gem::Requirement
71
+ requirement: &70222468277240 !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: *70289388148520
79
+ version_requirements: *70222468277240
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mocha
82
- requirement: &70289388148100 !ruby/object:Gem::Requirement
82
+ requirement: &70222468276800 !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: *70289388148100
90
+ version_requirements: *70222468276800
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: