meteor 0.9.12 → 0.9.13
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 +5 -1
- data/Gemfile.lock +2 -2
- data/README.md +5 -3
- data/demo/html.rb +41 -38
- data/demo/html4.rb +53 -50
- data/demo/ml/sample_html.html +5 -4
- data/demo/ml/sample_html4.html +4 -4
- data/demo/ml/sample_xhtml.html +6 -5
- data/demo/ml/sample_xhtml4.html +3 -3
- data/demo/xhtml.rb +39 -36
- data/demo/xhtml4.rb +37 -34
- data/demo/xml.rb +63 -63
- data/lib/meteor/attribute.rb +33 -0
- data/lib/meteor/attribute_map.rb +146 -0
- data/lib/meteor/core/kernel.rb +2182 -0
- data/lib/meteor/core/util/pattern_cache.rb +107 -0
- data/lib/meteor/element.rb +532 -0
- data/lib/meteor/element_factory.rb +68 -0
- data/lib/meteor/exception/no_such_element_exception.rb +84 -0
- data/lib/meteor/ml/html/parser_impl.rb +142 -0
- data/lib/meteor/ml/html4/parser_impl.rb +684 -0
- data/lib/meteor/ml/xhtml/parser_impl.rb +139 -0
- data/lib/meteor/ml/xhtml4/parser_impl.rb +398 -0
- data/lib/meteor/ml/xml/parser_impl.rb +160 -0
- data/lib/meteor/parser.rb +15 -0
- data/lib/meteor/parser_factory.rb +493 -0
- data/lib/meteor/root_element.rb +24 -0
- data/lib/meteor.rb +20 -5593
- data/meteor.gemspec +3 -3
- metadata +21 -6
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# -* coding: UTF-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Meteor
|
|
5
|
+
module Core
|
|
6
|
+
module Util
|
|
7
|
+
#
|
|
8
|
+
# Pattern Cache Class (パターン・キャッシュ クラス)
|
|
9
|
+
#
|
|
10
|
+
class PatternCache
|
|
11
|
+
@@regex_cache = Hash.new
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
## intializer (イニシャライザ)
|
|
15
|
+
##
|
|
16
|
+
# def initialize
|
|
17
|
+
# end
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# get pattern (パターンを取得する)
|
|
21
|
+
# @overload get(regex)
|
|
22
|
+
# @param [String] regex regular expression (正規表現)
|
|
23
|
+
# @return [Regexp] pattern (パターン)
|
|
24
|
+
# @overload get(regex,option)
|
|
25
|
+
# @param [String] regex regular expression (正規表現)
|
|
26
|
+
# @param [Fixnum] option option of Regex (オプション)
|
|
27
|
+
# @return [Regexp] pattern (パターン)
|
|
28
|
+
#
|
|
29
|
+
def self.get(*args)
|
|
30
|
+
case args.length
|
|
31
|
+
when ONE
|
|
32
|
+
# get_1(args[0])
|
|
33
|
+
if @@regex_cache[args[0].to_sym]
|
|
34
|
+
@@regex_cache[args[0].to_sym]
|
|
35
|
+
else
|
|
36
|
+
@@regex_cache[args[0].to_sym] = Regexp.new(args[0], Regexp::MULTILINE)
|
|
37
|
+
end
|
|
38
|
+
when TWO
|
|
39
|
+
# get_2(args[0], args[1])
|
|
40
|
+
if @@regex_cache[args[0].to_sym]
|
|
41
|
+
@@regex_cache[args[0].to_sym]
|
|
42
|
+
else
|
|
43
|
+
@@regex_cache[args[0].to_sym] = Regexp.new(args[0], args[1])
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
raise ArgumentError
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
## get pattern (パターンを取得する)
|
|
52
|
+
## @param [String] regex regular expression (正規表現)
|
|
53
|
+
## @return [Regexp] pattern (パターン)
|
|
54
|
+
##
|
|
55
|
+
# def self.get_1(regex)
|
|
56
|
+
# ## pattern = @@regex_cache[regex]
|
|
57
|
+
# ##
|
|
58
|
+
# ## if pattern == nil
|
|
59
|
+
# # if regex.kind_of?(String)
|
|
60
|
+
# if !@@regex_cache[regex.to_sym]
|
|
61
|
+
# # pattern = Regexp.new(regex)
|
|
62
|
+
# # @@regex_cache[regex] = pattern
|
|
63
|
+
# @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
|
|
64
|
+
# end
|
|
65
|
+
#
|
|
66
|
+
# # return pattern
|
|
67
|
+
# @@regex_cache[regex.to_sym]
|
|
68
|
+
# ## elsif regex.kind_of?(Symbol)
|
|
69
|
+
# ## if !@@regex_cache[regex]
|
|
70
|
+
# ## @@regex_cache[regex.object_id] = Regexp.new(regex.to_s, Regexp::MULTILINE)
|
|
71
|
+
# ## end
|
|
72
|
+
# ##
|
|
73
|
+
# ## @@regex_cache[regex]
|
|
74
|
+
# # end
|
|
75
|
+
# end
|
|
76
|
+
|
|
77
|
+
##
|
|
78
|
+
## パターンを取得する
|
|
79
|
+
## @param [String] regex 正規表現
|
|
80
|
+
## @param [Fixnum] option オプション
|
|
81
|
+
## @return [Regexp] パターン
|
|
82
|
+
##
|
|
83
|
+
# def self.get_2(regex, option)
|
|
84
|
+
# ## pattern = @@regex_cache[regex]
|
|
85
|
+
# ##
|
|
86
|
+
# ## if pattern == nil
|
|
87
|
+
# # if regex.kind_of?(String)
|
|
88
|
+
# if !@@regex_cache[regex.to_sym]
|
|
89
|
+
# # pattern = Regexp.new(regex)
|
|
90
|
+
# # @@regex_cache[regex] = pattern
|
|
91
|
+
# @@regex_cache[regex.to_sym] = Regexp.new(regex, option,"UTF-8")
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
# # return pattern
|
|
95
|
+
# @@regex_cache[regex.to_sym]
|
|
96
|
+
# ## elsif regex.kind_of?(Symbol)
|
|
97
|
+
# ## if !@@regex_cache[regex]
|
|
98
|
+
# ## @@regex_cache[regex] = Regexp.new(regex.to_s, option,"UTF-8")
|
|
99
|
+
# ## end
|
|
100
|
+
# ##
|
|
101
|
+
# ## @@regex_cache[regex]
|
|
102
|
+
# # end
|
|
103
|
+
# end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
# -* coding: UTF-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Meteor
|
|
5
|
+
#
|
|
6
|
+
# Element Class (要素クラス)
|
|
7
|
+
#
|
|
8
|
+
# @!attribute [rw] name
|
|
9
|
+
# @return [String] tag name (要素名)
|
|
10
|
+
# @!attribute [rw] attributes
|
|
11
|
+
# @return [String] attributes (属性群)
|
|
12
|
+
# @!attribute [rw] mixed_content
|
|
13
|
+
# @return [String] content (内容)
|
|
14
|
+
# @!attribute [rw] raw_content
|
|
15
|
+
# @return [false,true] entity ref flag of content (内容のエンティティ参照フラグ)
|
|
16
|
+
# @!attribute [rw] pattern
|
|
17
|
+
# @return [String] pattern (パターン)
|
|
18
|
+
# @!attribute [rw] document_sync
|
|
19
|
+
# @return [true,false] document update flag (ドキュメント更新フラグ)
|
|
20
|
+
# @!attribute [rw] empty
|
|
21
|
+
# @return [true,false] content empty flag (内容存在フラグ)
|
|
22
|
+
# @!attribute [rw] cx
|
|
23
|
+
# @return [true,false] comment extension tag flag (コメント拡張タグフラグ)
|
|
24
|
+
# @!attribute [rw] mono
|
|
25
|
+
# @return [true,false] child element existance flag (子要素存在フラグ)
|
|
26
|
+
# @!attribute [rw] parser
|
|
27
|
+
# @return [Meteor::Parser] parser(パーサ)
|
|
28
|
+
# @!attribute [rw] type_value
|
|
29
|
+
# @return [String] type (タイプ属性)
|
|
30
|
+
# @!attribute [rw] usable
|
|
31
|
+
# @return [true,false] usable flag (有効・無効フラグ)
|
|
32
|
+
# @!attribute [rw] origin
|
|
33
|
+
# @return [Meteor::Element] original pointer (原本ポインタ)
|
|
34
|
+
# @!attribute [rw] copy
|
|
35
|
+
# @return [Meteor::Element] copy pointer (複製ポインタ)
|
|
36
|
+
# @!attribute [rw] removed
|
|
37
|
+
# @return [true,false] deletion flag (削除フラグ)
|
|
38
|
+
#
|
|
39
|
+
class Element
|
|
40
|
+
attr_accessor :name
|
|
41
|
+
attr_accessor :attributes
|
|
42
|
+
attr_accessor :mixed_content
|
|
43
|
+
attr_accessor :raw_content
|
|
44
|
+
attr_accessor :pattern
|
|
45
|
+
attr_accessor :document_sync
|
|
46
|
+
attr_accessor :empty
|
|
47
|
+
attr_accessor :cx
|
|
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 :tag :name
|
|
57
|
+
alias :tag= :name=
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# initializer (イニシャライザ)
|
|
61
|
+
# @overload initialize(name)
|
|
62
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
63
|
+
# @overload initialize(elm)
|
|
64
|
+
# @param [Meteor::Element] elm element (要素)
|
|
65
|
+
# @overload initialize(elm,ps)
|
|
66
|
+
# @param [Meteor::Element] elm element (要素)
|
|
67
|
+
# @param [Meteor::Parser] ps parser (パーサ)
|
|
68
|
+
#
|
|
69
|
+
def initialize(*args)
|
|
70
|
+
case args.length
|
|
71
|
+
when Meteor::ONE
|
|
72
|
+
if args[0].kind_of?(String)
|
|
73
|
+
initialize_s(args[0])
|
|
74
|
+
elsif args[0].kind_of?(Meteor::Element)
|
|
75
|
+
initialize_e(args[0])
|
|
76
|
+
else
|
|
77
|
+
raise ArgumentError
|
|
78
|
+
end
|
|
79
|
+
when Meteor::TWO
|
|
80
|
+
@name = args[0].name
|
|
81
|
+
@attributes = String.new(args[0].attributes)
|
|
82
|
+
@mixed_content = String.new(args[0].mixed_content)
|
|
83
|
+
# @pattern = String.new(args[0].pattern)
|
|
84
|
+
@pattern = args[0].pattern
|
|
85
|
+
@document = String.new(args[0].document)
|
|
86
|
+
@empty = args[0].empty
|
|
87
|
+
@cx = args[0].cx
|
|
88
|
+
@mono = args[0].mono
|
|
89
|
+
@parser = args[1]
|
|
90
|
+
# @usable = false
|
|
91
|
+
@origin = args[0]
|
|
92
|
+
args[0].copy = self
|
|
93
|
+
when Meteor::ZERO
|
|
94
|
+
else
|
|
95
|
+
raise ArgumentError
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
#
|
|
100
|
+
# initializer (イニシャライザ)
|
|
101
|
+
# @param [String] name tag name (タグ名)
|
|
102
|
+
#
|
|
103
|
+
def initialize_s(name)
|
|
104
|
+
@name = name
|
|
105
|
+
# @attributes = nil
|
|
106
|
+
# @mixed_content = nil
|
|
107
|
+
# @pattern = nil
|
|
108
|
+
# @document = nil
|
|
109
|
+
# @parser=nil
|
|
110
|
+
# @empty = false
|
|
111
|
+
# @cx = false
|
|
112
|
+
# @mono = false
|
|
113
|
+
# @parent = false
|
|
114
|
+
@usable = true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private :initialize_s
|
|
118
|
+
|
|
119
|
+
#
|
|
120
|
+
# initializer (イニシャライザ)
|
|
121
|
+
# @param [Meteor::Element] elm element (要素)
|
|
122
|
+
#
|
|
123
|
+
def initialize_e(elm)
|
|
124
|
+
@name = elm.name
|
|
125
|
+
@attributes = String.new(elm.attributes)
|
|
126
|
+
# @pattern = String.new(elm.pattern)
|
|
127
|
+
@pattern = elm.pattern
|
|
128
|
+
@document = String.new(elm.document)
|
|
129
|
+
@empty = elm.empty
|
|
130
|
+
@cx = elm.cx
|
|
131
|
+
@mono = elm.mono
|
|
132
|
+
@origin = elm
|
|
133
|
+
@parser = elm.parser
|
|
134
|
+
@usable = true
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
private :initialize_e
|
|
138
|
+
|
|
139
|
+
#
|
|
140
|
+
# make copy (コピーを作成する)
|
|
141
|
+
# @overload new!(elm,ps)
|
|
142
|
+
# @param [Meteor::Element] elm element (要素)
|
|
143
|
+
# @param [Meteor::Parser] ps parser (パーサ)
|
|
144
|
+
# @return [Meteor::Element] element (要素)
|
|
145
|
+
#
|
|
146
|
+
def self.new!(*args)
|
|
147
|
+
case args.length
|
|
148
|
+
when Meteor::TWO
|
|
149
|
+
@obj = args[1].element_hook
|
|
150
|
+
if @obj
|
|
151
|
+
@obj.attributes = String.new(args[0].attributes)
|
|
152
|
+
@obj.mixed_content = String.new(args[0].mixed_content)
|
|
153
|
+
# @obj.pattern = String.new(args[0].pattern)
|
|
154
|
+
@obj.document = String.new(args[0].document)
|
|
155
|
+
@obj
|
|
156
|
+
else
|
|
157
|
+
@obj = self.new(args[0], args[1])
|
|
158
|
+
args[1].element_hook = @obj
|
|
159
|
+
@obj
|
|
160
|
+
end
|
|
161
|
+
else
|
|
162
|
+
raise ArgumentError
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
#
|
|
167
|
+
# clone (複製する)
|
|
168
|
+
# @return [Meteor::Element] element (要素)
|
|
169
|
+
#
|
|
170
|
+
def clone
|
|
171
|
+
obj = self.parser.element_cache[self.object_id]
|
|
172
|
+
if obj
|
|
173
|
+
obj.attributes = String.new(self.attributes)
|
|
174
|
+
obj.mixed_content = String.new(self.mixed_content)
|
|
175
|
+
# obj.pattern = String.new(self.pattern)
|
|
176
|
+
obj.document = String.new(self.document)
|
|
177
|
+
obj.usable = true
|
|
178
|
+
obj
|
|
179
|
+
else
|
|
180
|
+
obj = self.new(self)
|
|
181
|
+
self.parser.element_cache[self.object_id] = obj
|
|
182
|
+
obj
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
#
|
|
187
|
+
# set document (ドキュメントをセットする)
|
|
188
|
+
# @param [String] doc document (ドキュメント)
|
|
189
|
+
#
|
|
190
|
+
def document=(doc)
|
|
191
|
+
@document_sync = false
|
|
192
|
+
@document = doc
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
#
|
|
196
|
+
# get document (ドキュメントを取得する)
|
|
197
|
+
# @return [String] document (ドキュメント)
|
|
198
|
+
#
|
|
199
|
+
def document
|
|
200
|
+
if @document_sync
|
|
201
|
+
@document_sync = false
|
|
202
|
+
case @parser.doc_type
|
|
203
|
+
when Parser::HTML, Parser::HTML4
|
|
204
|
+
if @cx
|
|
205
|
+
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->' << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
206
|
+
@document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
207
|
+
else
|
|
208
|
+
if @empty
|
|
209
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
|
|
210
|
+
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
211
|
+
else
|
|
212
|
+
@document = String.new('') << "<" << @name << @attributes << '>'
|
|
213
|
+
# @document = "<#{@name}#{@attributes}>"
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
when Parser::XHTML, Parser::XHTML4, Parser::XML
|
|
217
|
+
if @cx
|
|
218
|
+
# @pattern_cc = String.new('') << '<!-- @' << elm.name << ' ' << elm.attributes << '-->' << elm.mixed_content << '<!-- /@' << elm.name << ' -->'
|
|
219
|
+
@document = "<!-- @#{@name} #{@attributes} -->#{@mixed_content}<!-- /@#{@name} -->"
|
|
220
|
+
else
|
|
221
|
+
if @empty
|
|
222
|
+
# @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
|
|
223
|
+
@document = "<#{@name}#{@attributes}>#{@mixed_content}</#{@name}>"
|
|
224
|
+
else
|
|
225
|
+
@document = String.new('') << "<" << @name << @attributes << '/>'
|
|
226
|
+
# @document = "<#{@name}#{@attributes}/>"
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
else
|
|
231
|
+
@document
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
#
|
|
236
|
+
# get element (要素を取得する)
|
|
237
|
+
# @overload element()
|
|
238
|
+
# get element (要素を取得する)
|
|
239
|
+
# @return [Meteor::Element] element (要素)
|
|
240
|
+
# @overload element(name)
|
|
241
|
+
# get element using tag name (要素のタグ名で要素を取得する)
|
|
242
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
243
|
+
# @return [Meteor::Element] element (要素)
|
|
244
|
+
# @overload element(name,attrs)
|
|
245
|
+
# get element using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
|
246
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
247
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
|
|
248
|
+
# @return [Meteor::Element] element (要素)
|
|
249
|
+
# @overload element(attrs)
|
|
250
|
+
# get element using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
|
251
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
|
|
252
|
+
# @return [Meteor::Element] element(要素)
|
|
253
|
+
# @overload element(name,attr_name,attr_value)
|
|
254
|
+
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
|
255
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
256
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
257
|
+
# @param [String] attr_value attribute value (属性値)
|
|
258
|
+
# @return [Meteor::Element] element (要素)
|
|
259
|
+
# @overload element(attr_name,attr_value)
|
|
260
|
+
# get element using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
|
|
261
|
+
# @param [String,Symbol] attr_name 属性名
|
|
262
|
+
# @param [String] attr_value 属性値
|
|
263
|
+
# @return [Meteor::Element] element (要素)
|
|
264
|
+
# @overload element(name,attr_name1,attr_value1,attr_name2,attr_value2)
|
|
265
|
+
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
|
266
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
267
|
+
# @param [String,Symbol] attr_name1 attribute name1 (属性名1)
|
|
268
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
|
269
|
+
# @param [String,Symbol] attr_name2 attribute name2 (属性名2)
|
|
270
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
|
271
|
+
# @return [Meteor::Element] element (要素)
|
|
272
|
+
# @overload element(attr_name1,attr_value1,attr_name2,attr_value2)
|
|
273
|
+
# get element using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
|
|
274
|
+
# @param [String,Symbol] attr_name1 属性名1
|
|
275
|
+
# @param [String] attr_value1 属性値1
|
|
276
|
+
# @param [String,Symbol] attr_name2 属性名2
|
|
277
|
+
# @param [String] attr_value2 属性値2
|
|
278
|
+
# @return [Meteor::Element] element(要素)
|
|
279
|
+
# @overload element(elm)
|
|
280
|
+
# mirror element (要素を射影する)
|
|
281
|
+
# @param [Meteor::Element] elm element(要素)
|
|
282
|
+
# @return [Meteor::Element] element(要素)
|
|
283
|
+
#
|
|
284
|
+
def element(elm = nil, attrs = nil,*args)
|
|
285
|
+
# case args.length
|
|
286
|
+
# when ZERO
|
|
287
|
+
if !elm && !attrs
|
|
288
|
+
@parser.element(self)
|
|
289
|
+
else
|
|
290
|
+
@parser.element(elm, attrs, *args)
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
alias :child :element
|
|
295
|
+
|
|
296
|
+
#
|
|
297
|
+
# get elements (要素を取得する)
|
|
298
|
+
# @overload elements(name)
|
|
299
|
+
# get elements using tag name (要素のタグ名で要素を取得する)
|
|
300
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
301
|
+
# @return [Array<Meteor::Element>] element array(要素配列)
|
|
302
|
+
# @overload elements(name,attrs)
|
|
303
|
+
# get elements using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
|
304
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
305
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
|
|
306
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
307
|
+
# @overload elements(attrs)
|
|
308
|
+
# get elements using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
|
309
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
|
|
310
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
311
|
+
# @overload elements(name,attr_name,attr_value)
|
|
312
|
+
# get elements using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
|
313
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
314
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
315
|
+
# @param [String] attr_value attribute value (属性値)
|
|
316
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
317
|
+
# @overload elements(attr_name,attr_value)
|
|
318
|
+
# get elements using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
|
|
319
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
320
|
+
# @param [String] attr_value attribute value (属性値)
|
|
321
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
322
|
+
# @overload elements(name,attr_name1,attr_value1,attr_name2,attr_value2)
|
|
323
|
+
# get elements using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
|
324
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
325
|
+
# @param [String,Symbol] attr_name1 attribute name1 (属性名1)
|
|
326
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
|
327
|
+
# @param [String,Symbol] attr_name2 attribute name2 (属性名2)
|
|
328
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
|
329
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
330
|
+
# @overload elements(attr_name1,attr_value1,attr_name2,attr_value2)
|
|
331
|
+
# get elements using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
|
|
332
|
+
# @param [String,Symbol] attr_name1 attribute name1 (属性名1)
|
|
333
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
|
334
|
+
# @param [String,Symbol] attr_name2 attribute name2 (属性名2)
|
|
335
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
|
336
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
337
|
+
#
|
|
338
|
+
def elements(*args)
|
|
339
|
+
@parser.elements(*args)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
#
|
|
343
|
+
# get (child) elements using selector like css3(CSS3のようにセレクタを用いて(子)要素を取得する)
|
|
344
|
+
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
|
345
|
+
# @param selector [String] selector (セレクタ)
|
|
346
|
+
# @return [Array<Meteor::Element>] element (要素)
|
|
347
|
+
#
|
|
348
|
+
def find(selector)
|
|
349
|
+
@parser.find(selector)
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
alias :css :find
|
|
353
|
+
|
|
354
|
+
#
|
|
355
|
+
# get cx(comment extension) tag (CX(コメント拡張)タグを取得する)
|
|
356
|
+
# @overload cxtag(name,id)
|
|
357
|
+
# get cx(comment extension) tag using tag name and id attribute (タグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
|
358
|
+
# @param [String,Symbol] name tag name (タグ名)
|
|
359
|
+
# @param [String] id id attribute value (ID属性値)
|
|
360
|
+
# @return [Meteor::Element] element(要素)
|
|
361
|
+
# @overload cxtag(id)
|
|
362
|
+
# get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
|
363
|
+
# @param [String] id id attribute value (ID属性値)
|
|
364
|
+
# @return [Meteor::Element] element (要素)
|
|
365
|
+
#
|
|
366
|
+
def cxtag(*args)
|
|
367
|
+
@parser.cxtag(*args)
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
#
|
|
371
|
+
# @overload attr(attr)
|
|
372
|
+
# set attribute of element (要素の属性をセットする)
|
|
373
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attr attribute (属性)
|
|
374
|
+
# @return [Meteor::Element] element (要素)
|
|
375
|
+
# @deprecated
|
|
376
|
+
# @overload attr(attr_name,attr_value)
|
|
377
|
+
# set attribute of element (要素の属性をセットする)
|
|
378
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
379
|
+
# @param [String,true,false] attr_value attribute value (属性値)
|
|
380
|
+
# @return [Meteor::Element] element (要素)
|
|
381
|
+
# @overload attr(attr_name)
|
|
382
|
+
# get attribute value of element (要素の属性値を取得する)
|
|
383
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
384
|
+
# @return [String] attribute value (属性値)
|
|
385
|
+
#
|
|
386
|
+
def attr(attrs,*args)
|
|
387
|
+
@parser.attr(self, attrs,*args)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
#
|
|
391
|
+
# set attribute of element (要素の属性をセットする)
|
|
392
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attr attribute (属性)
|
|
393
|
+
# @return [Meteor::Element] element (要素)
|
|
394
|
+
#
|
|
395
|
+
def attr=(attr)
|
|
396
|
+
@parser.attr(self,attr)
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
#
|
|
400
|
+
# set attribute map (要素マップをセットする)
|
|
401
|
+
# @param [Hash<String,String>,Hash<Symbol,String>] attrs attribute map (属性マップ)
|
|
402
|
+
# @return [Meteor::Element] element (要素)
|
|
403
|
+
def attrs=(attrs)
|
|
404
|
+
@parser.attrs(self, attrs)
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
#
|
|
408
|
+
# get attribute map (属性マップを取得する)
|
|
409
|
+
# @return [Hash<String,String>,Hash<Symbol,String>] attribute map (属性マップ)
|
|
410
|
+
#
|
|
411
|
+
def attrs
|
|
412
|
+
@parser.attrs(self)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
#
|
|
416
|
+
# @overload attr_map(attr_map)
|
|
417
|
+
# set attribute map (属性マップをセットする)
|
|
418
|
+
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
|
419
|
+
# @return [Meteor::Element] element (要素)
|
|
420
|
+
# @deprecated
|
|
421
|
+
# @overload attr_map()
|
|
422
|
+
# get attribute map (属性マップを取得する)
|
|
423
|
+
# @return [Meteor::AttributeMap] attribute map (属性マップ)
|
|
424
|
+
#
|
|
425
|
+
def attr_map(*args)
|
|
426
|
+
@parser.attr_map(self, *args)
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
#
|
|
430
|
+
# set attribute map (属性マップをセットする)
|
|
431
|
+
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
|
432
|
+
# @return [Meteor::Element] element (要素)
|
|
433
|
+
#
|
|
434
|
+
def attr_map=(attr_map)
|
|
435
|
+
@parser.attr_map(self, attr_map)
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
#
|
|
439
|
+
# @overload content(content,entity_ref=true)
|
|
440
|
+
# set content of element (要素の内容をセットする)
|
|
441
|
+
# @param [String] content content of element (要素の内容)
|
|
442
|
+
# @param [true,false] entity_ref entity reference flag (エンティティ参照フラグ)
|
|
443
|
+
# @return [Meteor::Element] element (要素)
|
|
444
|
+
# @deprecated
|
|
445
|
+
# @overload content(content)
|
|
446
|
+
# set content of element (要素の内容をセットする)
|
|
447
|
+
# @param [String] content content of element (要素の内容)
|
|
448
|
+
# @return [Meteor::Element] element (要素)
|
|
449
|
+
# @deprecated
|
|
450
|
+
# @overload content()
|
|
451
|
+
# get content of element (要素の内容を取得する)
|
|
452
|
+
# @return [String] content (内容)
|
|
453
|
+
#
|
|
454
|
+
def content(*args)
|
|
455
|
+
@parser.content(self, *args)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
alias :text :content
|
|
459
|
+
|
|
460
|
+
#
|
|
461
|
+
# set content of element (要素の内容をセットする)
|
|
462
|
+
# @param [String] value content (要素の内容)
|
|
463
|
+
# @return [Meteor::Element] element (要素)
|
|
464
|
+
#
|
|
465
|
+
def content=(value)
|
|
466
|
+
@parser.content(self, value)
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
alias :text= :content=
|
|
470
|
+
|
|
471
|
+
#
|
|
472
|
+
# set attribute (属性をセットする)
|
|
473
|
+
# @param [String,Symbol] name attribute name (属性の名前)
|
|
474
|
+
# @param [String] value attribute value (属性の値)
|
|
475
|
+
# @return [Meteor::Element] element (要素)
|
|
476
|
+
#
|
|
477
|
+
def []=(name, value)
|
|
478
|
+
if value != nil
|
|
479
|
+
@parser.attr(self, name, value)
|
|
480
|
+
else
|
|
481
|
+
@parser.remove_attr(self, name)
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
#
|
|
486
|
+
# get attribute value (属性の値を取得する)
|
|
487
|
+
# @param [String,Symbol] name attribute name (属性の名前)
|
|
488
|
+
# @return [String] attribute value (属性の値)
|
|
489
|
+
#
|
|
490
|
+
def [](name)
|
|
491
|
+
@parser.attr(self, name)
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
#
|
|
495
|
+
# remove attribute of element (要素の属性を消す)
|
|
496
|
+
# @param [String,Symbol] attr_name attribute name (属性名)
|
|
497
|
+
# @return [Meteor::Element] element (要素)
|
|
498
|
+
#
|
|
499
|
+
def remove_attr(attr_name)
|
|
500
|
+
@parser.remove_attr(self, attr_name)
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
#
|
|
504
|
+
# remove element (要素を削除する)
|
|
505
|
+
#
|
|
506
|
+
def remove
|
|
507
|
+
@parser.remove_element(self)
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
#
|
|
511
|
+
# reflect (反映する)
|
|
512
|
+
#
|
|
513
|
+
def flash
|
|
514
|
+
@parser.flash
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
alias :flush :flash
|
|
518
|
+
|
|
519
|
+
#
|
|
520
|
+
# @overload execute(hook)
|
|
521
|
+
# run action of Hooker (Hookerクラスの処理を実行する)
|
|
522
|
+
# @param [Meteor::Hook::Hooker] hook Hooker object (Hookerオブジェクト)
|
|
523
|
+
# @overload execute(loop,list)
|
|
524
|
+
# run action of Looper (Looperクラスの処理を実行する)
|
|
525
|
+
# @param [Meteor::Hook::Looper] loop Looper object (Looperオブジェクト)
|
|
526
|
+
# @param [Array] list 配列
|
|
527
|
+
#
|
|
528
|
+
def execute(*args)
|
|
529
|
+
@parser.execute(self, *args)
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# -* coding: UTF-8 -*-
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Meteor
|
|
5
|
+
#
|
|
6
|
+
# Element Factory Class (要素ファクトリ クラス)
|
|
7
|
+
#
|
|
8
|
+
class ElementFactory
|
|
9
|
+
@@pf = Meteor::ParserFactory.new
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# set options (オプションをセットする)
|
|
13
|
+
# @param [Hash] opts option (オプション)
|
|
14
|
+
# @option opts [String] :root root directory (基準ディレクトリ)
|
|
15
|
+
# @option @deprecated opts [String] :base_dir root directory (基準ディレクトリ)
|
|
16
|
+
# @option opts [String] :enc default character encoding (デフォルト文字エンコーディング)
|
|
17
|
+
# @option @deprecated opts [String] :base_enc default character encoding (デフォルト文字エンコーディング)
|
|
18
|
+
# @option opts [FixNum,Symbol] :type default type of parser (デフォルトのパーサ・タイプ)
|
|
19
|
+
# @option @deprecated opts [FixNum | Symbol] :base_type default type of parser (デフォルトのパーサ・タイプ)
|
|
20
|
+
#
|
|
21
|
+
def self.options=(opts)
|
|
22
|
+
@@pf.options = opts
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
#@overload link(type,relative_path,enc)
|
|
27
|
+
# generate parser (パーサを作成する)
|
|
28
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
|
29
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
|
30
|
+
# @param [String] enc character encoding (エンコーディング)
|
|
31
|
+
# @return [Meteor::Parser] parser (パーサ)
|
|
32
|
+
#@overload link(type,relative_path)
|
|
33
|
+
# generate parser (パーサを作成する)
|
|
34
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
|
35
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
|
36
|
+
# @return [Meteor::Parser] parser (パーサ)
|
|
37
|
+
#
|
|
38
|
+
def self.link(*args)
|
|
39
|
+
@@pf.link(*args)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# @overload link_str(type, relative_url, doc)
|
|
44
|
+
# generate parser (パーサを作成する)
|
|
45
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
|
46
|
+
# @param [String] relative_url relative URL (相対URL)
|
|
47
|
+
# @param [String] doc document (ドキュメント)
|
|
48
|
+
# @return [Meteor::Parser] parser (パーサ)
|
|
49
|
+
# @overload link_str(relative_url, doc)
|
|
50
|
+
# generate parser (パーサを作成する)
|
|
51
|
+
# @param [String] relative_url relative URL (相対URL)
|
|
52
|
+
# @param [String] doc document (ドキュメント)
|
|
53
|
+
# @return [Meteor::Parser] parser (パーサ)
|
|
54
|
+
#
|
|
55
|
+
def self.link_str(*args)
|
|
56
|
+
@@pf.link_str(args)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# get root element (ルート要素を取得する)
|
|
61
|
+
# @param [String,Symbol] key identifier (キー)
|
|
62
|
+
# @return [Meteor::RootElement] root element (ルート要素)
|
|
63
|
+
#
|
|
64
|
+
def self.element(key)
|
|
65
|
+
@@pf.element(key)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|