meteor 0.9.29 → 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.
@@ -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 = Hash.new
11
+ @@regex_cache = {}
12
12
 
13
13
  ##
14
14
  ## intializer (イニシャライザ)
@@ -29,79 +29,45 @@ module Meteor
29
29
  def self.get(*args)
30
30
  case args.length
31
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
-
32
+ get_1(args[0])
39
33
  when TWO
40
- # get_2(args[0], args[1])
41
- if @@regex_cache[args[0].to_sym]
42
- @@regex_cache[args[0].to_sym]
43
- else
44
- @@regex_cache[args[0].to_sym] = Regexp.new(args[0], args[1])
45
- end
34
+ get_2(args[0], args[1])
46
35
  else
47
36
  raise ArgumentError
48
37
  end
49
38
  end
50
39
 
51
- ##
52
- ## get pattern (パターンを取得する)
53
- ## @param [String] regex regular expression (正規表現)
54
- ## @return [Regexp] pattern (パターン)
55
- ##
56
- # def self.get_1(regex)
57
- # ## pattern = @@regex_cache[regex]
58
- # ##
59
- # ## if pattern == nil
60
- # # if regex.kind_of?(String)
61
- # if !@@regex_cache[regex.to_sym]
62
- # # pattern = Regexp.new(regex)
63
- # # @@regex_cache[regex] = pattern
64
- # @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
65
- # end
66
40
  #
67
- # # return pattern
68
- # @@regex_cache[regex.to_sym]
69
- # ## elsif regex.kind_of?(Symbol)
70
- # ## if !@@regex_cache[regex]
71
- # ## @@regex_cache[regex.object_id] = Regexp.new(regex.to_s, Regexp::MULTILINE)
72
- # ## end
73
- # ##
74
- # ## @@regex_cache[regex]
75
- # # end
76
- # end
41
+ # get pattern (パターンを取得する)
42
+ # @param [String] regex regular expression (正規表現)
43
+ # @return [Regexp] pattern (パターン)
44
+ #
45
+ def self.get_1(regex)
46
+ if @@regex_cache[regex.to_sym]
47
+ @@regex_cache[regex.to_sym]
48
+ else
49
+ @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
50
+ end
51
+ end
77
52
 
78
- ##
79
- ## get pattern (パターンを取得する)
80
- ## @param [String] regex (正規表現)
81
- ## @param [Integer] option (オプション)
82
- ## @return [Regexp] psttern (パターン)
83
- ##
84
- # def self.get_2(regex, option)
85
- # ## pattern = @@regex_cache[regex]
86
- # ##
87
- # ## if pattern == nil
88
- # # if regex.kind_of?(String)
89
- # if !@@regex_cache[regex.to_sym]
90
- # # pattern = Regexp.new(regex)
91
- # # @@regex_cache[regex] = pattern
92
- # @@regex_cache[regex.to_sym] = Regexp.new(regex, option,"UTF-8")
93
- # end
94
53
  #
95
- # # return pattern
96
- # @@regex_cache[regex.to_sym]
97
- # ## elsif regex.kind_of?(Symbol)
98
- # ## if !@@regex_cache[regex]
99
- # ## @@regex_cache[regex] = Regexp.new(regex.to_s, option,"UTF-8")
100
- # ## end
101
- # ##
102
- # ## @@regex_cache[regex]
103
- # # end
104
- # end
54
+ # get pattern (パターンを取得する)
55
+ # @param [String] regex (正規表現)
56
+ # @param [Integer] option (オプション)
57
+ # @return [Regexp] psttern (パターン)
58
+ #
59
+ def self.get_2(regex, option)
60
+ if @@regex_cache[regex.to_sym]
61
+ @@regex_cache[regex.to_sym]
62
+ else
63
+ @@regex_cache[regex.to_sym] = Regexp.new(regex, option)
64
+ end
65
+ end
66
+
67
+ class << self
68
+ private :get_1
69
+ private :get_2
70
+ end
105
71
  end
106
72
  end
107
73
  end
@@ -37,27 +37,14 @@ module Meteor
37
37
  # @return [true,false] deletion flag (削除フラグ)
38
38
  #
39
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 :normal
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_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,9 +59,9 @@ module Meteor
72
59
  def initialize(*args)
73
60
  case args.length
74
61
  when Meteor::ONE
75
- if args[0].kind_of?(String)
62
+ if args[0].is_a?(String)
76
63
  initialize_s(args[0])
77
- elsif args[0].kind_of?(Meteor::Element)
64
+ elsif args[0].is_a?(Meteor::Element)
78
65
  initialize_e(args[0])
79
66
  else
80
67
  raise ArgumentError
@@ -120,7 +107,7 @@ module Meteor
120
107
 
121
108
  def initialize_2(elm, ps)
122
109
  @parser = ps
123
- if self.normal
110
+ if normal
124
111
  ps.element(elm)
125
112
  else
126
113
  @name = elm.name
@@ -162,19 +149,18 @@ module Meteor
162
149
  # @return [Meteor::Element] element (要素)
163
150
  #
164
151
  def clone_0
165
- obj = self.parser.element_cache[self.object_id]
152
+ obj = parser.element_cache[object_id]
166
153
  if obj
167
- obj.attributes = String.new(self.attributes)
168
- obj.mixed_content = String.new(self.mixed_content)
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(self.document)
157
+ obj.document = String.new(document)
171
158
  obj.usable = true
172
- obj
173
159
  else
174
160
  obj = self.class.new(self)
175
- self.parser.element_cache[self.object_id] = obj
176
- obj
161
+ parser.element_cache[object_id] = obj
177
162
  end
163
+ obj
178
164
  end
179
165
 
180
166
  private :clone_0
@@ -187,16 +173,15 @@ module Meteor
187
173
  def clone_1(ps)
188
174
  obj = ps.element_hook
189
175
  if obj
190
- obj.attributes = String.new(self.attributes)
191
- obj.mixed_content = String.new(self.mixed_content)
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(self.document)
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
187
  private :clone_1
@@ -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
- if @normal
227
- # @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
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
- if @normal
240
- # @pattern_cc = String.new('') << "<" << elm.name << elm.attributes << '>' << elm.mixed_content << '</' << elm.name << '>'
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
- alias_method :child, :element
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
- alias_method :css, :find
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
- alias_method :text, :content
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
- alias_method :text=, :content=
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
- alias_method :unsafe_text=, :unsafe_content=
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 != nil
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
- alias_method :flush, :flash
527
+ alias flush flash
547
528
 
548
529
  #
549
530
  # @overload execute(hook)
@@ -23,13 +23,13 @@ module Meteor
23
23
  end
24
24
 
25
25
  #
26
- #@overload add(type,relative_path,enc)
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
- #@overload add(type,relative_path)
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
- alias_method :link, :add
61
- alias_method :add_str, :add_template
62
- alias_method :link_str, :add_template
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
- alias_method :element, :get
75
+ alias element get
76
76
  end
77
77
  end
78
78
 
@@ -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 = ["br", "hr", "img", "input", "meta", "base", "embed", "command", "keygen"]
13
-
14
- #[Array] non-nestable elements (入れ子にできない要素)
15
- MATCH_TAG_NNE = [
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
- ]
34
-
35
- #[Array] boolean attributes (論理値で指定する属性)
36
- ATTR_BOOL = ["disabled", "readonly", "checked", "selected", "multiple", "required"]
37
-
38
- #[Array] elements with the disabled attribute (disabled属性のある要素)
39
- DISABLE_ELEMENT = ["input", "textarea", "select", "optgroup", "fieldset"]
40
-
41
- #[Array] elements with the required attribute (required属性のある要素)
42
- REQUIRE_ELEMENT = ["input", "textarea"]
43
-
44
- REQUIRED_M = "\\srequired\\s|\\srequired$|\\sREQUIRED\\s|\\sREQUIRED$"
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 = "required\\s|required$|REQUIRED\\s|REQUIRED$"
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)
@@ -98,41 +98,38 @@ module Meteor
98
98
  def analyze_content_type
99
99
  @error_check = false
100
100
 
101
- element_3("meta", "charset", "[a-zA-Z-]+", false)
101
+ element_3('meta', 'charset', '[a-zA-Z-]+', false)
102
102
 
103
- if !@elm_
104
- element_3("meta", "charset", "[a-zA-Z-]+", false)
105
- end
103
+ element_3('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("charset")
111
- if !@root.charset
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 = "utf-8"
111
+ @root.charset = 'utf-8'
116
112
  end
117
113
 
118
- @root.content_type = "text/html"
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("selected", attr_name) && is_match("option", elm.name)
120
+ if is_match('selected', attr_name) && is_match('option', elm.name)
125
121
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_selected_m, @@pattern_selected_r)
126
- elsif is_match("multiple", attr_name) && is_match("select", elm.name)
122
+ elsif is_match('multiple', attr_name) && is_match('select', elm.name)
127
123
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_multiple_m, @@pattern_multiple_r)
128
- elsif is_match("disabled", attr_name) && is_match(DISABLE_ELEMENT, elm.name)
124
+ elsif is_match('disabled', attr_name) && is_match(DISABLE_ELEMENT, elm.name)
129
125
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_disabled_m, @@pattern_disabled_r)
130
- elsif is_match("checked", attr_name) && is_match("input", elm.name) && is_match("radio", get_type(elm))
126
+ elsif is_match('checked', attr_name) && is_match('input', elm.name) && is_match('radio', get_type(elm))
131
127
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_checked_m, @@pattern_checked_r)
132
- elsif is_match("readonly", attr_name) &&
133
- (is_match("textarea", elm.name) || (is_match("input", elm.name) && is_match(READONLY_TYPE, get_type(elm))))
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))))
134
131
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_readonly_m, @@pattern_readonly_r)
135
- elsif is_match("required", attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
132
+ elsif is_match('required', attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
136
133
  edit_attrs_5(elm, attr_name, attr_value, @@pattern_required_m, @@pattern_required_r)
137
134
  else
138
135
  super(elm, attr_name, attr_value)
@@ -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("selected", attr_name) && is_match("option", elm.name)
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("multiple", attr_name) && is_match("select", elm.name)
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("disabled", attr_name) && is_match(DISABLE_ELEMENT, elm.name)
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("checked", attr_name) && is_match("input", elm.name) && is_match("radio", get_type(elm))
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("readonly", attr_name) &&
154
- (is_match("textarea", elm.name) || (is_match("input", elm.name) && is_match(READONLY_TYPE, get_type(elm))))
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("required", attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
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)