hatemile 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +9 -0
- data/LICENSE +202 -0
- data/Rakefile +64 -0
- data/hatemile.gemspec +37 -0
- data/lib/hatemile/accessible_association.rb +62 -0
- data/lib/hatemile/accessible_css.rb +43 -0
- data/lib/hatemile/accessible_display.rb +178 -0
- data/lib/hatemile/accessible_event.rb +95 -0
- data/lib/hatemile/accessible_form.rb +101 -0
- data/lib/hatemile/accessible_navigation.rb +82 -0
- data/lib/hatemile/helper.rb +58 -0
- data/lib/hatemile/implementation/accessible_association_implementation.rb +346 -0
- data/lib/hatemile/implementation/accessible_css_implementation.rb +772 -0
- data/lib/hatemile/implementation/accessible_display_implementation.rb +1362 -0
- data/lib/hatemile/implementation/accessible_event_implementation.rb +278 -0
- data/lib/hatemile/implementation/accessible_form_implementation.rb +386 -0
- data/lib/hatemile/implementation/accessible_navigation_implementation.rb +561 -0
- data/lib/hatemile/util/common_functions.rb +106 -0
- data/lib/hatemile/util/configure.rb +92 -0
- data/lib/hatemile/util/css/rcp/rcp_declaration.rb +77 -0
- data/lib/hatemile/util/css/rcp/rcp_parser.rb +115 -0
- data/lib/hatemile/util/css/rcp/rcp_rule.rb +86 -0
- data/lib/hatemile/util/css/style_sheet_declaration.rb +59 -0
- data/lib/hatemile/util/css/style_sheet_parser.rb +43 -0
- data/lib/hatemile/util/css/style_sheet_rule.rb +73 -0
- data/lib/hatemile/util/html/html_dom_element.rb +234 -0
- data/lib/hatemile/util/html/html_dom_node.rb +131 -0
- data/lib/hatemile/util/html/html_dom_parser.rb +150 -0
- data/lib/hatemile/util/html/html_dom_text_node.rb +43 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_element.rb +302 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_node.rb +112 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_parser.rb +208 -0
- data/lib/hatemile/util/html/nokogiri/nokogiri_html_dom_text_node.rb +83 -0
- data/lib/hatemile/util/id_generator.rb +53 -0
- data/lib/js/common.js +98 -0
- data/lib/js/eventlistener.js +36 -0
- data/lib/js/include.js +292 -0
- data/lib/js/scriptlist_validation_fields.js +13 -0
- data/lib/js/validation.js +205 -0
- data/lib/locale/en-US.yml +388 -0
- data/lib/locale/pt-BR.yml +389 -0
- data/lib/skippers.xml +6 -0
- data/lib/symbols.xml +40 -0
- data/test/locale/en-US.yml +5 -0
- data/test/locale/pt-BR.yml +4 -0
- data/test/test_accessible_association_implementation.rb +258 -0
- data/test/test_accessible_css_implementation.rb +518 -0
- data/test/test_accessible_display_implementation.rb +873 -0
- data/test/test_accessible_form_implementation.rb +283 -0
- data/test/test_accessible_navigation_implementation.rb +228 -0
- data/test/test_common_functions.rb +128 -0
- data/test/test_configure.rb +73 -0
- data/test/test_nokogiri_html_dom_element.rb +586 -0
- data/test/test_nokogiri_html_dom_parser.rb +363 -0
- data/test/test_nokogiri_html_dom_text_node.rb +225 -0
- data/test/test_rcp_declaration.rb +103 -0
- data/test/test_rcp_parser.rb +86 -0
- data/test/test_rcp_rule.rb +89 -0
- metadata +199 -0
@@ -0,0 +1,112 @@
|
|
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
|
+
|
18
|
+
##
|
19
|
+
# The Hatemile module contains the interfaces with the acessibility solutions.
|
20
|
+
module Hatemile
|
21
|
+
##
|
22
|
+
# The Hatemile::Util module contains the utilities of library.
|
23
|
+
module Util
|
24
|
+
##
|
25
|
+
# The Hatemile::Util::Html module contains the interfaces of HTML handles.
|
26
|
+
module Html
|
27
|
+
##
|
28
|
+
# The Hatemile::Util::NokogiriLib module contains the implementation of
|
29
|
+
# HTML handles for Nokogiri library.
|
30
|
+
module NokogiriLib
|
31
|
+
##
|
32
|
+
# The NokogiriHTMLDOMNode module is official implementation of
|
33
|
+
# HTMLDOMNode methods.
|
34
|
+
module NokogiriHTMLDOMNode
|
35
|
+
##
|
36
|
+
# Initializes a new object that encapsulate the Nokogiri node.
|
37
|
+
#
|
38
|
+
# @param node [Nokogiri::XML::Node] The Nokogiri node.
|
39
|
+
# @param hatemile_node [Hatemile::Util::Html::HTMLDOMNode] The
|
40
|
+
# HaTeMiLe node.
|
41
|
+
def init(node, hatemile_node)
|
42
|
+
Hatemile::Helper.require_not_nil(node, hatemile_node)
|
43
|
+
Hatemile::Helper.require_valid_type(node, Nokogiri::XML::Node)
|
44
|
+
Hatemile::Helper.require_valid_type(
|
45
|
+
hatemile_node,
|
46
|
+
Hatemile::Util::Html::HTMLDOMNode
|
47
|
+
)
|
48
|
+
|
49
|
+
@node = node
|
50
|
+
@hatemile_node = hatemile_node
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#get_text_content
|
55
|
+
def get_text_content
|
56
|
+
@node.text
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#insert_before
|
61
|
+
def insert_before(new_node)
|
62
|
+
@node.before(new_node.get_data)
|
63
|
+
@hatemile_node
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#insert_after
|
68
|
+
def insert_after(new_node)
|
69
|
+
@node.after(new_node.get_data)
|
70
|
+
@hatemile_node
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#remove_node
|
75
|
+
def remove_node
|
76
|
+
@node.remove
|
77
|
+
@hatemile_node
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#replace_node
|
82
|
+
def replace_node(new_node)
|
83
|
+
@node.replace(new_node.get_data)
|
84
|
+
@hatemile_node
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#get_parent_element
|
89
|
+
def get_parent_element
|
90
|
+
parent = @node.parent
|
91
|
+
if !parent.nil? && parent.element?
|
92
|
+
return NokogiriHTMLDOMElement.new(parent)
|
93
|
+
end
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#get_data
|
99
|
+
def get_data
|
100
|
+
@node
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#set_data
|
105
|
+
def set_node(node)
|
106
|
+
@node = node
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,208 @@
|
|
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 'nokogiri'
|
14
|
+
require File.join(
|
15
|
+
File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))),
|
16
|
+
'helper'
|
17
|
+
)
|
18
|
+
require File.join(File.dirname(File.dirname(__FILE__)), 'html_dom_parser')
|
19
|
+
require File.join(File.dirname(__FILE__), 'nokogiri_html_dom_element')
|
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 class NokogiriHTMLDOMParser is official implementation of
|
36
|
+
# HTMLDOMParser interface for the Nokogiri library.
|
37
|
+
class NokogiriHTMLDOMParser < Hatemile::Util::Html::HTMLDOMParser
|
38
|
+
public_class_method :new
|
39
|
+
|
40
|
+
##
|
41
|
+
# Initializes a new object that encapsulate the parser of Jsoup.
|
42
|
+
#
|
43
|
+
# @param code_or_parser [String, Nokogiri::HTML::Document] The HTML
|
44
|
+
# code or the parser of Nokogiri.
|
45
|
+
# @param encoding [String] The enconding of code.
|
46
|
+
def initialize(code_or_parser, encoding = 'UTF-8')
|
47
|
+
Hatemile::Helper.require_not_nil(code_or_parser, encoding)
|
48
|
+
Hatemile::Helper.require_valid_type(
|
49
|
+
code_or_parser,
|
50
|
+
String,
|
51
|
+
Nokogiri::HTML::Document
|
52
|
+
)
|
53
|
+
Hatemile::Helper.require_valid_type(encoding, String)
|
54
|
+
|
55
|
+
@document = if code_or_parser.class == String
|
56
|
+
Nokogiri::HTML::Document.parse(
|
57
|
+
code_or_parser,
|
58
|
+
nil,
|
59
|
+
encoding
|
60
|
+
)
|
61
|
+
else
|
62
|
+
code_or_parser
|
63
|
+
end
|
64
|
+
@results = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#find
|
69
|
+
def find(selector)
|
70
|
+
@results = if selector.is_a?(NokogiriHTMLDOMElement)
|
71
|
+
[selector.get_data]
|
72
|
+
elsif selector.is_a?(Array)
|
73
|
+
selector.map(&:get_data)
|
74
|
+
else
|
75
|
+
@document.css(selector)
|
76
|
+
end
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#find_children
|
82
|
+
def find_children(selector)
|
83
|
+
array = []
|
84
|
+
selector = [selector] if selector.is_a?(NokogiriHTMLDOMElement)
|
85
|
+
if selector.is_a?(Array)
|
86
|
+
selector.each do |element|
|
87
|
+
native_element = element.get_data
|
88
|
+
@results.each do |result|
|
89
|
+
if result.children.include?(native_element)
|
90
|
+
array.push(native_element)
|
91
|
+
break
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
else
|
96
|
+
@results.each do |result|
|
97
|
+
result.css(selector).each do |found_element|
|
98
|
+
array.push(found_element) if found_element.parent == result
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@results = array
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#find_descendants
|
108
|
+
def find_descendants(selector)
|
109
|
+
array = []
|
110
|
+
selector = [selector] if selector.is_a?(NokogiriHTMLDOMElement)
|
111
|
+
if selector.is_a?(Array)
|
112
|
+
selector.each do |element|
|
113
|
+
native_element = element.get_data
|
114
|
+
parents = native_element.ancestors
|
115
|
+
@results.each do |result|
|
116
|
+
if parents.include?(result)
|
117
|
+
array.push(native_element)
|
118
|
+
break
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
else
|
123
|
+
@results.each do |result|
|
124
|
+
array = array.concat(result.css(selector))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
@results = array
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#find_ancestors
|
133
|
+
def find_ancestors(selector)
|
134
|
+
array = []
|
135
|
+
selector = [selector] if selector.is_a?(NokogiriHTMLDOMElement)
|
136
|
+
if selector.is_a?(Array)
|
137
|
+
selector.each do |element|
|
138
|
+
native_element = element.get_data
|
139
|
+
@results.each do |result|
|
140
|
+
parents = result.ancestors
|
141
|
+
if parents.include?(native_element)
|
142
|
+
array.push(native_element)
|
143
|
+
break
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
else
|
148
|
+
@results.each do |result|
|
149
|
+
array = array.concat(result.ancestors(selector))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
@results = array
|
153
|
+
self
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#first_result
|
158
|
+
def first_result
|
159
|
+
return nil if @results.nil? || @results.empty?
|
160
|
+
NokogiriHTMLDOMElement.new(@results[0])
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#last_result
|
165
|
+
def last_result
|
166
|
+
return nil if @results.nil? || @results.empty?
|
167
|
+
NokogiriHTMLDOMElement.new(@results[@results.length - 1])
|
168
|
+
end
|
169
|
+
|
170
|
+
##
|
171
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#list_results
|
172
|
+
def list_results
|
173
|
+
array = []
|
174
|
+
@results.each do |result|
|
175
|
+
array.push(NokogiriHTMLDOMElement.new(result))
|
176
|
+
end
|
177
|
+
array
|
178
|
+
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#create_element
|
182
|
+
def create_element(tag)
|
183
|
+
NokogiriHTMLDOMElement.new(@document.create_element(tag))
|
184
|
+
end
|
185
|
+
|
186
|
+
##
|
187
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#get_html
|
188
|
+
def get_html
|
189
|
+
NokogiriHTMLDOMElement.new(@document).get_outer_html
|
190
|
+
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#get_parser
|
194
|
+
def get_parser
|
195
|
+
@document
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# @see Hatemile::Util::Html::HTMLDOMParser#clear_parser
|
200
|
+
def clear_parser
|
201
|
+
@document = nil
|
202
|
+
@results = nil
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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_text_node')
|
18
|
+
require File.join(File.dirname(__FILE__), 'nokogiri_html_dom_node')
|
19
|
+
|
20
|
+
##
|
21
|
+
# The Hatemile module contains the interfaces with the acessibility solutions.
|
22
|
+
module Hatemile
|
23
|
+
##
|
24
|
+
# The Hatemile::Util module contains the utilities of library.
|
25
|
+
module Util
|
26
|
+
##
|
27
|
+
# The Hatemile::Util::Html module contains the interfaces of HTML handles.
|
28
|
+
module Html
|
29
|
+
##
|
30
|
+
# The Hatemile::Util::NokogiriLib module contains the implementation of
|
31
|
+
# HTML handles for Nokogiri library.
|
32
|
+
module NokogiriLib
|
33
|
+
##
|
34
|
+
# The NokogiriHTMLDOMTextNode class is official implementation of
|
35
|
+
# HTMLDOMTextNode interface for the Nokogiri library.
|
36
|
+
class NokogiriHTMLDOMTextNode < Hatemile::Util::Html::HTMLDOMTextNode
|
37
|
+
include NokogiriHTMLDOMNode
|
38
|
+
|
39
|
+
public_class_method :new
|
40
|
+
|
41
|
+
##
|
42
|
+
# Initializes a new object that encapsulate the Nokogiri text node.
|
43
|
+
#
|
44
|
+
# @param text_node [Nokogiri::XML::Text] The Nokogiri text node.
|
45
|
+
def initialize(text_node)
|
46
|
+
Hatemile::Helper.require_not_nil(text_node)
|
47
|
+
Hatemile::Helper.require_valid_type(text_node, Nokogiri::XML::Text)
|
48
|
+
|
49
|
+
@data = text_node
|
50
|
+
init(text_node, self)
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# @see Hatemile::Util::Html::HTMLDOMTextNode#set_text_content
|
55
|
+
def set_text_content(text)
|
56
|
+
@data.content = text
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#append_text
|
61
|
+
def append_text(text)
|
62
|
+
set_text_content(get_text_content + text)
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#prepend_text
|
68
|
+
def prepend_text(text)
|
69
|
+
set_text_content(text + get_text_content)
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# @see Hatemile::Util::Html::HTMLDOMNode#set_data
|
75
|
+
def set_data(data)
|
76
|
+
@data = data
|
77
|
+
set_node(data)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 'securerandom'
|
14
|
+
require File.join(File.dirname(File.dirname(__FILE__)), 'helper')
|
15
|
+
|
16
|
+
##
|
17
|
+
# The Hatemile module contains the interfaces with the acessibility solutions.
|
18
|
+
module Hatemile
|
19
|
+
##
|
20
|
+
# The Hatemile::Util module contains the utilities of library.
|
21
|
+
module Util
|
22
|
+
##
|
23
|
+
# The IDGenerator class generate ids for
|
24
|
+
# Hatemile::Util::Html::HTMLDOMElement.
|
25
|
+
class IDGenerator
|
26
|
+
##
|
27
|
+
# Initializes a new object that generate ids for elements.
|
28
|
+
#
|
29
|
+
# @param prefix_part [String] A part of prefix id.
|
30
|
+
def initialize(prefix_part = nil)
|
31
|
+
Hatemile::Helper.require_valid_type(prefix_part, String)
|
32
|
+
|
33
|
+
@prefix_id = if prefix_part.nil?
|
34
|
+
"id-hatemile-#{SecureRandom.hex}-"
|
35
|
+
else
|
36
|
+
"id-hatemile-#{prefix_part}-#{SecureRandom.hex}-"
|
37
|
+
end
|
38
|
+
@count = 0
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Generate a id for a element.
|
43
|
+
#
|
44
|
+
# @param element [Hatemile::Util::Html::HTMLDOMElement] The element.
|
45
|
+
def generate_id(element)
|
46
|
+
return if element.has_attribute?('id')
|
47
|
+
|
48
|
+
element.set_attribute('id', "#{@prefix_id}#{@count}")
|
49
|
+
@count += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|