htmlcompressor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ 0.0.3 - 18/05/2012
2
+ Added customizable options to rack middlewar
3
+ 0.0.2
4
+ First realase
data/README.md CHANGED
@@ -46,10 +46,10 @@ The compressor ships with some default option that may be overwritten passing th
46
46
  Using rack middleware is as easy as:
47
47
 
48
48
  ```ruby
49
- config.middleware.use HtmlCompressor::Rack
49
+ config.middleware.use HtmlCompressor::Rack, options
50
50
  ```
51
51
 
52
- It is not yet possible to override default options when using the rack middleware.
52
+ The options has his optional and can be used to overwrite default options
53
53
 
54
54
  Rails 2.3 users may need to add
55
55
  ```ruby
@@ -772,8 +772,6 @@ module HtmlCompressor
772
772
  html
773
773
  end
774
774
 
775
- private
776
-
777
775
  def message_format(message, *params)
778
776
  message.gsub(/\{(\d+),number,#\}/) do
779
777
  params[$1.to_i]
@@ -2,52 +2,56 @@ module HtmlCompressor
2
2
 
3
3
  class Rack
4
4
 
5
- def initialize app
6
- @app = app
7
-
8
- @compressor = HtmlCompressor::Compressor.new(
9
- :enabled => true,
10
- :remove_multi_spaces => true,
11
- :remove_comments => true,
12
- :remove_intertag_spaces => true,
13
- :remove_quotes => true,
14
- :compress_css => false,
15
- :compress_javascript => false,
16
- :simple_doctype => false,
17
- :remove_script_attributes => true,
18
- :remove_style_attributes => true,
19
- :remove_link_attributes => true,
20
- :remove_form_attributes => false,
21
- :remove_input_attributes => true,
22
- :remove_javascript_protocol => true,
23
- :remove_http_protocol => true,
24
- :remove_https_protocol => false,
25
- :preserve_line_breaks => false,
26
- :simple_boolean_attributes => true
27
- )
28
-
29
- end
30
-
31
- def call env
32
- status, headers, body = @app.call(env)
33
-
34
- if headers.key? 'Content-Type' and headers['Content-Type'] =~ /html/
35
- content = ''
36
-
37
- body.each do |part|
38
- content << part
39
- end
5
+ DEFAULT_OPTIONS = {
6
+ :enabled => true,
7
+ :remove_multi_spaces => true,
8
+ :remove_comments => true,
9
+ :remove_intertag_spaces => true,
10
+ :remove_quotes => true,
11
+ :compress_css => false,
12
+ :compress_javascript => false,
13
+ :simple_doctype => false,
14
+ :remove_script_attributes => true,
15
+ :remove_style_attributes => true,
16
+ :remove_link_attributes => true,
17
+ :remove_form_attributes => false,
18
+ :remove_input_attributes => true,
19
+ :remove_javascript_protocol => true,
20
+ :remove_http_protocol => true,
21
+ :remove_https_protocol => false,
22
+ :preserve_line_breaks => false,
23
+ :simple_boolean_attributes => true
24
+ }
25
+
26
+ def initialize app, options = {}
27
+ @app = app
28
+
29
+ options = DEFAULT_OPTIONS.merge(options)
30
+
31
+ @compressor = HtmlCompressor::Compressor.new(options)
32
+
33
+ end
34
+
35
+ def call env
36
+ status, headers, body = @app.call(env)
37
+
38
+ if headers.key? 'Content-Type' and headers['Content-Type'] =~ /html/
39
+ content = ''
40
+
41
+ body.each do |part|
42
+ content << part
43
+ end
40
44
 
41
- content = @compressor.compress(content)
42
- headers['Content-Length'] = content.length.to_s if headers['Content-Length']
45
+ content = @compressor.compress(content)
46
+ headers['Content-Length'] = content.length.to_s if headers['Content-Length']
43
47
 
44
- [status, headers, [content]]
45
- else
46
- [status, headers, body]
47
- end
48
- ensure
49
- body.close if body.respond_to?(:close)
48
+ [status, headers, [content]]
49
+ else
50
+ [status, headers, body]
50
51
  end
52
+ ensure
53
+ body.close if body.respond_to?(:close)
54
+ end
51
55
 
52
56
  end
53
57
 
@@ -1,3 +1,3 @@
1
1
  module HtmlCompressor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmlcompressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2012-05-11 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yui-compressor
16
- requirement: &2161817380 !ruby/object:Gem::Requirement
16
+ requirement: &2152417880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2161817380
24
+ version_requirements: *2152417880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: closure-compiler
27
- requirement: &2161816880 !ruby/object:Gem::Requirement
27
+ requirement: &2152433740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.1.5
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2161816880
35
+ version_requirements: *2152433740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2161832860 !ruby/object:Gem::Requirement
38
+ requirement: &2152433360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2161832860
46
+ version_requirements: *2152433360
47
47
  description: Put your html on a diet
48
48
  email:
49
49
  - chiodi84@gmail.com
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - .gitignore
55
+ - CHANGELOG
55
56
  - Gemfile
56
57
  - LICENSE
57
58
  - README.md
@@ -194,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
195
  version: '0'
195
196
  segments:
196
197
  - 0
197
- hash: -2490724316612321871
198
+ hash: -1615621865656681193
198
199
  required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  none: false
200
201
  requirements:
@@ -203,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  version: '0'
204
205
  segments:
205
206
  - 0
206
- hash: -2490724316612321871
207
+ hash: -1615621865656681193
207
208
  requirements: []
208
209
  rubyforge_project:
209
210
  rubygems_version: 1.8.15