html5small 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/VERSION +1 -1
- data/fixtures/lists.html.min +1 -1
- data/fixtures/whitespace-complex.html.min +1 -1
- data/fixtures/whitespace-p.html +1 -0
- data/fixtures/whitespace-p.html.min +1 -1
- data/html5small.gemspec +4 -4
- data/lib/html5small/minifier.rb +17 -6
- data/lib/html5small.rb +1 -1
- metadata +5 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGY2YjdiMTIzYjBjY2ExZmIwNzQxYjc5MDFkNTE2ZjU5MmNhOTk0MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTdjN2NmMTY2NWNjNTVjYmRiMTFiMDgyYTI3M2UxZTdhZTg3YTQxZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODVlYTI4NjhkNDc1OTcyM2UxYzlmN2YwZGY4YzQ1OTRmMjU4NGJhZjlhOWEw
|
10
|
+
YWM1MzhmMDVkYWM4MWYyMDg3NmVmN2M1YWI1ZmJhMWZmMTFmZTdkZDE2ZDM2
|
11
|
+
MWM0YmUwOTJjMDExN2Y1MDllOTE0ZTVmYWFlMjUwYWQ4NmEzNTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmI5YWMxZWM2NTk0ZTk2ZWY4ODI1Njg2NzQwMTMxZjFjYzkyM2JhYTY5ZDZl
|
14
|
+
ZGJkM2E3NDhjMmMwN2YzYjE1Y2Y3Y2QyZjZjZGUxZmY1MTAxMjJmMWQ4ZGUy
|
15
|
+
MjcwNDIzYzc1ZmYzNWYyZGEzNzgzMTQ4MGJlNGRkNjFlM2UzNzA=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/fixtures/lists.html.min
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><meta charset=utf-8><title>Untitled</title><body><ul><li><i>one</i><li><i>two</i></ul>
|
1
|
+
<!doctype html><meta charset=utf-8><title>Untitled</title><body><ul><li><i>one</i><li><i> two </i></ul>
|
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><meta charset=utf-8><title>Untitled</title><section><p>A <code>b</code> <i>c</i> d <dfn>e <code>f</code>
|
1
|
+
<!doctype html><meta charset=utf-8><title>Untitled</title><section><p>A <code>b</code> <i>c</i> d <dfn>e <code> f </code> . </dfn></section>
|
data/fixtures/whitespace-p.html
CHANGED
@@ -1 +1 @@
|
|
1
|
-
<!doctype html><meta charset=utf-8><title>Untitled</title><body><p>This is a<code>string</code>.
|
1
|
+
<!doctype html><meta charset=utf-8><title>Untitled</title><body><p>This is a<code>string </code>. Here is a space<span> </span>.
|
data/html5small.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "html5small"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Run Paint Run Run", "Ruben Verborgh"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-08-14"
|
13
13
|
s.description = "Minifier for HTML5 documents"
|
14
14
|
s.email = "ruben.verborgh@gmail.com"
|
15
15
|
s.executables = ["html5small", "html5small"]
|
@@ -77,11 +77,11 @@ Gem::Specification.new do |s|
|
|
77
77
|
]
|
78
78
|
s.homepage = "http://github.com/RubenVerborgh/HTML5small"
|
79
79
|
s.require_paths = ["lib"]
|
80
|
-
s.rubygems_version = "
|
80
|
+
s.rubygems_version = "2.0.6"
|
81
81
|
s.summary = "HTML5small"
|
82
82
|
|
83
83
|
if s.respond_to? :specification_version then
|
84
|
-
s.specification_version =
|
84
|
+
s.specification_version = 4
|
85
85
|
|
86
86
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
87
87
|
s.add_runtime_dependency(%q<htmlentities>, [">= 4.1.0"])
|
data/lib/html5small/minifier.rb
CHANGED
@@ -16,11 +16,17 @@ module HTML5small
|
|
16
16
|
strong style sub sup svg table textarea time ul var video wbr
|
17
17
|
}.map(&:to_sym)
|
18
18
|
|
19
|
+
# BLock-level elements
|
20
|
+
BLOCK_ELEMENTS = %w{address article aside audio blockquote canvas dd div dl fieldset
|
21
|
+
figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr
|
22
|
+
li noscript ol output p pre section table thead tfoot tr ul video
|
23
|
+
}.map(&:to_sym)
|
24
|
+
|
19
25
|
attr_accessor :buf, :text_node, :entities
|
20
26
|
|
21
27
|
def initialize
|
22
28
|
@buf, @text_node = '', ''
|
23
|
-
@stack = []
|
29
|
+
@stack = [], @prev_tag
|
24
30
|
@entities = HTMLEntities.new :expanded
|
25
31
|
end
|
26
32
|
|
@@ -33,14 +39,17 @@ module HTML5small
|
|
33
39
|
name = normalise_name name
|
34
40
|
dump_text_node
|
35
41
|
@stack.push name
|
42
|
+
@prev_tag = name
|
43
|
+
buf.rstrip! if is_block_element?(name) and not in_pre_element?
|
36
44
|
buf << "<#{name}" + format_attributes(attrs, name) + ">"
|
37
45
|
end
|
38
46
|
|
39
47
|
def end_element name
|
40
48
|
name = normalise_name name
|
41
49
|
dump_text_node
|
42
|
-
buf.rstrip!
|
50
|
+
buf.rstrip! if is_block_element?(name) and not in_pre_element?
|
43
51
|
@stack.pop
|
52
|
+
@prev_tag = name
|
44
53
|
buf << "</#{name}>"
|
45
54
|
end
|
46
55
|
|
@@ -104,10 +113,8 @@ module HTML5small
|
|
104
113
|
return text if in_pre_element?
|
105
114
|
# Treat all whitespace as spaces
|
106
115
|
text.gsub!(/[\n\t]/, ' ')
|
107
|
-
#
|
108
|
-
|
109
|
-
text.lstrip!
|
110
|
-
end
|
116
|
+
# Strip leading whitespace at the beginning of block elements
|
117
|
+
text.lstrip! if @prev_tag == @stack.last and is_block_element?(@prev_tag)
|
111
118
|
# Normalize spaces
|
112
119
|
text.squeeze(' ')
|
113
120
|
end
|
@@ -124,6 +131,10 @@ module HTML5small
|
|
124
131
|
@stack.include? :script
|
125
132
|
end
|
126
133
|
|
134
|
+
def is_block_element? name
|
135
|
+
BLOCK_ELEMENTS.include? name
|
136
|
+
end
|
137
|
+
|
127
138
|
def dump_text_node
|
128
139
|
buf << format_text_node
|
129
140
|
text_node.clear
|
data/lib/html5small.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html5small
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Run Paint Run Run
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: htmlentities
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ! '>='
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ! '>='
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,7 +28,6 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: nokogiri
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
32
|
- - ! '>='
|
37
33
|
- !ruby/object:Gem::Version
|
@@ -39,7 +35,6 @@ dependencies:
|
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
39
|
- - ! '>='
|
45
40
|
- !ruby/object:Gem::Version
|
@@ -47,7 +42,6 @@ dependencies:
|
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rspec
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
46
|
- - ! '>='
|
53
47
|
- !ruby/object:Gem::Version
|
@@ -55,7 +49,6 @@ dependencies:
|
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
53
|
- - ! '>='
|
61
54
|
- !ruby/object:Gem::Version
|
@@ -63,7 +56,6 @@ dependencies:
|
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: yard
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
60
|
- - ! '>='
|
69
61
|
- !ruby/object:Gem::Version
|
@@ -71,7 +63,6 @@ dependencies:
|
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
67
|
- - ! '>='
|
77
68
|
- !ruby/object:Gem::Version
|
@@ -143,26 +134,25 @@ files:
|
|
143
134
|
- spec/spec_helper.rb
|
144
135
|
homepage: http://github.com/RubenVerborgh/HTML5small
|
145
136
|
licenses: []
|
137
|
+
metadata: {}
|
146
138
|
post_install_message:
|
147
139
|
rdoc_options: []
|
148
140
|
require_paths:
|
149
141
|
- lib
|
150
142
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
143
|
requirements:
|
153
144
|
- - ! '>='
|
154
145
|
- !ruby/object:Gem::Version
|
155
146
|
version: '0'
|
156
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
-
none: false
|
158
148
|
requirements:
|
159
149
|
- - ! '>='
|
160
150
|
- !ruby/object:Gem::Version
|
161
151
|
version: '0'
|
162
152
|
requirements: []
|
163
153
|
rubyforge_project:
|
164
|
-
rubygems_version:
|
154
|
+
rubygems_version: 2.0.6
|
165
155
|
signing_key:
|
166
|
-
specification_version:
|
156
|
+
specification_version: 4
|
167
157
|
summary: HTML5small
|
168
158
|
test_files: []
|