meteor 0.9.30 → 0.9.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +8 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +34 -3
- data/demo/html.rb +32 -38
- data/demo/html4.rb +27 -33
- data/demo/xhtml.rb +29 -35
- data/demo/xhtml4.rb +27 -33
- data/demo/xml.rb +20 -20
- data/lib/meteor/attribute.rb +1 -4
- data/lib/meteor/attribute_map.rb +21 -22
- data/lib/meteor/core/kernel.rb +604 -727
- data/lib/meteor/core/util/file_reader.rb +37 -0
- data/lib/meteor/core/util/pattern_cache.rb +7 -7
- data/lib/meteor/element.rb +48 -67
- data/lib/meteor/elements.rb +6 -6
- data/lib/meteor/exception/no_such_element_exception.rb +15 -15
- data/lib/meteor/ml/html/parser_impl.rb +69 -71
- data/lib/meteor/ml/html4/parser_impl.rb +129 -144
- data/lib/meteor/ml/xhtml/parser_impl.rb +44 -46
- data/lib/meteor/ml/xhtml4/parser_impl.rb +85 -87
- data/lib/meteor/ml/xml/parser_impl.rb +29 -29
- data/lib/meteor/parsers.rb +92 -100
- data/lib/meteor/root_element.rb +5 -8
- data/lib/meteor.rb +62 -61
- data/meteor.gemspec +14 -13
- data/test/meteor_test.rb +4 -2
- data/test/test_helper.rb +3 -2
- metadata +4 -4
- data/Rakefile +0 -144
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Meteor
|
|
4
|
+
module Core
|
|
5
|
+
module Util
|
|
6
|
+
#
|
|
7
|
+
# FileReader Class (ファイル・リーダー クラス)
|
|
8
|
+
#
|
|
9
|
+
class FileReader
|
|
10
|
+
#
|
|
11
|
+
# read file (ファイルを読み込む)
|
|
12
|
+
# @param [String] file_path absolute path of input file (入力ファイルの絶対パス)
|
|
13
|
+
# @param [String] enc character encoding of input file (入力ファイルの文字コード)
|
|
14
|
+
#
|
|
15
|
+
def self.read(file_path, enc)
|
|
16
|
+
mode = if enc == 'UTF-8'
|
|
17
|
+
# String.new("") << "r:" << enc
|
|
18
|
+
'r:UTF-8'
|
|
19
|
+
else
|
|
20
|
+
String.new('') << 'r:' << enc << ':utf-8'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# open file (ファイルのオープン)
|
|
24
|
+
io = File.open(file_path, mode)
|
|
25
|
+
|
|
26
|
+
# load (読込)
|
|
27
|
+
data = io.read
|
|
28
|
+
|
|
29
|
+
# close file (ファイルのクローズ)
|
|
30
|
+
io.close
|
|
31
|
+
|
|
32
|
+
data
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -8,7 +8,7 @@ module Meteor
|
|
|
8
8
|
# Pattern Cache Class (パターン・キャッシュ クラス)
|
|
9
9
|
#
|
|
10
10
|
class PatternCache
|
|
11
|
-
@@regex_cache =
|
|
11
|
+
@@regex_cache = {}
|
|
12
12
|
|
|
13
13
|
##
|
|
14
14
|
## intializer (イニシャライザ)
|
|
@@ -29,9 +29,9 @@ module Meteor
|
|
|
29
29
|
def self.get(*args)
|
|
30
30
|
case args.length
|
|
31
31
|
when ONE
|
|
32
|
-
|
|
32
|
+
get_one(args[0])
|
|
33
33
|
when TWO
|
|
34
|
-
|
|
34
|
+
get_two(args[0], args[1])
|
|
35
35
|
else
|
|
36
36
|
raise ArgumentError
|
|
37
37
|
end
|
|
@@ -42,7 +42,7 @@ module Meteor
|
|
|
42
42
|
# @param [String] regex regular expression (正規表現)
|
|
43
43
|
# @return [Regexp] pattern (パターン)
|
|
44
44
|
#
|
|
45
|
-
def self.
|
|
45
|
+
def self.get_one(regex)
|
|
46
46
|
if @@regex_cache[regex.to_sym]
|
|
47
47
|
@@regex_cache[regex.to_sym]
|
|
48
48
|
else
|
|
@@ -56,7 +56,7 @@ module Meteor
|
|
|
56
56
|
# @param [Integer] option (オプション)
|
|
57
57
|
# @return [Regexp] psttern (パターン)
|
|
58
58
|
#
|
|
59
|
-
def self.
|
|
59
|
+
def self.get_two(regex, option)
|
|
60
60
|
if @@regex_cache[regex.to_sym]
|
|
61
61
|
@@regex_cache[regex.to_sym]
|
|
62
62
|
else
|
|
@@ -65,8 +65,8 @@ module Meteor
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
class << self
|
|
68
|
-
private :
|
|
69
|
-
private :
|
|
68
|
+
private :get_one
|
|
69
|
+
private :get_two
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
data/lib/meteor/element.rb
CHANGED
|
@@ -37,27 +37,14 @@ module Meteor
|
|
|
37
37
|
# @return [true,false] deletion flag (削除フラグ)
|
|
38
38
|
#
|
|
39
39
|
class Element
|
|
40
|
-
attr_accessor :name
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
attr_accessor :mono
|
|
49
|
-
attr_accessor :parser
|
|
50
|
-
attr_accessor :type_value
|
|
51
|
-
attr_accessor :usable
|
|
52
|
-
attr_accessor :origin
|
|
53
|
-
attr_accessor :copy
|
|
54
|
-
attr_accessor :removed
|
|
55
|
-
|
|
56
|
-
alias_method :tag, :name
|
|
57
|
-
alias_method :tag=, :name=
|
|
58
|
-
|
|
59
|
-
alias_method :empty, :normal
|
|
60
|
-
alias_method :empty=, :normal=
|
|
40
|
+
attr_accessor :name, :attributes, :mixed_content, :raw_content, :pattern, :document_sync, :normal, :cx, :mono,
|
|
41
|
+
:parser, :type_value, :usable, :origin, :copy, :removed
|
|
42
|
+
|
|
43
|
+
alias tag name
|
|
44
|
+
alias tag= name=
|
|
45
|
+
|
|
46
|
+
alias empty normal
|
|
47
|
+
alias empty= normal=
|
|
61
48
|
|
|
62
49
|
#
|
|
63
50
|
# initializer (イニシャライザ)
|
|
@@ -72,15 +59,15 @@ module Meteor
|
|
|
72
59
|
def initialize(*args)
|
|
73
60
|
case args.length
|
|
74
61
|
when Meteor::ONE
|
|
75
|
-
if args[0].
|
|
62
|
+
if args[0].is_a?(String)
|
|
76
63
|
initialize_s(args[0])
|
|
77
|
-
elsif args[0].
|
|
64
|
+
elsif args[0].is_a?(Meteor::Element)
|
|
78
65
|
initialize_e(args[0])
|
|
79
66
|
else
|
|
80
67
|
raise ArgumentError
|
|
81
68
|
end
|
|
82
69
|
when Meteor::TWO
|
|
83
|
-
|
|
70
|
+
initialize_two(args[0], args[1])
|
|
84
71
|
when Meteor::ZERO
|
|
85
72
|
else
|
|
86
73
|
raise ArgumentError
|
|
@@ -112,15 +99,15 @@ module Meteor
|
|
|
112
99
|
# @param [Meteor::Element] elm element (要素)
|
|
113
100
|
#
|
|
114
101
|
def initialize_e(elm)
|
|
115
|
-
|
|
102
|
+
initialize_two(elm, elm.parser)
|
|
116
103
|
@usable = true
|
|
117
104
|
end
|
|
118
105
|
|
|
119
106
|
private :initialize_e
|
|
120
107
|
|
|
121
|
-
def
|
|
108
|
+
def initialize_two(elm, ps)
|
|
122
109
|
@parser = ps
|
|
123
|
-
if
|
|
110
|
+
if normal
|
|
124
111
|
ps.element(elm)
|
|
125
112
|
else
|
|
126
113
|
@name = elm.name
|
|
@@ -138,7 +125,7 @@ module Meteor
|
|
|
138
125
|
end
|
|
139
126
|
end
|
|
140
127
|
|
|
141
|
-
private :
|
|
128
|
+
private :initialize_two
|
|
142
129
|
|
|
143
130
|
#
|
|
144
131
|
# clone (複製する)
|
|
@@ -151,9 +138,9 @@ module Meteor
|
|
|
151
138
|
def clone(*args)
|
|
152
139
|
case args.length
|
|
153
140
|
when Meteor::ZERO
|
|
154
|
-
|
|
141
|
+
clone_zero
|
|
155
142
|
when Meteor::ONE
|
|
156
|
-
|
|
143
|
+
clone_one(args[0])
|
|
157
144
|
end
|
|
158
145
|
end
|
|
159
146
|
|
|
@@ -161,45 +148,43 @@ module Meteor
|
|
|
161
148
|
# clone (複製する)
|
|
162
149
|
# @return [Meteor::Element] element (要素)
|
|
163
150
|
#
|
|
164
|
-
def
|
|
165
|
-
obj =
|
|
151
|
+
def clone_zero
|
|
152
|
+
obj = parser.element_cache[object_id]
|
|
166
153
|
if obj
|
|
167
|
-
obj.attributes = String.new(
|
|
168
|
-
obj.mixed_content = String.new(
|
|
154
|
+
obj.attributes = String.new(attributes)
|
|
155
|
+
obj.mixed_content = String.new(mixed_content)
|
|
169
156
|
# obj.pattern = String.new(self.pattern)
|
|
170
|
-
obj.document = String.new(
|
|
157
|
+
obj.document = String.new(document)
|
|
171
158
|
obj.usable = true
|
|
172
|
-
obj
|
|
173
159
|
else
|
|
174
160
|
obj = self.class.new(self)
|
|
175
|
-
|
|
176
|
-
obj
|
|
161
|
+
parser.element_cache[object_id] = obj
|
|
177
162
|
end
|
|
163
|
+
obj
|
|
178
164
|
end
|
|
179
165
|
|
|
180
|
-
private :
|
|
166
|
+
private :clone_zero
|
|
181
167
|
|
|
182
168
|
#
|
|
183
169
|
# clone (複製する)
|
|
184
170
|
# @param [Meteor::Parser] ps parser (パーサ)
|
|
185
171
|
# @return [Meteor::Element] element (要素)
|
|
186
172
|
#
|
|
187
|
-
def
|
|
173
|
+
def clone_one(ps)
|
|
188
174
|
obj = ps.element_hook
|
|
189
175
|
if obj
|
|
190
|
-
obj.attributes = String.new(
|
|
191
|
-
obj.mixed_content = String.new(
|
|
176
|
+
obj.attributes = String.new(attributes)
|
|
177
|
+
obj.mixed_content = String.new(mixed_content)
|
|
192
178
|
# obj.pattern = String.new(self.pattern)
|
|
193
|
-
obj.document = String.new(
|
|
194
|
-
obj
|
|
179
|
+
obj.document = String.new(document)
|
|
195
180
|
else
|
|
196
181
|
obj = self.class.new(self, ps)
|
|
197
182
|
ps.element_hook = obj
|
|
198
|
-
obj
|
|
199
183
|
end
|
|
184
|
+
obj
|
|
200
185
|
end
|
|
201
186
|
|
|
202
|
-
private :
|
|
187
|
+
private :clone_one
|
|
203
188
|
|
|
204
189
|
#
|
|
205
190
|
# set document (ドキュメントをセットする)
|
|
@@ -222,27 +207,23 @@ module Meteor
|
|
|
222
207
|
if @cx
|
|
223
208
|
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->' << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
224
209
|
@document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
210
|
+
elsif @normal
|
|
211
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
|
|
212
|
+
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
225
213
|
else
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
229
|
-
else
|
|
230
|
-
@document = String.new("") << "<" << @name << @attributes << ">"
|
|
231
|
-
# @document = "<#{@name}#{@attributes}>"
|
|
232
|
-
end
|
|
214
|
+
@document = String.new('') << '<' << @name << @attributes << '>'
|
|
215
|
+
# @document = "<#{@name}#{@attributes}>"
|
|
233
216
|
end
|
|
234
217
|
when Parser::XHTML, Parser::XHTML4, Parser::XML
|
|
235
218
|
if @cx
|
|
236
219
|
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->' << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
237
220
|
@document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
221
|
+
elsif @normal
|
|
222
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
|
|
223
|
+
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
238
224
|
else
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
242
|
-
else
|
|
243
|
-
@document = String.new("") << "<" << @name << @attributes << "/>"
|
|
244
|
-
# @document = "<#{@name}#{@attributes}/>"
|
|
245
|
-
end
|
|
225
|
+
@document = String.new('') << '<' << @name << @attributes << '/>'
|
|
226
|
+
# @document = "<#{@name}#{@attributes}/>"
|
|
246
227
|
end
|
|
247
228
|
end
|
|
248
229
|
else
|
|
@@ -309,7 +290,7 @@ module Meteor
|
|
|
309
290
|
end
|
|
310
291
|
end
|
|
311
292
|
|
|
312
|
-
|
|
293
|
+
alias child element
|
|
313
294
|
|
|
314
295
|
#
|
|
315
296
|
# get elements (要素を取得する)
|
|
@@ -367,7 +348,7 @@ module Meteor
|
|
|
367
348
|
@parser.find(selector)
|
|
368
349
|
end
|
|
369
350
|
|
|
370
|
-
|
|
351
|
+
alias css find
|
|
371
352
|
|
|
372
353
|
#
|
|
373
354
|
# get cx(comment extension) tag (CX(コメント拡張)タグを取得する)
|
|
@@ -473,7 +454,7 @@ module Meteor
|
|
|
473
454
|
@parser.content(self, *args)
|
|
474
455
|
end
|
|
475
456
|
|
|
476
|
-
|
|
457
|
+
alias text content
|
|
477
458
|
|
|
478
459
|
#
|
|
479
460
|
# set content of element (要素の内容をセットする)
|
|
@@ -484,7 +465,7 @@ module Meteor
|
|
|
484
465
|
@parser.content(self, value)
|
|
485
466
|
end
|
|
486
467
|
|
|
487
|
-
|
|
468
|
+
alias text= content=
|
|
488
469
|
|
|
489
470
|
#
|
|
490
471
|
# set content of element (要素の内容をセットする)
|
|
@@ -495,7 +476,7 @@ module Meteor
|
|
|
495
476
|
@parser.content(self, value, false)
|
|
496
477
|
end
|
|
497
478
|
|
|
498
|
-
|
|
479
|
+
alias unsafe_text= unsafe_content=
|
|
499
480
|
|
|
500
481
|
#
|
|
501
482
|
# set attribute (属性をセットする)
|
|
@@ -504,7 +485,7 @@ module Meteor
|
|
|
504
485
|
# @return [Meteor::Element] element (要素)
|
|
505
486
|
#
|
|
506
487
|
def []=(name, value)
|
|
507
|
-
if value
|
|
488
|
+
if !value.nil?
|
|
508
489
|
@parser.attr(self, name, value)
|
|
509
490
|
else
|
|
510
491
|
@parser.remove_attr(self, name)
|
|
@@ -543,7 +524,7 @@ module Meteor
|
|
|
543
524
|
@parser.flash
|
|
544
525
|
end
|
|
545
526
|
|
|
546
|
-
|
|
527
|
+
alias flush flash
|
|
547
528
|
|
|
548
529
|
#
|
|
549
530
|
# @overload execute(hook)
|
data/lib/meteor/elements.rb
CHANGED
|
@@ -23,13 +23,13 @@ module Meteor
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
#
|
|
26
|
-
|
|
26
|
+
# @overload add(type,relative_path,enc)
|
|
27
27
|
# add parser (パーサを追加する)
|
|
28
28
|
# @param [Integer] type type of parser (パーサ・タイプ)
|
|
29
29
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
|
30
30
|
# @param [String] enc character encoding (エンコーディング)
|
|
31
31
|
# @return [Meteor::Parser] parser (パーサ)
|
|
32
|
-
|
|
32
|
+
# @overload add(type,relative_path)
|
|
33
33
|
# add parser (パーサを追加する)
|
|
34
34
|
# @param [Integer] type type of parser (パーサ・タイプ)
|
|
35
35
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
|
@@ -57,9 +57,9 @@ module Meteor
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
class << self
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
alias link add
|
|
61
|
+
alias add_str add_template
|
|
62
|
+
alias link_str add_template
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
#
|
|
@@ -72,7 +72,7 @@ module Meteor
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
class << self
|
|
75
|
-
|
|
75
|
+
alias element get
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -38,47 +38,47 @@ module Meteor
|
|
|
38
38
|
def initialize(*args)
|
|
39
39
|
case args.length
|
|
40
40
|
when ONE
|
|
41
|
-
|
|
41
|
+
initialize_one(args[0])
|
|
42
42
|
when TWO
|
|
43
|
-
|
|
43
|
+
initialize_two(args[0], args[1])
|
|
44
44
|
when THREE
|
|
45
|
-
|
|
45
|
+
initialize_three(args[0], args[1], args[2])
|
|
46
46
|
when FOUR
|
|
47
|
-
|
|
47
|
+
initialize_four(args[0], args[1], args[2], args[3])
|
|
48
48
|
when FIVE
|
|
49
|
-
|
|
49
|
+
initialize_five(args[0], args[1], args[2], args[3], args[4])
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def
|
|
53
|
+
def initialize_one(name)
|
|
54
54
|
self.message = "element not found : #{name}"
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
private :
|
|
57
|
+
private :initialize_one
|
|
58
58
|
|
|
59
|
-
def
|
|
59
|
+
def initialize_two(attr_name, attr_value)
|
|
60
60
|
self.message = "element not found : [#{attr_name}=#{attr_value}]"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
private :
|
|
63
|
+
private :initialize_two
|
|
64
64
|
|
|
65
|
-
def
|
|
65
|
+
def initialize_three(name, attr_name, attr_value)
|
|
66
66
|
self.message = "element not found : #{name}[#{attr_name}=#{attr_value}]"
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
private :
|
|
69
|
+
private :initialize_three
|
|
70
70
|
|
|
71
|
-
def
|
|
71
|
+
def initialize_four(attr_name1, attr_value1, attr_name2, attr_value2)
|
|
72
72
|
self.message = "element not found : [#{attr_name1}=#{attr_value1}][#{attr_name2}=#{attr_value2}]"
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
private :
|
|
75
|
+
private :initialize_four
|
|
76
76
|
|
|
77
|
-
def
|
|
77
|
+
def initialize_five(name, attr_name1, attr_value1, attr_name2, attr_value2)
|
|
78
78
|
self.message = "element not found : #{name}[#{attr_name1}=#{attr_value1}][#{attr_name2}=#{attr_value2}]"
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
private :
|
|
81
|
+
private :initialize_five
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -8,42 +8,42 @@ module Meteor
|
|
|
8
8
|
# HTML parser (HTMLパーサ)
|
|
9
9
|
#
|
|
10
10
|
class ParserImpl < Meteor::Ml::Html4::ParserImpl
|
|
11
|
-
#[Array] void elements (空要素)
|
|
12
|
-
MATCH_TAG = [
|
|
13
|
-
|
|
14
|
-
#[Array] non-nestable elements (入れ子にできない要素)
|
|
15
|
-
MATCH_TAG_NNE = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
#[Array] boolean attributes (論理値で指定する属性)
|
|
36
|
-
ATTR_BOOL = [
|
|
37
|
-
|
|
38
|
-
#[Array] elements with the disabled attribute (disabled属性のある要素)
|
|
39
|
-
DISABLE_ELEMENT = [
|
|
40
|
-
|
|
41
|
-
#[Array] elements with the required attribute (required属性のある要素)
|
|
42
|
-
REQUIRE_ELEMENT = [
|
|
43
|
-
|
|
44
|
-
REQUIRED_M =
|
|
11
|
+
# [Array] void elements (空要素)
|
|
12
|
+
MATCH_TAG = %w[br hr img input meta base embed command keygen].freeze
|
|
13
|
+
|
|
14
|
+
# [Array] non-nestable elements (入れ子にできない要素)
|
|
15
|
+
MATCH_TAG_NNE = %w[
|
|
16
|
+
texarea
|
|
17
|
+
select
|
|
18
|
+
option
|
|
19
|
+
form
|
|
20
|
+
fieldset
|
|
21
|
+
figure
|
|
22
|
+
figcaption
|
|
23
|
+
video
|
|
24
|
+
audio
|
|
25
|
+
progress
|
|
26
|
+
meter
|
|
27
|
+
time
|
|
28
|
+
ruby
|
|
29
|
+
rt
|
|
30
|
+
rp
|
|
31
|
+
datalist
|
|
32
|
+
output
|
|
33
|
+
].freeze
|
|
34
|
+
|
|
35
|
+
# [Array] boolean attributes (論理値で指定する属性)
|
|
36
|
+
ATTR_BOOL = %w[disabled readonly checked selected multiple required].freeze
|
|
37
|
+
|
|
38
|
+
# [Array] elements with the disabled attribute (disabled属性のある要素)
|
|
39
|
+
DISABLE_ELEMENT = %w[input textarea select optgroup fieldset].freeze
|
|
40
|
+
|
|
41
|
+
# [Array] elements with the required attribute (required属性のある要素)
|
|
42
|
+
REQUIRE_ELEMENT = %w[input textarea].freeze
|
|
43
|
+
|
|
44
|
+
REQUIRED_M = '\\srequired\\s|\\srequired$|\\sREQUIRED\\s|\\sREQUIRED$'
|
|
45
45
|
# REQUIRED_M = [' required ',' required',' REQUIRED ',' REQUIRED']
|
|
46
|
-
REQUIRED_R =
|
|
46
|
+
REQUIRED_R = 'required\\s|required$|REQUIRED\\s|REQUIRED$'
|
|
47
47
|
|
|
48
48
|
@@pattern_required_m = Regexp.new(REQUIRED_M)
|
|
49
49
|
@@pattern_required_r = Regexp.new(REQUIRED_R)
|
|
@@ -62,9 +62,9 @@ module Meteor
|
|
|
62
62
|
@doc_type = Parser::HTML
|
|
63
63
|
case args.length
|
|
64
64
|
when ZERO
|
|
65
|
-
#
|
|
65
|
+
# initialize_zero
|
|
66
66
|
when ONE
|
|
67
|
-
|
|
67
|
+
initialize_one(args[0])
|
|
68
68
|
else
|
|
69
69
|
raise ArgumentError
|
|
70
70
|
end
|
|
@@ -73,16 +73,16 @@ module Meteor
|
|
|
73
73
|
#
|
|
74
74
|
# initializer (イニシャライザ)
|
|
75
75
|
#
|
|
76
|
-
# def
|
|
76
|
+
# def initialize_zero
|
|
77
77
|
# end
|
|
78
78
|
#
|
|
79
|
-
# private :
|
|
79
|
+
# private :initialize_zero
|
|
80
80
|
|
|
81
81
|
#
|
|
82
82
|
# initializer (イニシャライザ)
|
|
83
83
|
# @param [Meteor::Parser] ps parser (パーサ)
|
|
84
84
|
#
|
|
85
|
-
def
|
|
85
|
+
def initialize_one(ps)
|
|
86
86
|
@root.document = String.new(ps.document)
|
|
87
87
|
self.document_hook = String.new(ps.document_hook)
|
|
88
88
|
@root.content_type = String.new(ps.root_element.content_type)
|
|
@@ -90,7 +90,7 @@ module Meteor
|
|
|
90
90
|
@root.newline = ps.root_element.newline
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
private :
|
|
93
|
+
private :initialize_one
|
|
94
94
|
|
|
95
95
|
#
|
|
96
96
|
# analyze document , set content type (ドキュメントをパースし、コンテントタイプをセットする)
|
|
@@ -98,42 +98,39 @@ module Meteor
|
|
|
98
98
|
def analyze_content_type
|
|
99
99
|
@error_check = false
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
element_three('meta', 'charset', '[a-zA-Z-]+', false)
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
element_3("meta", "charset", "[a-zA-Z-]+", false)
|
|
105
|
-
end
|
|
103
|
+
element_three('meta', 'charset', '[a-zA-Z-]+', false) unless @elm_
|
|
106
104
|
|
|
107
105
|
@error_check = true
|
|
108
106
|
|
|
109
107
|
if @elm_
|
|
110
|
-
@root.charset = @elm_.attr(
|
|
111
|
-
|
|
112
|
-
@root.charset = "utf-8"
|
|
113
|
-
end
|
|
108
|
+
@root.charset = @elm_.attr('charset')
|
|
109
|
+
@root.charset = 'utf-8' unless @root.charset
|
|
114
110
|
else
|
|
115
|
-
@root.charset =
|
|
111
|
+
@root.charset = 'utf-8'
|
|
116
112
|
end
|
|
117
113
|
|
|
118
|
-
@root.content_type =
|
|
114
|
+
@root.content_type = 'text/html'
|
|
119
115
|
end
|
|
120
116
|
|
|
121
117
|
private :analyze_content_type
|
|
122
118
|
|
|
123
119
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
124
|
-
if is_match(
|
|
125
|
-
|
|
126
|
-
elsif is_match(
|
|
127
|
-
|
|
128
|
-
elsif is_match(
|
|
129
|
-
|
|
130
|
-
elsif is_match(
|
|
131
|
-
|
|
132
|
-
elsif is_match(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
120
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
121
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_selected_m, @@pattern_selected_r)
|
|
122
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
123
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_multiple_m, @@pattern_multiple_r)
|
|
124
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
125
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_disabled_m, @@pattern_disabled_r)
|
|
126
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
127
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_checked_m, @@pattern_checked_r)
|
|
128
|
+
elsif is_match('readonly', attr_name) &&
|
|
129
|
+
(is_match('textarea',
|
|
130
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
131
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_readonly_m, @@pattern_readonly_r)
|
|
132
|
+
elsif is_match('required', attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
|
|
133
|
+
edit_attrs_five(elm, attr_name, attr_value, @@pattern_required_m, @@pattern_required_r)
|
|
137
134
|
else
|
|
138
135
|
super(elm, attr_name, attr_value)
|
|
139
136
|
end
|
|
@@ -142,18 +139,19 @@ module Meteor
|
|
|
142
139
|
private :edit_attrs_
|
|
143
140
|
|
|
144
141
|
def get_attr_value_(elm, attr_name)
|
|
145
|
-
if is_match(
|
|
142
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
146
143
|
get_attr_value_r(elm, @@pattern_selected_m)
|
|
147
|
-
elsif is_match(
|
|
144
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
148
145
|
get_attr_value_r(elm, @@pattern_multiple_m)
|
|
149
|
-
elsif is_match(
|
|
146
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
150
147
|
get_attr_value_r(elm, @@pattern_disabled_m)
|
|
151
|
-
elsif is_match(
|
|
148
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
152
149
|
get_attr_value_r(elm, @@pattern_checked_m)
|
|
153
|
-
elsif is_match(
|
|
154
|
-
|
|
150
|
+
elsif is_match('readonly', attr_name) &&
|
|
151
|
+
(is_match('textarea',
|
|
152
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
155
153
|
get_attr_value_r(elm, @@pattern_readonly_m)
|
|
156
|
-
elsif is_match(
|
|
154
|
+
elsif is_match('required', attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
|
|
157
155
|
get_attr_value_r(elm, @@pattern_required_m)
|
|
158
156
|
else
|
|
159
157
|
super(elm, attr_name)
|