web_resource_bundler 0.0.14 → 0.0.15

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.
Files changed (43) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +1 -1
  3. data/Readme.md +141 -0
  4. data/VERSION +1 -1
  5. data/lib/web_resource_bundler/content_management/block_data.rb +3 -3
  6. data/lib/web_resource_bundler/content_management/block_parser.rb +2 -2
  7. data/lib/web_resource_bundler/content_management/resource_file.rb +11 -8
  8. data/lib/web_resource_bundler/exceptions.rb +6 -0
  9. data/lib/web_resource_bundler/filters/bundle_filter/resource_packager.rb +1 -1
  10. data/lib/web_resource_bundler/filters/bundle_filter.rb +3 -1
  11. data/lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb +1 -3
  12. data/lib/web_resource_bundler/filters/image_encode_filter/image_data.rb +3 -3
  13. data/lib/web_resource_bundler/filters/image_encode_filter.rb +3 -1
  14. data/lib/web_resource_bundler/rails_app_helpers.rb +5 -3
  15. data/lib/web_resource_bundler/settings_manager.rb +91 -0
  16. data/lib/web_resource_bundler/web_resource_bundler_init.rb +2 -16
  17. data/lib/web_resource_bundler.rb +36 -52
  18. data/spec/sample_block_helper.rb +6 -6
  19. data/spec/spec_helper.rb +14 -6
  20. data/spec/test_data/config/web_resource_bundler.yml +21 -0
  21. data/spec/{public → test_data/public}/foo.css +0 -0
  22. data/spec/{public → test_data/public}/images/good.jpg +0 -0
  23. data/spec/{public → test_data/public}/images/logo.jpg +0 -0
  24. data/spec/{public → test_data/public}/images/sdfo.jpg +0 -0
  25. data/spec/{public → test_data/public}/images/too_big_image.jpg +0 -0
  26. data/spec/{public → test_data/public}/marketing.js +0 -0
  27. data/spec/{public → test_data/public}/salog20.js +0 -0
  28. data/spec/{public → test_data/public}/sample.css +0 -0
  29. data/spec/{public → test_data/public}/seal.js +0 -0
  30. data/spec/{public → test_data/public}/set_cookies.js +0 -0
  31. data/spec/{public → test_data/public}/styles/boo.css +0 -0
  32. data/spec/{public → test_data/public}/styles/for_import.css +0 -0
  33. data/spec/{public → test_data/public}/temp.css +0 -0
  34. data/spec/{public → test_data/public}/test.css +0 -0
  35. data/spec/web_resource_bundler/content_management/resource_file_spec.rb +11 -3
  36. data/spec/web_resource_bundler/filters/bundle_filter/filter_spec.rb +4 -2
  37. data/spec/web_resource_bundler/filters/image_encode_filter/filter_spec.rb +17 -4
  38. data/spec/web_resource_bundler/settings_manager_spec.rb +88 -0
  39. data/spec/web_resource_bundler/web_resource_bundler_spec.rb +96 -94
  40. data/web_resource_bundler.gemspec +23 -23
  41. metadata +25 -22
  42. data/.bundle/config +0 -2
  43. data/README +0 -143
@@ -7,121 +7,123 @@ module WebResourceBundler
7
7
  @bundler = WebResourceBundler::Bundler.instance
8
8
  end
9
9
 
10
- describe "#set_settings" do
11
- it "sets settings_correct property to false if resource dir not specified" do
12
- @bundler.set_settings({})
13
- @bundler.settings_correct.should be_false
14
- end
15
- it "sets settings_correct property to true if resource dir specified" do
16
- @bundler.set_settings({:resource_dir => @s[:resource_dir]})
17
- @bundler.settings_correct.should be_true
10
+ describe "#initialize" do
11
+ it "sets instance state correctly" do
12
+ @bundler.logger.should == nil
13
+ @bundler.settings.should == nil
14
+ @bundler.settings_correct.should == false
18
15
  end
19
16
  end
20
17
 
18
+ context "#bundler setup called" do
19
+ before(:each) do
20
+ @bundler.setup(root_dir, 'development')
21
+ end
22
+
23
+ #describe "#set_settings" do
24
+ # it "changes settings for all filters" do
25
+ # settings = @bundler.settings.dup
26
+ # settings[:base64_filter][:use] = false
27
+ # @bundler.set_settings(settings)
28
+ # end
29
+ #end
21
30
 
22
- describe "#filters_array" do
23
- it "returns array of filters that has :use => true in settings" do
24
- @bundler.set_settings(@s)
25
- filters = @bundler.send("filters_array")
26
- filters.size.should == 3
27
- @bundler.filters.size.should == 3
28
- i = 2
29
- %w{cdn_filter bundle_filter base64_filter}.each do |s|
30
- @s[s.to_sym][:use] = false
31
+ describe "#filters_array" do
32
+ it "returns array of filters that has :use => true in settings" do
31
33
  @bundler.set_settings(@s)
32
34
  filters = @bundler.send("filters_array")
33
- filters.size.should == i
35
+ filters.size.should == 3
34
36
  @bundler.filters.size.should == 3
35
- i -= 1
37
+ i = 2
38
+ %w{cdn_filter bundle_filter base64_filter}.each do |s|
39
+ @s[s.to_sym][:use] = false
40
+ @bundler.set_settings(@s)
41
+ filters = @bundler.send("filters_array")
42
+ filters.size.should == i
43
+ @bundler.filters.size.should == 3
44
+ i -= 1
45
+ end
36
46
  end
37
47
  end
38
- end
39
48
 
40
- describe "#set_filters" do
41
- before(:each) do
42
- @file_manager = FileManager.new(@s[:resource_dir], @s[:cache_dir])
43
- @bundler.instance_eval "@filters={}"
44
- end
45
- it "inits filters if no filters were initialized before" do
46
- @bundler.filters.should == {}
47
- @bundler.send("set_filters", @s, @file_manager)
48
- @bundler.filters.size.should == 3
49
- end
50
- it "sets filters settings if filters already inited" do
51
- @bundler.send("set_filters", @s, @file_manager)
52
- @bundler.filters[:base64_filter].settings[:max_image_size].should == @s[:base64_filter][:max_image_size]
53
- @s[:base64_filter][:max_image_size] = 90
54
- @bundler.send("set_filters", @s, @file_manager)
55
- @bundler.filters[:base64_filter].settings[:max_image_size].should == 90
56
- end
57
- end
58
- describe "#initialize" do
59
- it "set instance to nil if resource_dir ins't specified" do
60
- @bundler.set_settings({})
61
- @bundler.settings_correct.should be_false
62
- end
63
- it "correctly inits cache dir, and log path with defaults if resource_dir specified" do
64
- res_dir = settings[:resource_dir]
65
- @bundler.set_settings({:resource_dir => res_dir })
66
- @bundler.settings_correct.should be_true
67
- @bundler.settings[:cache_dir].should == 'cache'
68
- @bundler.settings[:log_path].should == File.expand_path('../log/web_resource_bundler.log', res_dir)
69
- end
70
- it "creates log directory if it's unexistent" do
71
- @bundler.set_settings({:resource_dir => @s[:resource_dir]})
72
- log_dir_path = File.expand_path('../log', @s[:resource_dir])
73
- File.exist?(log_dir_path).should be_true
74
- Dir.delete(log_dir_path)
49
+ describe "#set_filters" do
50
+ before(:each) do
51
+ @file_manager = FileManager.new(@s[:resource_dir], @s[:cache_dir])
52
+ @bundler.instance_eval "@filters={}"
53
+ end
54
+ it "inits filters if no filters were initialized before" do
55
+ @bundler.filters.should == {}
56
+ @bundler.send("set_filters", @s, @file_manager)
57
+ @bundler.filters.size.should == 3
58
+ end
59
+ it "sets filters settings if filters already inited" do
60
+ @bundler.send("set_filters", @s, @file_manager)
61
+ @bundler.filters[:base64_filter].settings[:max_image_size].should == @s[:base64_filter][:max_image_size]
62
+ @s[:base64_filter][:max_image_size] = 90
63
+ @bundler.send("set_filters", @s, @file_manager)
64
+ @bundler.filters[:base64_filter].settings[:max_image_size].should == 90
65
+ end
75
66
  end
76
- end
67
+
68
+
69
+ describe "#create_logger" do
70
+
71
+ it "creates log directory if it's unexistent" do
72
+ log_dir_path = File.dirname(@bundler.settings[:log_path])
73
+ FileUtils.rm_rf(log_dir_path)
74
+ @bundler.send("create_logger", @bundler.settings[:log_path])
75
+ File.exist?(log_dir_path).should be_true
76
+ FileUtils.rm_rf(log_dir_path)
77
+ end
78
+
79
+ it "sets log_path in settings if it isn't specified" do
80
+ path = @bundler.settings[:log_path]
81
+ @bundler.send("create_logger", path)
82
+ File.exist?(path).should be_true
83
+ File.delete(path)
84
+ end
77
85
 
78
- describe "#create_logger" do
79
- it "sets log_path in settings if it isn't specified" do
80
- path = File.expand_path('../web_resource_bundler.log', @s[:resource_dir])
81
- @bundler.send("create_logger", path)
82
- File.exist?(path).should be_true
83
- File.delete(path)
84
86
  end
85
- end
86
87
 
87
- describe "#process" do
88
- it "returns the same filenames when bundling or just computing resulted files" do
89
- @bundler.set_settings(settings)
90
- clean_cache_dir
91
- block_text = @sample_block_helper.sample_block
92
- block_data = @bundler.process(block_text)
93
- files1 = BlockData.all_childs(block_data).inject([]) {|files, c| files += c.files.map {|f| f.path} }
94
- block_text = @sample_block_helper.sample_block
95
- block_data = @bundler.process(block_text)
96
- files2 = BlockData.all_childs(block_data).inject([]) {|files, c| files += c.files.map {|f| f.path} }
97
- (files1.flatten - files2.flatten).should be_empty
88
+ describe "#process" do
89
+ it "returns the same filenames when bundling or just computing resulted files" do
90
+ @bundler.set_settings(settings)
91
+ clean_cache_dir
92
+ block_text = @sample_block_helper.sample_block
93
+ block_data = @bundler.process(block_text, 'localhost:3000', 'http')
94
+ files1 = BlockData.all_childs(block_data).inject([]) {|files, c| files += c.files.map {|f| f.path} }
95
+ block_text = @sample_block_helper.sample_block
96
+ block_data = @bundler.process(block_text, 'localhost:3000', 'http')
97
+ files2 = BlockData.all_childs(block_data).inject([]) {|files, c| files += c.files.map {|f| f.path} }
98
+ (files1.flatten - files2.flatten).should be_empty
99
+ end
98
100
  end
99
- end
100
101
 
101
- describe "#bundle_upto_date?" do
102
- it "returns true if block was already bundled and resulted files exist" do
103
- @bundler.set_settings(settings)
104
- clean_cache_dir
105
- block_text = @sample_block_helper.sample_block
106
- block_data = BlockParser.new.parse(block_text.dup)
107
- @bundler.send("bundle_upto_date?", block_data).should == false
108
- @bundler.process(block_text)
109
- @bundler.send("bundle_upto_date?", block_data).should == true
102
+ describe "#bundle_upto_date?" do
103
+ it "returns true if block was already bundled and resulted files exist" do
104
+ @bundler.set_settings(settings)
105
+ clean_cache_dir
106
+ block_text = @sample_block_helper.sample_block
107
+ block_data = BlockParser.new.parse(block_text.dup)
108
+ @bundler.send("bundle_upto_date?", block_data).should == false
109
+ @bundler.process(block_text, 'localhost:3000', 'http')
110
+ @bundler.send("bundle_upto_date?", block_data).should == true
111
+ end
110
112
  end
111
- end
112
113
 
113
114
 
114
- describe "#read_resources!" do
115
- it "populates block_data resource files structure with files content" do
116
- @bundler.set_settings(settings)
117
- block_data = @sample_block_helper.sample_block_data
118
- @bundler.send("read_resources!", block_data)
119
- all_files = block_data.styles + block_data.scripts + block_data.child_blocks[0].styles + block_data.child_blocks[0].scripts
120
- all_files.each do |file|
121
- CssUrlRewriter::rewrite_content_urls!(file.path, File.read(File.join(@s[:resource_dir], file.path))).should == file.content
115
+ describe "#read_resources!" do
116
+ it "populates block_data resource files structure with files content" do
117
+ @bundler.set_settings(settings)
118
+ block_data = @sample_block_helper.sample_block_data
119
+ @bundler.send("read_resources!", block_data)
120
+ all_files = block_data.styles + block_data.scripts + block_data.child_blocks[0].styles + block_data.child_blocks[0].scripts
121
+ all_files.each do |file|
122
+ CssUrlRewriter::rewrite_content_urls!(file.path, File.read(File.join(@s[:resource_dir], file.path))).should == file.content
123
+ end
122
124
  end
123
125
  end
124
- end
125
126
 
127
+ end
126
128
  end
127
129
  end
@@ -5,23 +5,19 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{web_resource_bundler}
8
- s.version = "0.0.14"
8
+ s.version = "0.0.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["gregolsen"]
12
- s.date = %q{2010-12-13}
12
+ s.date = %q{2010-12-18}
13
13
  s.description = %q{this lib could bundle you css/js files in single file, encode images in base64, rewrite images urls to your cdn hosts}
14
14
  s.email = %q{anotheroneman@yahoo.com}
15
- s.extra_rdoc_files = [
16
- "README"
17
- ]
18
15
  s.files = [
19
- ".bundle/config",
20
- ".gitignore",
16
+ ".gitignore",
21
17
  "Gemfile",
22
18
  "Gemfile.lock",
23
- "README",
24
19
  "Rakefile",
20
+ "Readme.md",
25
21
  "VERSION",
26
22
  "lib/web_resource_bundler.rb",
27
23
  "lib/web_resource_bundler/content_management/block_data.rb",
@@ -39,23 +35,25 @@ Gem::Specification.new do |s|
39
35
  "lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb",
40
36
  "lib/web_resource_bundler/filters/image_encode_filter/image_data.rb",
41
37
  "lib/web_resource_bundler/rails_app_helpers.rb",
38
+ "lib/web_resource_bundler/settings_manager.rb",
42
39
  "lib/web_resource_bundler/web_resource_bundler_init.rb",
43
- "spec/public/foo.css",
44
- "spec/public/images/good.jpg",
45
- "spec/public/images/logo.jpg",
46
- "spec/public/images/sdfo.jpg",
47
- "spec/public/images/too_big_image.jpg",
48
- "spec/public/marketing.js",
49
- "spec/public/salog20.js",
50
- "spec/public/sample.css",
51
- "spec/public/seal.js",
52
- "spec/public/set_cookies.js",
53
- "spec/public/styles/boo.css",
54
- "spec/public/styles/for_import.css",
55
- "spec/public/temp.css",
56
- "spec/public/test.css",
57
40
  "spec/sample_block_helper.rb",
58
41
  "spec/spec_helper.rb",
42
+ "spec/test_data/config/web_resource_bundler.yml",
43
+ "spec/test_data/public/foo.css",
44
+ "spec/test_data/public/images/good.jpg",
45
+ "spec/test_data/public/images/logo.jpg",
46
+ "spec/test_data/public/images/sdfo.jpg",
47
+ "spec/test_data/public/images/too_big_image.jpg",
48
+ "spec/test_data/public/marketing.js",
49
+ "spec/test_data/public/salog20.js",
50
+ "spec/test_data/public/sample.css",
51
+ "spec/test_data/public/seal.js",
52
+ "spec/test_data/public/set_cookies.js",
53
+ "spec/test_data/public/styles/boo.css",
54
+ "spec/test_data/public/styles/for_import.css",
55
+ "spec/test_data/public/temp.css",
56
+ "spec/test_data/public/test.css",
59
57
  "spec/web_resource_bundler/content_management/block_data_spec.rb",
60
58
  "spec/web_resource_bundler/content_management/block_parser_spec.rb",
61
59
  "spec/web_resource_bundler/content_management/css_url_rewriter_spec.rb",
@@ -67,10 +65,11 @@ Gem::Specification.new do |s|
67
65
  "spec/web_resource_bundler/filters/image_encode_filter/css_generator_spec.rb",
68
66
  "spec/web_resource_bundler/filters/image_encode_filter/filter_spec.rb",
69
67
  "spec/web_resource_bundler/filters/image_encode_filter/image_data_spec.rb",
68
+ "spec/web_resource_bundler/settings_manager_spec.rb",
70
69
  "spec/web_resource_bundler/web_resource_bundler_spec.rb",
71
70
  "web_resource_bundler.gemspec"
72
71
  ]
73
- s.homepage = %q{http://github.com/gregolsen/web-bundler}
72
+ s.homepage = %q{https://github.com/railsware/web-bundler}
74
73
  s.rdoc_options = ["--charset=UTF-8"]
75
74
  s.require_paths = ["lib"]
76
75
  s.rubygems_version = %q{1.3.7}
@@ -84,6 +83,7 @@ Gem::Specification.new do |s|
84
83
  "spec/web_resource_bundler/filters/bundle_filter/resource_packager_spec.rb",
85
84
  "spec/web_resource_bundler/web_resource_bundler_spec.rb",
86
85
  "spec/web_resource_bundler/file_manager_spec.rb",
86
+ "spec/web_resource_bundler/settings_manager_spec.rb",
87
87
  "spec/web_resource_bundler/content_management/css_url_rewriter_spec.rb",
88
88
  "spec/web_resource_bundler/content_management/block_data_spec.rb",
89
89
  "spec/web_resource_bundler/content_management/resource_file_spec.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 14
9
- version: 0.0.14
8
+ - 15
9
+ version: 0.0.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - gregolsen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-13 00:00:00 +02:00
17
+ date: 2010-12-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -38,15 +38,14 @@ executables: []
38
38
 
39
39
  extensions: []
40
40
 
41
- extra_rdoc_files:
42
- - README
41
+ extra_rdoc_files: []
42
+
43
43
  files:
44
- - .bundle/config
45
44
  - .gitignore
46
45
  - Gemfile
47
46
  - Gemfile.lock
48
- - README
49
47
  - Rakefile
48
+ - Readme.md
50
49
  - VERSION
51
50
  - lib/web_resource_bundler.rb
52
51
  - lib/web_resource_bundler/content_management/block_data.rb
@@ -64,23 +63,25 @@ files:
64
63
  - lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb
65
64
  - lib/web_resource_bundler/filters/image_encode_filter/image_data.rb
66
65
  - lib/web_resource_bundler/rails_app_helpers.rb
66
+ - lib/web_resource_bundler/settings_manager.rb
67
67
  - lib/web_resource_bundler/web_resource_bundler_init.rb
68
- - spec/public/foo.css
69
- - spec/public/images/good.jpg
70
- - spec/public/images/logo.jpg
71
- - spec/public/images/sdfo.jpg
72
- - spec/public/images/too_big_image.jpg
73
- - spec/public/marketing.js
74
- - spec/public/salog20.js
75
- - spec/public/sample.css
76
- - spec/public/seal.js
77
- - spec/public/set_cookies.js
78
- - spec/public/styles/boo.css
79
- - spec/public/styles/for_import.css
80
- - spec/public/temp.css
81
- - spec/public/test.css
82
68
  - spec/sample_block_helper.rb
83
69
  - spec/spec_helper.rb
70
+ - spec/test_data/config/web_resource_bundler.yml
71
+ - spec/test_data/public/foo.css
72
+ - spec/test_data/public/images/good.jpg
73
+ - spec/test_data/public/images/logo.jpg
74
+ - spec/test_data/public/images/sdfo.jpg
75
+ - spec/test_data/public/images/too_big_image.jpg
76
+ - spec/test_data/public/marketing.js
77
+ - spec/test_data/public/salog20.js
78
+ - spec/test_data/public/sample.css
79
+ - spec/test_data/public/seal.js
80
+ - spec/test_data/public/set_cookies.js
81
+ - spec/test_data/public/styles/boo.css
82
+ - spec/test_data/public/styles/for_import.css
83
+ - spec/test_data/public/temp.css
84
+ - spec/test_data/public/test.css
84
85
  - spec/web_resource_bundler/content_management/block_data_spec.rb
85
86
  - spec/web_resource_bundler/content_management/block_parser_spec.rb
86
87
  - spec/web_resource_bundler/content_management/css_url_rewriter_spec.rb
@@ -92,10 +93,11 @@ files:
92
93
  - spec/web_resource_bundler/filters/image_encode_filter/css_generator_spec.rb
93
94
  - spec/web_resource_bundler/filters/image_encode_filter/filter_spec.rb
94
95
  - spec/web_resource_bundler/filters/image_encode_filter/image_data_spec.rb
96
+ - spec/web_resource_bundler/settings_manager_spec.rb
95
97
  - spec/web_resource_bundler/web_resource_bundler_spec.rb
96
98
  - web_resource_bundler.gemspec
97
99
  has_rdoc: true
98
- homepage: http://github.com/gregolsen/web-bundler
100
+ homepage: https://github.com/railsware/web-bundler
99
101
  licenses: []
100
102
 
101
103
  post_install_message:
@@ -135,6 +137,7 @@ test_files:
135
137
  - spec/web_resource_bundler/filters/bundle_filter/resource_packager_spec.rb
136
138
  - spec/web_resource_bundler/web_resource_bundler_spec.rb
137
139
  - spec/web_resource_bundler/file_manager_spec.rb
140
+ - spec/web_resource_bundler/settings_manager_spec.rb
138
141
  - spec/web_resource_bundler/content_management/css_url_rewriter_spec.rb
139
142
  - spec/web_resource_bundler/content_management/block_data_spec.rb
140
143
  - spec/web_resource_bundler/content_management/resource_file_spec.rb
data/.bundle/config DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
data/README DELETED
@@ -1,143 +0,0 @@
1
- =================== WebResourceBundler gem README ============================
2
-
3
- Content:
4
- 1. Purpose
5
- 2. Functional description
6
- 3. Installation
7
- 4. Usage
8
- 5. Recommendations
9
-
10
- =================== 1. Purpose ===============================================
11
-
12
- The main purpose of WebResourceBundler gem is to minimize request & response
13
- round-trips count. This could be done by bundling particular resource (css or js) in
14
- one file. Encoding images in base64 and putting then in css directly.
15
-
16
- =================== 2. Functional description ================================
17
-
18
- WebResourceBundler parse your head html block, finding all css and js resource
19
- files.
20
- It can bundle resource of particular type in one single file. Base64 filter
21
- encodes images in base64 putting them in css directly. Separate files for IE
22
- and other browsers created. Conditional comments (like <!--[if IE 6]>) also
23
- supported. You can use external image hosts to server images in css:
24
- cdn filter can rewrite image urls for you. Resulted filename is a md5(filenames.sort)
25
-
26
- =================== 3. Installation ==========================================
27
-
28
- gem install web_resource_bundler
29
-
30
- It's pretty easy, yeah?
31
-
32
- =================== 4. Usage =================================================
33
- Firstly you should create your settings file in config dir.
34
- You can set separate settings for each environment
35
-
36
- -------------- config/web_resource_bundler.yml --------------
37
- development:
38
- :base64_filter:
39
- :use: true
40
- :max_image_size: 23
41
- :protocol: http
42
- :domain: localhost:3000
43
- :bundle_filter:
44
- :use: true
45
- :cdn_filter:
46
- :use: true
47
- :http_hosts: ['http://localhost:3000']
48
- :https_hosts: ['https://localhost:3000']
49
- ------------------------------------------------------------
50
-
51
- Then you should create initializer file in
52
- /path/to/your/rails_app/config/initializers/ directory
53
- Let's say it will be web_resource_bundler_init.rb
54
- Then you should put content like this in it.
55
-
56
- ------------- config/initializers/web_resource_bundler_init.rb ---------------
57
- require 'web_resource_bundler'
58
- require 'yaml'
59
- root_dir = Rails.root #or RAILS_ROOT if you are using older rails version than 3
60
- environment = Rails.env #or RAILS_ENV in case rails <= 2.3
61
- settings = { }
62
- settings_file_path = File.join(root_dir, 'config', 'web_resource_bundler.yml')
63
- if File.exist?(settings_file_path)
64
- settings_file = File.open(settings_file_path)
65
- all_settings = YAML::load(settings_file)
66
- if all_settings[environment]
67
- settings = all_settings[environment]
68
- settings[:resource_dir] = File.join(root_dir, 'public')
69
- end
70
- end
71
-
72
- WebResourceBundler::Bundler.instance.set_settings(settings)
73
- ActionView::Base.send(:include, WebResourceBundler::RailsAppHelpers)
74
- ------------------------------------------------------------------------------
75
-
76
- Now in your view files you can call web_resource_bundler_process helper like this:
77
-
78
- <head>
79
- <% web_resource_bundler_process do %>
80
- <%= stylesheet_link_tag :scaffold %>
81
- <%= javascript_include_tag :defaults %>
82
- <link type="text/css" rel="stylesheet" href="/stylesheets/somestyle.css"/>
83
- <%=yield :head %>
84
- <!--[if lte IE 7]>
85
- <link type="text/css" rel="stylesheet" href="/stylesheets/ie7fix.css"/>
86
- <link type="text/css" rel="stylesheet" href="/stylesheets/pngfix.css"/>
87
- <![endif]-->
88
-
89
- <% end %>
90
- </head>
91
- Notice:
92
-
93
- For Rails < 3
94
- you should use <% web_resource_bundler_process do %>
95
-
96
- And For Rails >= 3
97
- use <%= web_resource_bundler_process do %>
98
-
99
-
100
- And as result you'll have
101
-
102
- <link href="/cache/base64_style_d880a502addaa493b889c0970616430b.css?1290594873" media="screen" rel="stylesheet" type="text/css" />
103
- <script src="/cache/script_275d311037da40e9c9b8c919a8c08b55.js?1290594873" type="text/javascript"></script>
104
-
105
- <!--[if lte IE 7]>
106
- <link href="/cache/base64_ie_style_d880a502addaa493b889c0970616430b.css?1290594873" media="screen" rel="stylesheet" type="text/css" />
107
- <![endif]-->
108
-
109
- <!--[if lte IE 7]>
110
- <link type="text/css" rel="stylesheet" href="/cache/base64_style_ad801w02addaa493b889c0970616430b.css?1290594873"/>
111
- <![endif]-->
112
-
113
- !!!
114
- Don't forget to clean your cache directory after deploy to clean old bundles
115
-
116
-
117
- To disable bundling and see raw results add no_bundler param
118
- mysite.com/?no_bundler=1
119
- ================= 5. Recommendations ===================================
120
-
121
- 1. Be mindful while organazing and linking your resource files
122
- WebResourceBundler combines all resource file in one. This resulted file could be huge.
123
- a. Don't link all resources in layouts!
124
- Be sure to link resources (css\js) only for pages that using them, in other case your users will be forced
125
- to download huge css\js files with unused content.
126
- b. One css for one page.
127
- Try to slice you css files - separate file for each particular page.
128
- c. Separate bundle block for crucial resources
129
- To make crucial resources (basic styles\scripts for user can see basic page layout ASAP) load first - just bundle them in separate web_resource_bundler_process block and put this block at the top of your head block.
130
-
131
- 2. Don't set max_image_size to big values.
132
- The main reason of using Base64 filter is to avoid unnecessary server requests and minimize load time,
133
- but when encoded image is very big, traffic overhead time (encoded image base64 code is bigger for apprx. 30% than source image size) could be bigger than request time. In this case your site could be even slower than without a WebResourceBundler.
134
- Recommended max_image_size value is 1..20kbytes
135
-
136
- 3. Be careful with third party scripts.
137
- Some third party javascript libs can load another script file on the fly, relative path for this file computed
138
- on the client side. But your scripts are bundled and their relative path changed (cache folder), that's why such script
139
- won't be able to compute loaded file path correctly. You should avoid bundling such tricky javascripts.
140
-
141
- 4. Unexistent resources handling
142
- a. Be sure to link in html only existent resource files, otherwise bundler won't work.
143
- b. If you have unexistent images in css, bundler will work but you've got info messages in log.