meteor 0.9.30 → 0.9.31
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 +4 -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 +27 -33
- data/demo/xhtml4.rb +25 -31
- data/demo/xml.rb +20 -20
- data/lib/meteor/attribute.rb +1 -4
- data/lib/meteor/attribute_map.rb +15 -16
- data/lib/meteor/core/kernel.rb +482 -605
- data/lib/meteor/core/util/file_reader.rb +37 -0
- data/lib/meteor/core/util/pattern_cache.rb +1 -1
- data/lib/meteor/element.rb +38 -57
- data/lib/meteor/elements.rb +6 -6
- data/lib/meteor/ml/html/parser_impl.rb +57 -59
- data/lib/meteor/ml/html4/parser_impl.rb +87 -102
- data/lib/meteor/ml/xhtml/parser_impl.rb +32 -34
- data/lib/meteor/ml/xhtml4/parser_impl.rb +72 -74
- data/lib/meteor/ml/xml/parser_impl.rb +23 -23
- data/lib/meteor/parsers.rb +54 -62
- 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
|
@@ -10,50 +10,50 @@ module Meteor
|
|
|
10
10
|
class ParserImpl < Meteor::Core::Kernel
|
|
11
11
|
# KAIGYO_CODE = "\r?\n|\r"
|
|
12
12
|
# KAIGYO_CODE = "\r\n|\n|\r"
|
|
13
|
-
KAIGYO_CODE = ["\r\n", "\n", "\r"]
|
|
14
|
-
BR =
|
|
13
|
+
KAIGYO_CODE = ["\r\n", "\n", "\r"].freeze
|
|
14
|
+
BR = '<br>'
|
|
15
15
|
BR_RE = BR
|
|
16
16
|
|
|
17
17
|
# @@match_tag = "br|hr|img|input|meta|base"
|
|
18
|
-
#[Array] void elemets (空要素)
|
|
19
|
-
@@match_tag = [
|
|
18
|
+
# [Array] void elemets (空要素)
|
|
19
|
+
@@match_tag = %w[br hr img input meta base]
|
|
20
20
|
# @@match_tag_2 = "textarea|option|pre"
|
|
21
|
-
#[Array] elements where line breaks do not need to be converted to <br> (改行を<br>に変換する必要のない要素)
|
|
22
|
-
@@match_tag_2 = [
|
|
21
|
+
# [Array] elements where line breaks do not need to be converted to <br> (改行を<br>に変換する必要のない要素)
|
|
22
|
+
@@match_tag_2 = %w[textarea option pre]
|
|
23
23
|
|
|
24
|
-
#[Array] non-nestable elements (入れ子にできない要素)
|
|
25
|
-
@@match_tag_nne = [
|
|
24
|
+
# [Array] non-nestable elements (入れ子にできない要素)
|
|
25
|
+
@@match_tag_nne = %w[texarea select option form fieldset]
|
|
26
26
|
|
|
27
|
-
#[Array] boolean attributes (論理値で指定する属性)
|
|
28
|
-
@@attr_bool = [
|
|
27
|
+
# [Array] boolean attributes (論理値で指定する属性)
|
|
28
|
+
@@attr_bool = %w[disabled readonly checked selected multiple]
|
|
29
29
|
|
|
30
30
|
# DISABLE_ELEMENT = "input|textarea|select|optgroup"
|
|
31
|
-
#[Array] elements with the disabled attribute (disabled属性のある要素)
|
|
32
|
-
DISABLE_ELEMENT = [
|
|
31
|
+
# [Array] elements with the disabled attribute (disabled属性のある要素)
|
|
32
|
+
DISABLE_ELEMENT = %w[input textarea select optgroup].freeze
|
|
33
33
|
# READONLY_TYPE = "text|password"
|
|
34
|
-
#[Array] the type of an input element with a readonly attribute (readonly属性のあるinput要素のタイプ)
|
|
35
|
-
READONLY_TYPE = [
|
|
34
|
+
# [Array] the type of an input element with a readonly attribute (readonly属性のあるinput要素のタイプ)
|
|
35
|
+
READONLY_TYPE = %w[text password].freeze
|
|
36
36
|
|
|
37
|
-
SELECTED_M =
|
|
37
|
+
SELECTED_M = '\\sselected\\s|\\sselected$|\\sSELECTED\\s|\\sSELECTED$'
|
|
38
38
|
# SELECTED_M = [' selected ',' selected',' SELECTED ',' SELECTED']
|
|
39
|
-
SELECTED_R =
|
|
40
|
-
CHECKED_M =
|
|
39
|
+
SELECTED_R = 'selected\\s|selected$|SELECTED\\s|SELECTED$'
|
|
40
|
+
CHECKED_M = '\\schecked\\s|\\schecked$|\\sCHECKED\\s|\\sCHECKED$'
|
|
41
41
|
# CHECKED_M = [' checked ',' checked',' CHECKED ',' CHECKED']
|
|
42
|
-
CHECKED_R =
|
|
43
|
-
DISABLED_M =
|
|
42
|
+
CHECKED_R = 'checked\\s|checked$|CHECKED\\s|CHECKED$'
|
|
43
|
+
DISABLED_M = '\\sdisabled\\s|\\sdisabled$|\\sDISABLED\\s|\\sDISABLED$'
|
|
44
44
|
# DISABLED_M = [' disabled ',' disiabled',' DISABLED ',' DISABLED']
|
|
45
|
-
DISABLED_R =
|
|
46
|
-
READONLY_M =
|
|
45
|
+
DISABLED_R = 'disabled\\s|disabled$|DISABLED\\s|DISABLED$'
|
|
46
|
+
READONLY_M = '\\sreadonly\\s|\\sreadonly$|\\sREADONLY\\s|\\sREADONLY$'
|
|
47
47
|
# READONLY_M = [' readonly ',' readonly',' READONLY ',' READONLY']
|
|
48
|
-
READONLY_R =
|
|
49
|
-
MULTIPLE_M =
|
|
48
|
+
READONLY_R = 'readonly\\s|readonly$|READONLY\\s|READONLY$'
|
|
49
|
+
MULTIPLE_M = '\\smultiple\\s|\\smultiple$|\\sMULTIPLE\\s|\\sMULTIPLE$'
|
|
50
50
|
# MULTIPLE_M = [' multiple ',' multiple',' MULTIPLE ',' MULTIPLE']
|
|
51
|
-
MULTIPLE_R =
|
|
51
|
+
MULTIPLE_R = 'multiple\\s|multiple$|MULTIPLE\\s|MULTIPLE$'
|
|
52
52
|
|
|
53
53
|
# @@pattern_true = Regexp.new("true")
|
|
54
54
|
# @@pattern_false = Regexp.new("false")
|
|
55
55
|
|
|
56
|
-
GET_ATTRS_MAP2 =
|
|
56
|
+
GET_ATTRS_MAP2 = '\\s(disabled|readonly|checked|selected|multiple)'
|
|
57
57
|
|
|
58
58
|
@@pattern_selected_m = Regexp.new(SELECTED_M)
|
|
59
59
|
@@pattern_selected_r = Regexp.new(SELECTED_R)
|
|
@@ -119,6 +119,8 @@ module Meteor
|
|
|
119
119
|
analyze_ml
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
+
protected :parse
|
|
123
|
+
|
|
122
124
|
#
|
|
123
125
|
# analyze document (ドキュメントをパースする)
|
|
124
126
|
#
|
|
@@ -145,21 +147,19 @@ module Meteor
|
|
|
145
147
|
def analyze_content_type
|
|
146
148
|
@error_check = false
|
|
147
149
|
|
|
148
|
-
element_3(
|
|
150
|
+
element_3('meta', 'http-equiv', 'Content-Type')
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
element_3("meta", "http-equiv", "Content-Type")
|
|
152
|
-
end
|
|
152
|
+
element_3('meta', 'http-equiv', 'Content-Type') unless @elm_
|
|
153
153
|
|
|
154
154
|
@error_check = true
|
|
155
155
|
|
|
156
156
|
if @elm_
|
|
157
|
-
content = @elm_.attr(
|
|
158
|
-
content_arr = content&.split(
|
|
159
|
-
@root.content_type = content_arr&.at(0) ||
|
|
160
|
-
@root.charset = content_arr&.at(1)&.split(
|
|
157
|
+
content = @elm_.attr('content')
|
|
158
|
+
content_arr = content&.split(';')
|
|
159
|
+
@root.content_type = content_arr&.at(0) || ''
|
|
160
|
+
@root.charset = content_arr&.at(1)&.split('=')&.at(1) || ''
|
|
161
161
|
else
|
|
162
|
-
@root.content_type =
|
|
162
|
+
@root.content_type = ''
|
|
163
163
|
end
|
|
164
164
|
end
|
|
165
165
|
|
|
@@ -169,7 +169,7 @@ module Meteor
|
|
|
169
169
|
# analuze document , set newline (ドキュメントをパースし、改行コードをセットする)
|
|
170
170
|
#
|
|
171
171
|
def analyze_newline
|
|
172
|
-
|
|
172
|
+
KAIGYO_CODE.each do |a|
|
|
173
173
|
if @root.document.include?(a)
|
|
174
174
|
@root.newline = a
|
|
175
175
|
# puts "kaigyo:" << @root.newline
|
|
@@ -190,16 +190,14 @@ module Meteor
|
|
|
190
190
|
# case of void element (空要素の場合(<->内容あり要素の場合))
|
|
191
191
|
if is_match(@@match_tag, name)
|
|
192
192
|
# void element search pattern (空要素検索用パターン)
|
|
193
|
-
@pattern_cc = String.new(
|
|
193
|
+
@pattern_cc = String.new('') << '<' << @_name << '(|\\s[^<>]*)>'
|
|
194
194
|
# @pattern_cc = "<#{@_name}(|\\s[^<>]*)>"
|
|
195
195
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
196
196
|
@res = @pattern.match(@root.document)
|
|
197
197
|
if @res
|
|
198
198
|
element_void_1(name)
|
|
199
199
|
else
|
|
200
|
-
if @error_check
|
|
201
|
-
puts(Meteor::Exception::NoSuchElementException.new(name).message)
|
|
202
|
-
end
|
|
200
|
+
puts(Meteor::Exception::NoSuchElementException.new(name).message) if @error_check
|
|
203
201
|
|
|
204
202
|
@elm_ = nil
|
|
205
203
|
end
|
|
@@ -217,9 +215,7 @@ module Meteor
|
|
|
217
215
|
@on_search = true
|
|
218
216
|
element_normal_1(name)
|
|
219
217
|
else
|
|
220
|
-
if @error_check
|
|
221
|
-
puts(Meteor::Exception::NoSuchElementException.new(name).message)
|
|
222
|
-
end
|
|
218
|
+
puts(Meteor::Exception::NoSuchElementException.new(name).message) if @error_check
|
|
223
219
|
|
|
224
220
|
@elm_ = nil
|
|
225
221
|
end
|
|
@@ -272,9 +268,7 @@ module Meteor
|
|
|
272
268
|
if @res
|
|
273
269
|
element_void_3(name)
|
|
274
270
|
else
|
|
275
|
-
if @error_check
|
|
276
|
-
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message)
|
|
277
|
-
end
|
|
271
|
+
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message) if @error_check
|
|
278
272
|
|
|
279
273
|
@elm_ = nil
|
|
280
274
|
end
|
|
@@ -289,16 +283,12 @@ module Meteor
|
|
|
289
283
|
# search of normal element (内容あり要素検索)
|
|
290
284
|
@res = @pattern.match(@root.document)
|
|
291
285
|
|
|
292
|
-
if !@res && !is_match(@@match_tag_nne, name)
|
|
293
|
-
@res = element_normal_3_2
|
|
294
|
-
end
|
|
286
|
+
@res = element_normal_3_2 if !@res && !is_match(@@match_tag_nne, name)
|
|
295
287
|
|
|
296
288
|
if @res
|
|
297
289
|
element_normal_3_1(name)
|
|
298
290
|
else
|
|
299
|
-
if @error_check
|
|
300
|
-
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message)
|
|
301
|
-
end
|
|
291
|
+
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message) if @error_check
|
|
302
292
|
|
|
303
293
|
@elm_ = nil
|
|
304
294
|
end
|
|
@@ -310,7 +300,7 @@ module Meteor
|
|
|
310
300
|
private :element_3
|
|
311
301
|
|
|
312
302
|
def element_void_3(name)
|
|
313
|
-
element_void_3_1(name, "
|
|
303
|
+
element_void_3_1(name, '"[^<>]*)>')
|
|
314
304
|
end
|
|
315
305
|
|
|
316
306
|
private :element_void_3
|
|
@@ -334,9 +324,7 @@ module Meteor
|
|
|
334
324
|
if @res
|
|
335
325
|
element_3(@res[1], attr_name, attr_value)
|
|
336
326
|
else
|
|
337
|
-
if @error_check
|
|
338
|
-
puts(Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message)
|
|
339
|
-
end
|
|
327
|
+
puts(Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message) if @error_check
|
|
340
328
|
|
|
341
329
|
@elm_ = nil
|
|
342
330
|
end
|
|
@@ -399,9 +387,7 @@ module Meteor
|
|
|
399
387
|
# search of normal element (内容あり要素検索)
|
|
400
388
|
@res = @pattern.match(@root.document)
|
|
401
389
|
|
|
402
|
-
if !@res && !is_match(@@match_tag_nne, tag)
|
|
403
|
-
@res = element_normal_5_2
|
|
404
|
-
end
|
|
390
|
+
@res = element_normal_5_2 if !@res && !is_match(@@match_tag_nne, tag)
|
|
405
391
|
|
|
406
392
|
if @res
|
|
407
393
|
element_normal_5_1(name)
|
|
@@ -424,7 +410,7 @@ module Meteor
|
|
|
424
410
|
private :element_5
|
|
425
411
|
|
|
426
412
|
def element_void_5(name)
|
|
427
|
-
element_void_5_1(name, "
|
|
413
|
+
element_void_5_1(name, '")[^<>]*)>')
|
|
428
414
|
end
|
|
429
415
|
|
|
430
416
|
private :element_void_5
|
|
@@ -470,16 +456,17 @@ module Meteor
|
|
|
470
456
|
private :element_4
|
|
471
457
|
|
|
472
458
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
473
|
-
if is_match(
|
|
459
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
474
460
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_selected_m, @@pattern_selected_r)
|
|
475
|
-
elsif is_match(
|
|
461
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
476
462
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_multiple_m, @@pattern_multiple_r)
|
|
477
|
-
elsif is_match(
|
|
463
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
478
464
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_disabled_m, @@pattern_disabled_r)
|
|
479
|
-
elsif is_match(
|
|
465
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
480
466
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_checked_m, @@pattern_checked_r)
|
|
481
|
-
elsif is_match(
|
|
482
|
-
|
|
467
|
+
elsif is_match('readonly', attr_name) &&
|
|
468
|
+
(is_match('textarea',
|
|
469
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
483
470
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_readonly_m, @@pattern_readonly_r)
|
|
484
471
|
else
|
|
485
472
|
super(elm, attr_name, attr_value)
|
|
@@ -489,43 +476,44 @@ module Meteor
|
|
|
489
476
|
private :edit_attrs_
|
|
490
477
|
|
|
491
478
|
def edit_attrs_5(elm, attr_name, attr_value, match_p, replace)
|
|
492
|
-
if true.equal?(attr_value) || is_match(
|
|
479
|
+
if true.equal?(attr_value) || is_match('true', attr_value)
|
|
493
480
|
@res = match_p.match(elm.attributes)
|
|
494
481
|
|
|
495
|
-
|
|
496
|
-
if elm.attributes !=
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
482
|
+
unless @res
|
|
483
|
+
elm.attributes = if elm.attributes != '' && elm.attributes.strip != ''
|
|
484
|
+
String.new('') << ' ' << elm.attributes.strip
|
|
485
|
+
else
|
|
486
|
+
String.new('')
|
|
487
|
+
end
|
|
501
488
|
|
|
502
|
-
elm.attributes <<
|
|
489
|
+
elm.attributes << ' ' << attr_name
|
|
503
490
|
# else
|
|
504
491
|
end
|
|
505
|
-
elsif false.equal?(attr_value) || is_match(
|
|
506
|
-
elm.attributes.sub!(replace,
|
|
492
|
+
elsif false.equal?(attr_value) || is_match('false', attr_value)
|
|
493
|
+
elm.attributes.sub!(replace, '')
|
|
507
494
|
end
|
|
508
495
|
end
|
|
509
496
|
|
|
510
497
|
private :edit_attrs_5
|
|
511
498
|
|
|
512
499
|
def edit_document_1(elm)
|
|
513
|
-
edit_document_2(elm,
|
|
500
|
+
edit_document_2(elm, '>')
|
|
514
501
|
end
|
|
515
502
|
|
|
516
503
|
private :edit_document_1
|
|
517
504
|
|
|
518
505
|
def get_attr_value_(elm, attr_name)
|
|
519
|
-
if is_match(
|
|
506
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
520
507
|
get_attr_value_r(elm, @@pattern_selected_m)
|
|
521
|
-
elsif is_match(
|
|
508
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
522
509
|
get_attr_value_r(elm, @@pattern_multiple_m)
|
|
523
|
-
elsif is_match(
|
|
510
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
524
511
|
get_attr_value_r(elm, @@pattern_disabled_m)
|
|
525
|
-
elsif is_match(
|
|
512
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
526
513
|
get_attr_value_r(elm, @@pattern_checked_m)
|
|
527
|
-
elsif is_match(
|
|
528
|
-
|
|
514
|
+
elsif is_match('readonly', attr_name) &&
|
|
515
|
+
(is_match('textarea',
|
|
516
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
529
517
|
get_attr_value_r(elm, @@pattern_readonly_m)
|
|
530
518
|
else
|
|
531
519
|
super(elm, attr_name)
|
|
@@ -535,11 +523,9 @@ module Meteor
|
|
|
535
523
|
private :get_attr_value_
|
|
536
524
|
|
|
537
525
|
def get_type(elm)
|
|
538
|
-
|
|
539
|
-
elm.type_value = get_attr_value_(elm,
|
|
540
|
-
|
|
541
|
-
elm.type_value = get_attr_value_(elm, "TYPE")
|
|
542
|
-
end
|
|
526
|
+
unless elm.type_value
|
|
527
|
+
elm.type_value = get_attr_value_(elm, 'type')
|
|
528
|
+
elm.type_value = get_attr_value_(elm, 'TYPE') unless elm.type_value
|
|
543
529
|
end
|
|
544
530
|
|
|
545
531
|
elm.type_value
|
|
@@ -551,9 +537,9 @@ module Meteor
|
|
|
551
537
|
@res = match_p.match(elm.attributes)
|
|
552
538
|
|
|
553
539
|
if @res
|
|
554
|
-
|
|
540
|
+
'true'
|
|
555
541
|
else
|
|
556
|
-
|
|
542
|
+
'false'
|
|
557
543
|
end
|
|
558
544
|
end
|
|
559
545
|
|
|
@@ -565,14 +551,14 @@ module Meteor
|
|
|
565
551
|
# @return [Hash] attribute map (属性マップ)
|
|
566
552
|
#
|
|
567
553
|
def get_attrs(elm)
|
|
568
|
-
attrs =
|
|
554
|
+
attrs = {}
|
|
569
555
|
|
|
570
556
|
elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
|
|
571
557
|
attrs.store(a, unescape(b))
|
|
572
558
|
end
|
|
573
559
|
|
|
574
560
|
elm.attributes.scan(@@pattern_get_attrs_map2) do |a|
|
|
575
|
-
attrs.store(a[0],
|
|
561
|
+
attrs.store(a[0], 'true')
|
|
576
562
|
end
|
|
577
563
|
|
|
578
564
|
attrs
|
|
@@ -593,7 +579,7 @@ module Meteor
|
|
|
593
579
|
end
|
|
594
580
|
|
|
595
581
|
elm.attributes.scan(@@pattern_get_attrs_map2) do |a|
|
|
596
|
-
attrs.store(a[0],
|
|
582
|
+
attrs.store(a[0], 'true')
|
|
597
583
|
end
|
|
598
584
|
|
|
599
585
|
attrs.recordable = true
|
|
@@ -604,16 +590,15 @@ module Meteor
|
|
|
604
590
|
private :get_attr_map
|
|
605
591
|
|
|
606
592
|
def remove_attrs_(elm, attr_name)
|
|
607
|
-
if !is_match(@@attr_bool, attr_name)
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
end
|
|
593
|
+
@pattern = if !is_match(@@attr_bool, attr_name)
|
|
594
|
+
# attribute search pattern (属性検索用パターン)
|
|
595
|
+
Meteor::Core::Util::PatternCache.get(String.new('') << attr_name << '="[^"]*"\\s?')
|
|
596
|
+
# @pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"\\s?")
|
|
597
|
+
else
|
|
598
|
+
# attribute search pattern (属性検索用パターン)
|
|
599
|
+
Meteor::Core::Util::PatternCache.get(attr_name)
|
|
600
|
+
end
|
|
601
|
+
elm.attributes.sub!(@pattern, '')
|
|
617
602
|
end
|
|
618
603
|
|
|
619
604
|
private :remove_attrs_
|
|
@@ -8,19 +8,19 @@ module Meteor
|
|
|
8
8
|
# XHTML parser (XHTMLパーサ)
|
|
9
9
|
#
|
|
10
10
|
class ParserImpl < Meteor::Ml::Xhtml4::ParserImpl
|
|
11
|
-
#[Array] boolean attributes (論理値で指定する属性)
|
|
12
|
-
ATTR_BOOL = [
|
|
11
|
+
# [Array] boolean attributes (論理値で指定する属性)
|
|
12
|
+
ATTR_BOOL = %w[disabled readonly checked selected multiple required].freeze
|
|
13
13
|
|
|
14
|
-
#[Array] elements with the disabled attribute (disabled属性のある要素)
|
|
15
|
-
DISABLE_ELEMENT = [
|
|
14
|
+
# [Array] elements with the disabled attribute (disabled属性のある要素)
|
|
15
|
+
DISABLE_ELEMENT = %w[input textarea select optgroup fieldset].freeze
|
|
16
16
|
|
|
17
|
-
#[Array] elements with a readonly attribute (required属性のある要素)
|
|
18
|
-
REQUIRE_ELEMENT = [
|
|
17
|
+
# [Array] elements with a readonly attribute (required属性のある要素)
|
|
18
|
+
REQUIRE_ELEMENT = %w[input textarea].freeze
|
|
19
19
|
|
|
20
|
-
REQUIRED_M =
|
|
21
|
-
REQUIRED_M1 =
|
|
22
|
-
REQUIRED_R =
|
|
23
|
-
REQUIRED_U =
|
|
20
|
+
REQUIRED_M = '\\srequired="[^"]*"\\s|\\srequired="[^"]*"$'
|
|
21
|
+
REQUIRED_M1 = '\\srequired="([^"]*)"\\s|\\srequired="([^"]*)"$'
|
|
22
|
+
REQUIRED_R = 'required="[^"]*"'
|
|
23
|
+
REQUIRED_U = 'required="required"'
|
|
24
24
|
|
|
25
25
|
@@pattern_required_m = Regexp.new(REQUIRED_M)
|
|
26
26
|
@@pattern_required_m1 = Regexp.new(REQUIRED_M1)
|
|
@@ -74,41 +74,38 @@ module Meteor
|
|
|
74
74
|
def analyze_content_type
|
|
75
75
|
@error_check = false
|
|
76
76
|
|
|
77
|
-
element_3(
|
|
77
|
+
element_3('meta', 'charset', '[a-zA-Z-]+', false)
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
element_3("meta", "charset", "[a-zA-Z-]+", false)
|
|
81
|
-
end
|
|
79
|
+
element_3('meta', 'charset', '[a-zA-Z-]+', false) unless @elm_
|
|
82
80
|
|
|
83
81
|
@error_check = true
|
|
84
82
|
|
|
85
83
|
if @elm_
|
|
86
|
-
@root.charset = @elm_.attr(
|
|
87
|
-
|
|
88
|
-
@root.charset = "utf-8"
|
|
89
|
-
end
|
|
84
|
+
@root.charset = @elm_.attr('charset')
|
|
85
|
+
@root.charset = 'utf-8' unless @root.charset
|
|
90
86
|
else
|
|
91
|
-
@root.charset =
|
|
87
|
+
@root.charset = 'utf-8'
|
|
92
88
|
end
|
|
93
89
|
|
|
94
|
-
@root.content_type =
|
|
90
|
+
@root.content_type = 'text/html'
|
|
95
91
|
end
|
|
96
92
|
|
|
97
93
|
private :analyze_content_type
|
|
98
94
|
|
|
99
95
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
100
|
-
if is_match(
|
|
96
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
101
97
|
edit_attrs_5(elm, attr_value, @@pattern_selected_m, @@pattern_selected_r, SELECTED_U)
|
|
102
|
-
elsif is_match(
|
|
98
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
103
99
|
edit_attrs_5(elm, attr_value, @@pattern_multiple_m, @@pattern_multiple_r, MULTIPLE_U)
|
|
104
|
-
elsif is_match(
|
|
100
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
105
101
|
edit_attrs_5(elm, attr_value, @@pattern_disabled_m, @@pattern_disabled_r, DISABLED_U)
|
|
106
|
-
elsif is_match(
|
|
102
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
107
103
|
edit_attrs_5(elm, attr_value, @@pattern_checked_m, @@pattern_checked_r, CHECKED_U)
|
|
108
|
-
elsif is_match(
|
|
109
|
-
|
|
104
|
+
elsif is_match('readonly', attr_name) &&
|
|
105
|
+
(is_match('textarea',
|
|
106
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
110
107
|
edit_attrs_5(elm, attr_value, @@pattern_readonly_m, @@pattern_readonly_r, READONLY_U)
|
|
111
|
-
elsif is_match(
|
|
108
|
+
elsif is_match('required', attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
|
|
112
109
|
edit_attrs_5(elm, attr_value, @@pattern_required_m, @@pattern_required_r, REQUIRED_U)
|
|
113
110
|
else
|
|
114
111
|
super(elm, attr_name, attr_value)
|
|
@@ -118,18 +115,19 @@ module Meteor
|
|
|
118
115
|
private :edit_attrs_
|
|
119
116
|
|
|
120
117
|
def get_attr_value_(elm, attr_name)
|
|
121
|
-
if is_match(
|
|
118
|
+
if is_match('selected', attr_name) && is_match('option', elm.name)
|
|
122
119
|
get_attr_value_r(elm, attr_name, @@pattern_selected_m1)
|
|
123
|
-
elsif is_match(
|
|
120
|
+
elsif is_match('multiple', attr_name) && is_match('select', elm.name)
|
|
124
121
|
get_attr_value_r(elm, attr_name, @@pattern_multiple_m1)
|
|
125
|
-
elsif is_match(
|
|
122
|
+
elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
|
|
126
123
|
get_attr_value_r(elm, attr_name, @@pattern_disabled_m1)
|
|
127
|
-
elsif is_match(
|
|
124
|
+
elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
|
|
128
125
|
get_attr_value_r(elm, attr_name, @@pattern_checked_m1)
|
|
129
|
-
elsif is_match(
|
|
130
|
-
|
|
126
|
+
elsif is_match('readonly', attr_name) &&
|
|
127
|
+
(is_match('textarea',
|
|
128
|
+
elm.name) || (is_match('input', elm.name) && is_match(READONLY_TYPE, get_type(elm))))
|
|
131
129
|
get_attr_value_r(elm, attr_name, @@pattern_readonly_m1)
|
|
132
|
-
elsif is_match(
|
|
130
|
+
elsif is_match('required', attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
|
|
133
131
|
get_attr_value_r(elm, attr_name, @@pattern_required_m1)
|
|
134
132
|
else
|
|
135
133
|
super(elm, attr_name)
|