hatemile 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +46 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE +202 -0
  5. data/Rakefile +64 -0
  6. data/hatemile.gemspec +37 -0
  7. data/lib/hatemile/accessible_association.rb +62 -0
  8. data/lib/hatemile/accessible_css.rb +43 -0
  9. data/lib/hatemile/accessible_display.rb +178 -0
  10. data/lib/hatemile/accessible_event.rb +95 -0
  11. data/lib/hatemile/accessible_form.rb +101 -0
  12. data/lib/hatemile/accessible_navigation.rb +82 -0
  13. data/lib/hatemile/helper.rb +58 -0
  14. data/lib/hatemile/implementation/accessible_association_implementation.rb +346 -0
  15. data/lib/hatemile/implementation/accessible_css_implementation.rb +772 -0
  16. data/lib/hatemile/implementation/accessible_display_implementation.rb +1362 -0
  17. data/lib/hatemile/implementation/accessible_event_implementation.rb +278 -0
  18. data/lib/hatemile/implementation/accessible_form_implementation.rb +386 -0
  19. data/lib/hatemile/implementation/accessible_navigation_implementation.rb +561 -0
  20. data/lib/hatemile/util/common_functions.rb +106 -0
  21. data/lib/hatemile/util/configure.rb +92 -0
  22. data/lib/hatemile/util/css/rcp/rcp_declaration.rb +77 -0
  23. data/lib/hatemile/util/css/rcp/rcp_parser.rb +115 -0
  24. data/lib/hatemile/util/css/rcp/rcp_rule.rb +86 -0
  25. data/lib/hatemile/util/css/style_sheet_declaration.rb +59 -0
  26. data/lib/hatemile/util/css/style_sheet_parser.rb +43 -0
  27. data/lib/hatemile/util/css/style_sheet_rule.rb +73 -0
  28. data/lib/hatemile/util/html/html_dom_element.rb +234 -0
  29. data/lib/hatemile/util/html/html_dom_node.rb +131 -0
  30. data/lib/hatemile/util/html/html_dom_parser.rb +150 -0
  31. data/lib/hatemile/util/html/html_dom_text_node.rb +43 -0
  32. data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_element.rb +302 -0
  33. data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_node.rb +112 -0
  34. data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_parser.rb +208 -0
  35. data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_text_node.rb +83 -0
  36. data/lib/hatemile/util/id_generator.rb +53 -0
  37. data/lib/js/common.js +98 -0
  38. data/lib/js/eventlistener.js +36 -0
  39. data/lib/js/include.js +292 -0
  40. data/lib/js/scriptlist_validation_fields.js +13 -0
  41. data/lib/js/validation.js +205 -0
  42. data/lib/locale/en-US.yml +388 -0
  43. data/lib/locale/pt-BR.yml +389 -0
  44. data/lib/skippers.xml +6 -0
  45. data/lib/symbols.xml +40 -0
  46. data/test/locale/en-US.yml +5 -0
  47. data/test/locale/pt-BR.yml +4 -0
  48. data/test/test_accessible_association_implementation.rb +258 -0
  49. data/test/test_accessible_css_implementation.rb +518 -0
  50. data/test/test_accessible_display_implementation.rb +873 -0
  51. data/test/test_accessible_form_implementation.rb +283 -0
  52. data/test/test_accessible_navigation_implementation.rb +228 -0
  53. data/test/test_common_functions.rb +128 -0
  54. data/test/test_configure.rb +73 -0
  55. data/test/test_nokogiri_html_dom_element.rb +586 -0
  56. data/test/test_nokogiri_html_dom_parser.rb +363 -0
  57. data/test/test_nokogiri_html_dom_text_node.rb +225 -0
  58. data/test/test_rcp_declaration.rb +103 -0
  59. data/test/test_rcp_parser.rb +86 -0
  60. data/test/test_rcp_rule.rb +89 -0
  61. metadata +199 -0
@@ -0,0 +1,150 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ ##
14
+ # The Hatemile module contains the interfaces with the acessibility solutions.
15
+ module Hatemile
16
+ ##
17
+ # The Hatemile::Util module contains the utilities of library.
18
+ module Util
19
+ ##
20
+ # The Hatemile::Util::Html module contains the interfaces of HTML handles.
21
+ module Html
22
+ ##
23
+ # The HTMLDOMParser interface contains the methods for access a native
24
+ # parser.
25
+ #
26
+ # @abstract
27
+ class HTMLDOMParser
28
+ private_class_method :new
29
+
30
+ ##
31
+ # Find all elements in the parser by selector.
32
+ #
33
+ # @abstract
34
+ # @param selector [String, Hatemile::Util::Html::HTMLDOMElement] The
35
+ # selector.
36
+ # @return [Hatemile::Util::Html::HTMLDOMParser] The parser with the
37
+ # elements found.
38
+ def find(selector)
39
+ # Interface method
40
+ end
41
+
42
+ ##
43
+ # Find all elements in the parser by selector, children of found
44
+ # elements.
45
+ #
46
+ # @abstract
47
+ # @param selector [String, Hatemile::Util::Html::HTMLDOMElement] The
48
+ # selector.
49
+ # @return [Hatemile::Util::Html::HTMLDOMParser] The parser with the
50
+ # elements found.
51
+ def find_children(selector)
52
+ # Interface method
53
+ end
54
+
55
+ ##
56
+ # Find all elements in the parser by selector, descendants of found
57
+ # elements.
58
+ #
59
+ # @abstract
60
+ # @param selector [String, Hatemile::Util::Html::HTMLDOMElement] The
61
+ # selector.
62
+ # @return [Hatemile::Util::Html::HTMLDOMParser] The parser with the
63
+ # elements found.
64
+ def find_descendants(selector)
65
+ # Interface method
66
+ end
67
+
68
+ ##
69
+ # Find all elements in the parser by selector, ancestors of found
70
+ # elements.
71
+ #
72
+ # @abstract
73
+ # @param selector [String, Hatemile::Util::Html::HTMLDOMElement] The
74
+ # selector.
75
+ # @return [Hatemile::Util::Html::HTMLDOMParser] The parser with the
76
+ # elements found.
77
+ def find_ancestors(selector)
78
+ # Interface method
79
+ end
80
+
81
+ ##
82
+ # Returns the first element found.
83
+ #
84
+ # @abstract
85
+ # @return [Hatemile::Util::Html::HTMLDOMElement] The first element found
86
+ # or null if not have elements found.
87
+ def first_result
88
+ # Interface method
89
+ end
90
+
91
+ ##
92
+ # Returns the last element found.
93
+ #
94
+ # @abstract
95
+ # @return [Hatemile::Util::Html::HTMLDOMElement] The last element found
96
+ # or null if not have elements found.
97
+ def last_result
98
+ # Interface method
99
+ end
100
+
101
+ ##
102
+ # Returns a list with all elements found.
103
+ #
104
+ # @abstract
105
+ # @return [Array<Hatemile::Util::Html::HTMLDOMElement>] The list with
106
+ # all elements found.
107
+ def list_results
108
+ # Interface method
109
+ end
110
+
111
+ ##
112
+ # Create a element.
113
+ #
114
+ # @abstract
115
+ # @param tag [String] The tag of element.
116
+ # @return [Hatemile::Util::Html::HTMLDOMElement] The element created.
117
+ def create_element(tag)
118
+ # Interface method
119
+ end
120
+
121
+ ##
122
+ # Returns the HTML code of parser.
123
+ #
124
+ # @abstract
125
+ # @return [String] The HTML code of parser.
126
+ def get_html
127
+ # Interface method
128
+ end
129
+
130
+ ##
131
+ # Returns the parser.
132
+ #
133
+ # @abstract
134
+ # @return [Object] The parser or root element of the parser.
135
+ def get_parser
136
+ # Interface method
137
+ end
138
+
139
+ ##
140
+ # Clear the memory of this object.
141
+ #
142
+ # @abstract
143
+ # @return [void]
144
+ def clear_parser
145
+ # Interface method
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,43 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require File.join(File.dirname(__FILE__), 'html_dom_node')
14
+
15
+ ##
16
+ # The Hatemile module contains the interfaces with the acessibility solutions.
17
+ module Hatemile
18
+ ##
19
+ # The Hatemile::Util module contains the utilities of library.
20
+ module Util
21
+ ##
22
+ # The Hatemile::Util::Html module contains the interfaces of HTML handles.
23
+ module Html
24
+ ##
25
+ # The HTMLDOMTextNode interface contains the methods for access of the
26
+ # HTML TextNode.
27
+ #
28
+ # @abstract
29
+ class HTMLDOMTextNode < HTMLDOMNode
30
+ private_class_method :new
31
+
32
+ ##
33
+ # Change the text content of text node.
34
+ #
35
+ # @abstract
36
+ # @param text [String] The new text content.
37
+ def set_text_content(text)
38
+ # Interface method
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,302 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require File.join(
14
+ File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))),
15
+ 'helper'
16
+ )
17
+ require File.join(File.dirname(File.dirname(__FILE__)), 'html_dom_element')
18
+ require File.join(File.dirname(__FILE__), 'nokogiri_html_dom_node')
19
+ require File.join(File.dirname(__FILE__), 'nokogiri_html_dom_text_node')
20
+
21
+ ##
22
+ # The Hatemile module contains the interfaces with the acessibility solutions.
23
+ module Hatemile
24
+ ##
25
+ # The Hatemile::Util module contains the utilities of library.
26
+ module Util
27
+ ##
28
+ # The Hatemile::Util::Html module contains the interfaces of HTML handles.
29
+ module Html
30
+ ##
31
+ # The Hatemile::Util::NokogiriLib module contains the implementation of
32
+ # HTML handles for Nokogiri library.
33
+ module NokogiriLib
34
+ ##
35
+ # The NokogiriHTMLDOMElement class is official implementation of
36
+ # HTMLDOMElement interface for the Nokogiri library.
37
+ class NokogiriHTMLDOMElement < Hatemile::Util::Html::HTMLDOMElement
38
+ include NokogiriHTMLDOMNode
39
+
40
+ public_class_method :new
41
+
42
+ ##
43
+ # Tags that are self closing.
44
+ SELF_CLOSING_TAGS = %w[
45
+ area base br col embed hr img input keygen
46
+ link menuitem meta param source track wbr
47
+ ].freeze
48
+
49
+ ##
50
+ # Initializes a new object that encapsulate the Nokogiri element.
51
+ #
52
+ # @param element [Nokogiri::XML::Node] The Nokogiri element.
53
+ def initialize(element)
54
+ Hatemile::Helper.require_not_nil(element)
55
+ Hatemile::Helper.require_valid_type(element, Nokogiri::XML::Node)
56
+
57
+ @data = element
58
+ init(element, self)
59
+ end
60
+
61
+ ##
62
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_tag_name
63
+ def get_tag_name
64
+ @data.name.upcase
65
+ end
66
+
67
+ ##
68
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_attribute
69
+ def get_attribute(name)
70
+ @data.get_attribute(name)
71
+ end
72
+
73
+ ##
74
+ # @see Hatemile::Util::Html::HTMLDOMElement#set_attribute
75
+ def set_attribute(name, value)
76
+ @data.set_attribute(name, value)
77
+ end
78
+
79
+ ##
80
+ # @see Hatemile::Util::Html::HTMLDOMElement#remove_attribute
81
+ def remove_attribute(name)
82
+ @data.remove_attribute(name) if has_attribute?(name)
83
+ end
84
+
85
+ ##
86
+ # @see Hatemile::Util::Html::HTMLDOMElement#has_attribute?
87
+ def has_attribute?(name)
88
+ !@data.attributes[name].nil?
89
+ end
90
+
91
+ ##
92
+ # @see Hatemile::Util::Html::HTMLDOMElement#has_attributes?
93
+ def has_attributes?
94
+ !@data.attributes.empty?
95
+ end
96
+
97
+ ##
98
+ # @see Hatemile::Util::Html::HTMLDOMElement#append_element
99
+ def append_element(element)
100
+ @data.add_child(element.get_data)
101
+ self
102
+ end
103
+
104
+ ##
105
+ # @see Hatemile::Util::Html::HTMLDOMElement#prepend_element
106
+ def prepend_element(element)
107
+ @data.prepend_child(element.get_data)
108
+ self
109
+ end
110
+
111
+ ##
112
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_children_elements
113
+ def get_children_elements
114
+ array = []
115
+ @data.element_children.each do |child|
116
+ array.push(NokogiriHTMLDOMElement.new(child))
117
+ end
118
+ array
119
+ end
120
+
121
+ ##
122
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_children
123
+ def get_children
124
+ array = []
125
+ @data.children.each do |child|
126
+ array.push(NokogiriHTMLDOMElement.new(child)) if child.element?
127
+ array.push(NokogiriHTMLDOMTextNode.new(child)) if child.text?
128
+ end
129
+ array
130
+ end
131
+
132
+ ##
133
+ # @see Hatemile::Util::Html::HTMLDOMElement#normalize
134
+ def normalize
135
+ return self unless has_children?
136
+
137
+ last = nil
138
+ get_children.each do |child|
139
+ if child.is_a?(NokogiriHTMLDOMElement)
140
+ child.normalize
141
+ elsif child.is_a?(NokogiriHTMLDOMTextNode) &&
142
+ last.is_a?(NokogiriHTMLDOMTextNode)
143
+ child.prepend_text(last.get_text_content)
144
+ last.remove_node
145
+ end
146
+ last = child
147
+ end
148
+
149
+ self
150
+ end
151
+
152
+ ##
153
+ # @see Hatemile::Util::Html::HTMLDOMNode#append_text
154
+ def append_text(text)
155
+ @data.add_child(Nokogiri::XML::Text.new(text, @data.document))
156
+ self
157
+ end
158
+
159
+ ##
160
+ # @see Hatemile::Util::Html::HTMLDOMNode#prepend_text
161
+ def prepend_text(text)
162
+ @data.prepend_child(Nokogiri::XML::Text.new(text, @data.document))
163
+ self
164
+ end
165
+
166
+ ##
167
+ # @see Hatemile::Util::Html::HTMLDOMElement#has_children_elements?
168
+ def has_children_elements?
169
+ @data.element_children.empty? == false
170
+ end
171
+
172
+ ##
173
+ # @see Hatemile::Util::Html::HTMLDOMElement#has_children?
174
+ def has_children?
175
+ @data.children.each do |child|
176
+ return true if child.element? || child.text?
177
+ end
178
+ false
179
+ end
180
+
181
+ ##
182
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_inner_html
183
+ def get_inner_html
184
+ html = ''
185
+ @data.children.each do |child|
186
+ html += to_string(child)
187
+ end
188
+ html
189
+ end
190
+
191
+ ##
192
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_outer_html
193
+ def get_outer_html
194
+ to_string(@data)
195
+ end
196
+
197
+ ##
198
+ # @see Hatemile::Util::Html::HTMLDOMNode#set_data
199
+ def set_data(data)
200
+ @data = data
201
+ set_node(data)
202
+ end
203
+
204
+ ##
205
+ # @see Hatemile::Util::Html::HTMLDOMElement#clone_element
206
+ def clone_element
207
+ NokogiriHTMLDOMElement.new(@data.clone)
208
+ end
209
+
210
+ ##
211
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_first_element_child
212
+ def get_first_element_child
213
+ return nil unless has_children_elements?
214
+ get_children_elements.first
215
+ end
216
+
217
+ ##
218
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_last_element_child
219
+ def get_last_element_child
220
+ return nil unless has_children_elements?
221
+ get_children_elements.last
222
+ end
223
+
224
+ ##
225
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_first_node_child
226
+ def get_first_node_child
227
+ return nil unless has_children?
228
+ get_children.first
229
+ end
230
+
231
+ ##
232
+ # @see Hatemile::Util::Html::HTMLDOMElement#get_last_node_child
233
+ def get_last_node_child
234
+ return nil unless has_children?
235
+ get_children.last
236
+ end
237
+
238
+ ##
239
+ # Convert a Nokogiri Node to a HTML code.
240
+ #
241
+ # @param node [Nokogiri::XML::Node] The Nokogiri Node.
242
+ # @return [String] The HTML code of the Nokogiri Node.
243
+ def to_string(node)
244
+ string = ''
245
+ if node.element?
246
+ string += "<#{node.name.downcase}"
247
+ node.attributes.each do |attribute, value|
248
+ string += " #{attribute}=\"#{value}\""
249
+ end
250
+ string += if node.children.empty? && self_closing_tag?(node.name)
251
+ ' />'
252
+ else
253
+ '>'
254
+ end
255
+ elsif node.comment?
256
+ string += node.to_s
257
+ elsif node.cdata?
258
+ string += node.to_s
259
+ elsif node.html?
260
+ document = node.to_s
261
+ string += document.split("\n")[0] + "\n"
262
+ elsif node.text?
263
+ string += node.text
264
+ end
265
+
266
+ node.children.each do |child|
267
+ string += to_string(child)
268
+ end
269
+
270
+ if node.element? &&
271
+ !(node.children.empty? && self_closing_tag?(node.name))
272
+ string += "</#{node.name.downcase}>"
273
+ end
274
+ string
275
+ end
276
+
277
+ ##
278
+ # Returns if the tag is self closing.
279
+ #
280
+ # @param tag [String] The element tag.
281
+ # @return [Boolean] True if the tag is self closing or false if not.
282
+ def self_closing_tag?(tag)
283
+ SELF_CLOSING_TAGS.include?(tag.downcase)
284
+ end
285
+
286
+ ##
287
+ # Compare if two elements object reference the same element.
288
+ #
289
+ # @param other [Hatemile::Util::Html::HTMLDOMElement] The other
290
+ # object.
291
+ # @return [Boolean] True if the object reference the same element or
292
+ # false if not.
293
+ def ==(other)
294
+ return false if other.nil?
295
+ return false unless other.is_a?(HTMLDOMElement)
296
+ get_data == other.get_data
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end