h5-min 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/h5-min.rb +38 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/h5-min.rb
CHANGED
@@ -17,6 +17,31 @@ module HTML5
|
|
17
17
|
strong style sub sup svg table textarea time ul var video wbr
|
18
18
|
}.map(&:to_sym)
|
19
19
|
|
20
|
+
BOOL_ATTR = {
|
21
|
+
_: [:itemscope, :hidden],
|
22
|
+
audio: [:loop, :autoplay, :controls],
|
23
|
+
button: [:formnovalidate, :disabled, :autofocus],
|
24
|
+
command: [:disabled, :checked],
|
25
|
+
details: [:open],
|
26
|
+
fieldset: [:disabled],
|
27
|
+
form: [:novalidate],
|
28
|
+
iframe: [:seamless],
|
29
|
+
img: [:ismap],
|
30
|
+
input: [:autocomplete, :autofocus, :defaultchecked,
|
31
|
+
:checked, :disabled, :formnovalidate, :indeterminate,
|
32
|
+
:multiple, :readonly, :required],
|
33
|
+
keygen: [:disabled, :autofocus],
|
34
|
+
optgroup: [:disabled],
|
35
|
+
option: [:disabled, :defaultselected, :selected],
|
36
|
+
ol: [:reversed],
|
37
|
+
select: [:autofocus, :disabled, :multiple],
|
38
|
+
script: [:async, :defer],
|
39
|
+
style: [:scoped],
|
40
|
+
textarea: [:autofocus, :disabled, :readonly, :required],
|
41
|
+
time: [:pubdate],
|
42
|
+
video: [:loop, :autoplay, :controls],
|
43
|
+
}
|
44
|
+
|
20
45
|
@minifier ||= Class.new(Nokogiri::XML::SAX::Document) do
|
21
46
|
|
22
47
|
attr_accessor :buf, :text_node, :entities
|
@@ -36,7 +61,7 @@ module HTML5
|
|
36
61
|
name = normalise_name name
|
37
62
|
dump_text_node
|
38
63
|
@stack.push name
|
39
|
-
buf << "<#{name}" + format_attributes(attrs) + ">"
|
64
|
+
buf << "<#{name}" + format_attributes(attrs, name) + ">"
|
40
65
|
end
|
41
66
|
|
42
67
|
def end_element name
|
@@ -72,14 +97,18 @@ module HTML5
|
|
72
97
|
name.downcase.to_sym
|
73
98
|
end
|
74
99
|
|
75
|
-
def format_attributes attrs
|
100
|
+
def format_attributes attrs, element
|
76
101
|
return '' if attrs.empty?
|
77
102
|
Hash[*attrs].map do |name, value|
|
78
103
|
[normalise_name(name), format_attribute_value(value)]
|
79
104
|
end.sort_by do |name, value|
|
80
105
|
name
|
81
106
|
end.map do |name, value|
|
82
|
-
|
107
|
+
if boolean_attribute?(element, name)
|
108
|
+
name.to_s
|
109
|
+
else
|
110
|
+
"#{name}=#{value}"
|
111
|
+
end
|
83
112
|
end.join(' ').insert(0, ' ')
|
84
113
|
end
|
85
114
|
|
@@ -91,6 +120,12 @@ module HTML5
|
|
91
120
|
value =~ /[[:space:]"'><=`]/ or value.empty?
|
92
121
|
end
|
93
122
|
|
123
|
+
def boolean_attribute? element, attribute
|
124
|
+
e, a = [element, attribute].map(&:to_sym)
|
125
|
+
BOOL_ATTR[:_].include?(a) or
|
126
|
+
(BOOL_ATTR.key?(e) and BOOL_ATTR[e].include?(a))
|
127
|
+
end
|
128
|
+
|
94
129
|
def format_entities html, except={}
|
95
130
|
html = entities.encode(entities.decode(html), :basic)
|
96
131
|
except.each{|name, replace| html.gsub!(/&#{name};/, replace)}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Run Paint Run Run
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|