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 +4 -0
- data/README.md +2 -2
- data/lib/htmlcompressor/compressor.rb +0 -2
- data/lib/htmlcompressor/rack.rb +47 -43
- data/lib/htmlcompressor/version.rb +1 -1
- metadata +11 -10
data/CHANGELOG
ADDED
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
|
-
|
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
|
data/lib/htmlcompressor/rack.rb
CHANGED
@@ -2,52 +2,56 @@ module HtmlCompressor
|
|
2
2
|
|
3
3
|
class Rack
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
45
|
+
content = @compressor.compress(content)
|
46
|
+
headers['Content-Length'] = content.length.to_s if headers['Content-Length']
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
|
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.
|
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-
|
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: &
|
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: *
|
24
|
+
version_requirements: *2152417880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: closure-compiler
|
27
|
-
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: *
|
35
|
+
version_requirements: *2152433740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
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: *
|
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: -
|
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: -
|
207
|
+
hash: -1615621865656681193
|
207
208
|
requirements: []
|
208
209
|
rubyforge_project:
|
209
210
|
rubygems_version: 1.8.15
|