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.
@@ -0,0 +1,15 @@
1
+ # -* coding: UTF-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ module Meteor
5
+ #
6
+ # Parser Class (パーサ共通クラス)
7
+ #
8
+ class Parser
9
+ HTML = 0
10
+ XHTML = 1
11
+ HTML4 = 2
12
+ XHTML4 = 3
13
+ XML = 4
14
+ end
15
+ end
@@ -0,0 +1,493 @@
1
+ # -* coding: UTF-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ module Meteor
5
+ #
6
+ # Parser Factory Class (パーサ・ファクトリ クラス)
7
+ #
8
+ # @!attribute [rw] type
9
+ # @return [FixNum,Symbol] default type of parser (デフォルトのパーサ・タイプ)
10
+ # @!attribute [rw] root
11
+ # @return [String] root root directory (基準ディレクトリ)
12
+ # @!attribute [rw] enc
13
+ # @return [String] default character encoding (デフォルトエンコーディング)
14
+ #
15
+ class ParserFactory
16
+ attr_accessor :type
17
+ attr_accessor :root
18
+ attr_accessor :enc
19
+
20
+ alias_method :base_type, :type
21
+ alias_method :base_type=, :type=
22
+ alias_method :base_dir, :root
23
+ alias_method :base_dir=, :root=
24
+ alias_method :base_enc, :enc
25
+ alias_method :base_enc=, :enc=
26
+
27
+ alias_method :base_encoding, :enc
28
+ alias_method :base_encoding=, :enc=
29
+
30
+ #
31
+ # initializer (イニシャライザ)
32
+ # @overload initialize()
33
+ # @overload initialize(root)
34
+ # @param [String] root root directory (基準ディレクトリ)
35
+ # @overload initialize(root, enc)
36
+ # @param [String] root root directory (基準ディレクトリ)
37
+ # @param [String] enc default character encoding (デフォルトエンコーディング)
38
+ # @overload initialize(type, root, enc)
39
+ # @param [FixNum,Symbol] type default type of parser (デフォルトのパーサ・タイプ)
40
+ # @param [String] root root directory (基準ディレクトリ)
41
+ # @param [String] enc default character encoding (デフォルト文字エンコーディング)
42
+ #
43
+ def initialize(*args)
44
+ case args.length
45
+ when 0
46
+ initialize_0
47
+ when 1
48
+ initialize_1(args[0])
49
+ when 2
50
+ initialize_2(args[0], args[1])
51
+ when 3
52
+ initialize_3(args[0],args[1],args[2])
53
+ else
54
+ raise ArgumentError
55
+ end
56
+ end
57
+
58
+ #
59
+ # initializer (イニシャライザ)
60
+ #
61
+ def initialize_0
62
+ @cache = Hash.new
63
+ @root = "."
64
+ @enc = "UTF-8"
65
+ end
66
+
67
+ private :initialize_0
68
+
69
+ #
70
+ # イニシャライザ
71
+ # @param [String] root root directory (基準ディレクトリ)
72
+ #
73
+ def initialize_1(root)
74
+ @cache = Hash.new
75
+ @root = root
76
+ @enc = "UTF-8"
77
+ end
78
+
79
+ private :initialize_1
80
+
81
+ #
82
+ # イニシャライザ
83
+ # @param [String] root root directory (基準ディレクトリ)
84
+ # @param [String] enc default character encoding (デフォルト文字エンコーディング)
85
+ #
86
+ def initialize_2(root, enc)
87
+ @cache = Hash.new
88
+ @root = root
89
+ @enc = enc
90
+ end
91
+
92
+ private :initialize_2
93
+
94
+ #
95
+ # イニシャライザ
96
+ # @param [FixNum,Symbol] type default type of parser (デフォルトのパーサ・タイプ)
97
+ # @param [String] root root directory (基準ディレクトリ)
98
+ # @param [String] enc default character encoding (デフォルト文字エンコーディング)
99
+ #
100
+ def initialize_3(type , root, enc)
101
+ @cache = Hash.new
102
+ @type = type
103
+ @root = root
104
+ @enc = enc
105
+ end
106
+
107
+ private :initialize_3
108
+
109
+ #
110
+ # set options (オプションをセットする)
111
+ # @param [Hash] opts option (オプション)
112
+ # @option opts [String] :root root directory (基準ディレクトリ)
113
+ # @option @deprecated opts [String] :base_dir root directory (基準ディレクトリ)
114
+ # @option opts [String] :enc default character encoding (デフォルト文字エンコーディング)
115
+ # @option @deprecated opts [String] :base_enc default character encoding (デフォルト文字エンコーディング)
116
+ # @option opts [FixNum,Symbol] :type default type of parser (デフォルトのパーサ・タイプ)
117
+ # @option @deprecated opts [FixNum | Symbol] :base_type default type of parser (デフォルトのパーサ・タイプ)
118
+ #
119
+ def options=(opts)
120
+ if opts.kind_of?(Hash)
121
+ if opts.include?(:root)
122
+ @root = opts[:root]
123
+ elsif opts.include?(:base_dir)
124
+ @root = opts[:base_dir]
125
+ end
126
+ if opts.include?(:enc)
127
+ @enc = opts[:enc]
128
+ elsif opts.include?(:base_enc)
129
+ @enc = opts[:base_enc]
130
+ end
131
+ if opts.include?(:type)
132
+ @type = opts[:type]
133
+ elsif opts.include?(:base_type)
134
+ @type = opts[:base_type]
135
+ end
136
+ else
137
+ raise ArgumentError
138
+ end
139
+ end
140
+
141
+ #
142
+ #@overload link(relative_path,enc)
143
+ # generate parser (パーサを作成する)
144
+ # @param [String] relative_path relative file path (相対ファイルパス)
145
+ # @param [String] enc character encoding (文字エンコーディング)
146
+ # @return [Meteor::Parser] parser (パーサ)
147
+ #@overload link(relative_path)
148
+ # generate parser (パーサを作成する)
149
+ # @param [String] relative_path relative file path (相対ファイルパス)
150
+ # @return [Meteor::Parser] parser (パーサ)
151
+ #@overload link(type,relative_path,enc)
152
+ # generate parser (パーサを作成する)
153
+ # @param [Fixnum,Symbol] type type of parser (パーサ・タイプ)
154
+ # @param [String] relative_path relative file path (相対ファイルパス)
155
+ # @param [String] enc character encoding (文字エンコーディング)
156
+ # @return [Meteor::Parser] parser (パーサ)
157
+ #@overload link(type,relative_path)
158
+ # generate parser (パーサを作成する)
159
+ # @param [Fixnum,Symbol] type type of parser (パーサ・タイプ)
160
+ # @param [String] relative_path relative file path (相対ファイルパス)
161
+ # @return [Meteor::Parser] parser (パーサ)
162
+ #
163
+ def link(*args)
164
+ case args.length
165
+ when 1
166
+ link_1(args[0])
167
+ when 2
168
+ if args[0].kind_of?(Fixnum) || args[0].kind_of?(Symbol)
169
+ link_2_n(args[0], args[1])
170
+ elsif args[0].kind_of?(String)
171
+ link_2_s(args[0], args[1])
172
+ else
173
+ raise ArgumentError
174
+ end
175
+ when 3
176
+ link_3(args[0], args[1], args[2])
177
+ else
178
+ raise ArgumentError
179
+ end
180
+ end
181
+
182
+ #
183
+ # change relative path to relative url (相対パスを相対URLにする)
184
+ # @param [String] path relative path (相対パス)
185
+ # @return [String] relative url (相対URL)
186
+ #
187
+ def path_to_url(path)
188
+ paths = File.split(path)
189
+
190
+ if paths.length == 1
191
+ return File.basename(paths[0], '.*')
192
+ else
193
+ if ".".eql?(paths[0])
194
+ paths.delete_at 0
195
+ paths[paths.length - 1] = File.basename(paths[paths.length - 1], '.*')
196
+ return String.new('') << "/" << paths.join("/")
197
+ else
198
+ paths[paths.length - 1] = File.basename(paths[paths.length - 1], '.*')
199
+ return String.new('') << "/" << paths.join("/")
200
+ end
201
+ end
202
+ end
203
+
204
+ private :path_to_url
205
+
206
+ #
207
+ # generate parser (パーサを作成する)
208
+ # @param [Fixnum,Symbol] type type of parser (パーサ・タイプ)
209
+ # @param [String] relative_path relative file path (相対ファイルパス)
210
+ # @param [String] enc character encoding (文字エンコーディング)
211
+ # @return [Meteor::Parser] parser(パーサ)
212
+ #
213
+ def link_3(type, relative_path, enc)
214
+
215
+ relative_url = path_to_url(relative_path)
216
+
217
+ case type
218
+ when Parser::HTML4, :html4
219
+ html4 = Meteor::Ml::Html4::ParserImpl.new
220
+ html.read(File.expand_path(relative_path, @root), enc)
221
+ @cache[relative_url] = html4
222
+ when Parser::XHTML4, :xhtml4
223
+ xhtml4 = Meteor::Ml::Xhtml4::ParserImpl.new
224
+ xhtml4.read(File.expand_path(relative_path, @root), enc)
225
+ @cache[relative_url] = xhtml4
226
+ when Parser::HTML, :html, :html5
227
+ html = Meteor::Ml::Html::ParserImpl.new
228
+ html.read(File.expand_path(relative_path, @root), enc)
229
+ @cache[relative_url] = html
230
+ when Parser::XHTML, :xhtml, :xhtml5
231
+ xhtml = Meteor::Ml::Xhtml::ParserImpl.new
232
+ xhtml.read(File.expand_path(relative_path, @root), enc)
233
+ @cache[relative_url] = xhtml
234
+ when Parser::XML, :xml
235
+ xml = Meteor::Ml::Xml::ParserImpl.new
236
+ xml.read(File.expand_path(relative_path, @root), enc)
237
+ @cache[relative_url] = xml
238
+ end
239
+ end
240
+
241
+ private :link_3
242
+
243
+ #
244
+ # generate parser (パーサを作成する)
245
+ # @param [Fixnum,Symbol] type type of parser(パーサ・タイプ)
246
+ # @param [String] relative_path relative file path (相対ファイルパス)
247
+ # @return [Meteor::Parser] parser (パーサ)
248
+ #
249
+ def link_2_n(type, relative_path)
250
+
251
+ relative_url = path_to_url(relative_path)
252
+
253
+ case type
254
+ when Parser::HTML4, :html4
255
+ ps = Meteor::Ml::Html4::ParserImpl.new
256
+ when Parser::XHTML4, :xhtml4
257
+ ps = Meteor::Ml::Xhtml4::ParserImpl.new
258
+ when Parser::HTML, :html, :html5
259
+ ps = Meteor::Ml::Html::ParserImpl.new
260
+ when Parser::XHTML, :xhtml, :xhtml5
261
+ ps = Meteor::Ml::Xhtml::ParserImpl.new
262
+ when Parser::XML, :xml
263
+ ps = Meteor::Ml::Xml::ParserImpl.new
264
+ end
265
+
266
+ ps.read(File.expand_path(relative_path, @root), @enc)
267
+ @cache[relative_url] = ps
268
+
269
+ end
270
+
271
+ private :link_2_n
272
+
273
+ #
274
+ # generate parser (パーサを作成する)
275
+ # @param [String] relative_path relative file path (相対ファイルパス)
276
+ # @param [String] enc character encoding (文字エンコーディング)
277
+ # @return [Meteor::Parser] parser (パーサ)
278
+ #
279
+ def link_2_s(relative_path,enc)
280
+
281
+ relative_url = path_to_url(relative_path)
282
+
283
+ case @type
284
+ when Parser::HTML4, :html4
285
+ ps = Meteor::Ml::Html4::ParserImpl.new
286
+ when Parser::XHTML4, :xhtml4
287
+ ps = Meteor::Ml::Xhtml4::ParserImpl.new
288
+ when Parser::HTML, :html
289
+ ps = Meteor::Ml::Html::ParserImpl.new
290
+ when Parser::XHTML, :xhtml
291
+ ps = Meteor::Ml::Xhtml::ParserImpl.new
292
+ when Parser::XML, :xml
293
+ ps = Meteor::Ml::Xml::ParserImpl.new
294
+ end
295
+
296
+ ps.read(File.expand_path(relative_path, @root), enc)
297
+ @cache[relative_url] = ps
298
+
299
+ end
300
+
301
+ private :link_2_s
302
+
303
+ #
304
+ # generate parser (パーサを作成する)
305
+ # @param [String] relative_path relative file path (相対ファイルパス)
306
+ # @return [Meteor::Parser] parser (パーサ)
307
+ #
308
+ def link_1(relative_path)
309
+
310
+ relative_url = path_to_url(relative_path)
311
+
312
+ case @type
313
+ when Parser::HTML4, :html4
314
+ ps = Meteor::Ml::Html4::ParserImpl.new
315
+ when Parser::XHTML, :xhtml
316
+ ps = Meteor::Ml::Xhtml4::ParserImpl.new
317
+ when Parser::HTML, :html
318
+ ps = Meteor::Ml::Html::ParserImpl.new
319
+ when Parser::XHTML, :xhtml
320
+ ps = Meteor::Ml::Xhtml::ParserImpl.new
321
+ when Parser::XML, :xml
322
+ ps = Meteor::Ml::Xml::ParserImpl.new
323
+ else
324
+ raise ArgumentError
325
+ end
326
+
327
+ ps.read(File.expand_path(relative_path, @root), @enc)
328
+ @cache[relative_url] = ps
329
+
330
+ end
331
+
332
+ private :link_1
333
+
334
+ #
335
+ #@overload parser(key)
336
+ # get parser (パーサを取得する)
337
+ # @param [String,Symbol] key identifier (キー)
338
+ # @return [Meteor::Parser] parser (パーサ)
339
+ #@overload parser(type,relative_path,enc)
340
+ # generate parser (パーサを作成する)
341
+ # @param [Fixnum] type type of parser (パーサ・タイプ)
342
+ # @param [String] relative_path relative file path (相対ファイルパス)
343
+ # @param [String] enc character encoding (エンコーディング)
344
+ # @return [Meteor::Parser] parser (パーサ)
345
+ # @deprecated
346
+ #@overload parser(type,relative_path)
347
+ # generate parser (パーサを作成する)
348
+ # @param [Fixnum] type type of parser (パーサ・タイプ)
349
+ # @param [String] relative_path relative file path (相対ファイルパス)
350
+ # @return [Meteor::Parser] parser (パーサ)
351
+ # @deprecated
352
+ def parser(*args)
353
+ case args.length
354
+ when 1
355
+ parser_1(args[0])
356
+ when 2,3
357
+ link(args)
358
+ end
359
+ # parser_1(key)
360
+ end
361
+
362
+ #
363
+ # get parser (パーサを取得する)
364
+ # @param [String] key identifier (キー)
365
+ # @return [Meteor::Parser] parser (パーサ)
366
+ #
367
+ def parser_1(key)
368
+ @pif = @cache[key.to_s]
369
+ case @pif.doc_type
370
+ when Meteor::Parser::HTML4
371
+ Meteor::Ml::Html4::ParserImpl.new(@pif)
372
+ when Meteor::Parser::XHTML4
373
+ Meteor::Ml::Xhtml4::ParserImpl.new(@pif)
374
+ when Meteor::Parser::HTML
375
+ Meteor::Ml::Html::ParserImpl.new(@pif)
376
+ when Meteor::Parser::XHTML
377
+ Meteor::Ml::Xhtml::ParserImpl.new(@pif)
378
+ when Meteor::Parser::XML
379
+ Meteor::Ml::Xml::ParserImpl.new(@pif)
380
+ end
381
+ end
382
+
383
+ private :parser_1
384
+
385
+ #
386
+ # get root element (ルート要素を取得する)
387
+ # @param [String,Symbol] key identifier (キー)
388
+ # @return [Meteor::RootElement] root element (ルート要素)
389
+ #
390
+ def element(key)
391
+ parser_1(key).root_element
392
+ end
393
+
394
+ #
395
+ # @overload link_str(type, relative_url, doc)
396
+ # generate parser (パーサを作成する)
397
+ # @param [Fixnum] type type of parser (パーサ・タイプ)
398
+ # @param [String] relative_url relative URL (相対URL)
399
+ # @param [String] doc document (ドキュメント)
400
+ # @return [Meteor::Parser] parser (パーサ)
401
+ # @overload link_str(relative_url, doc)
402
+ # generate parser (パーサを作成する)
403
+ # @param [String] relative_url relative URL (相対URL)
404
+ # @param [String] doc document (ドキュメント)
405
+ # @return [Meteor::Parser] parser (パーサ)
406
+ #
407
+ def link_str(*args)
408
+ case args.length
409
+ when 2
410
+ link_str_2(args[0],args[1])
411
+ when 3
412
+ link_str_3(args[0],args[1],args[2])
413
+ else
414
+ raise ArgumentError
415
+ end
416
+ end
417
+
418
+ #
419
+ # generate parser (パーサを作成する)
420
+ # @param [Fixnum,Symbol] type type of parser (パーサ・タイプ)
421
+ # @param [String] relative_url relative URL (相対URL)
422
+ # @param [String] doc document (ドキュメント)
423
+ # @return [Meteor::Parser] parser (パーサ)
424
+ #
425
+ def link_str_3(type, relative_url, doc)
426
+ case type
427
+ when Parser::HTML4, :html
428
+ ps = Meteor::Ml::Html4::ParserImpl.new
429
+ when Parser::XHTML4, :xhtml4
430
+ ps = Meteor::Ml::Xhtml4::ParserImpl.new
431
+ when Parser::HTML, :html
432
+ ps = Meteor::Ml::Html::ParserImpl.new
433
+ when Parser::XHTML, :xhtml
434
+ ps = Meteor::Ml::Xhtml::ParserImpl.new
435
+ when Parser::XML, :xml
436
+ ps = Meteor::Ml::Xml::ParserImpl.new
437
+ end
438
+
439
+ ps.dcument = doc
440
+ ps.parse
441
+ @cache[relative_url] = ps
442
+ end
443
+
444
+ private :link_str_3
445
+
446
+ #
447
+ # generate parser (パーサを作成する)
448
+ # @param [String] relative_url relative URL (相対URL)
449
+ # @param [String] doc document (ドキュメント)
450
+ # @return [Meteor::Parser] parser (パーサ)
451
+ #
452
+ def link_str_2(relative_url, doc)
453
+ case @type
454
+ when Parser::HTML4, :html4
455
+ ps = Meteor::Ml::Html4::ParserImpl.new
456
+ when Parser::XHTML, :xhtml
457
+ ps = Meteor::Ml::Xhtml4::ParserImpl.new
458
+ when Parser::HTML, :html
459
+ ps = Meteor::Ml::Html::ParserImpl.new
460
+ when Parser::XHTML, :xhtml
461
+ ps = Meteor::Ml::Xhtml::ParserImpl.new
462
+ when Parser::XML, :xml
463
+ ps = Meteor::Ml::Xml::ParserImpl.new
464
+ end
465
+
466
+ ps.document = doc
467
+ ps.parse
468
+ @cache[relative_url] = ps
469
+ end
470
+
471
+ private :link_str_2
472
+
473
+ alias :paraser_str :link_str
474
+
475
+ #
476
+ # set parser (パーサをセットする)
477
+ # @param [String,Symbol] key identifier (キー)
478
+ # @param [Meteor::Parser] ps parser (パーサ)
479
+ #
480
+ def []=(key, ps)
481
+ @cache[key] = ps
482
+ end
483
+
484
+ #
485
+ # get parser (パーサを取得する)
486
+ # @param [String,Symbol] key identifier (キー)
487
+ # @return [Meteor::Parser] parser (パーサ)
488
+ #
489
+ def [](key)
490
+ self.parser(key)
491
+ end
492
+ end
493
+ end
@@ -0,0 +1,24 @@
1
+ # -* coding: UTF-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ module Meteor
5
+ #
6
+ # root element class (ルート要素クラス)
7
+ #
8
+ # @!attribute [rw] content_type
9
+ # @return [String] content type (コンテントタイプ)
10
+ # @!attribute [rw] kaigyo_code
11
+ # @return [String] newline (改行コード)
12
+ # @!attribute [rw] charset
13
+ # @return [String] charset (文字コード)
14
+ # @!attribute [rw] character_encoding
15
+ # @return [String] character encoding (文字エンコーディング)
16
+ #
17
+ class RootElement < Element
18
+ attr_accessor :content_type
19
+ attr_accessor :kaigyo_code
20
+ attr_accessor :charset
21
+ attr_accessor :character_encoding
22
+ # attr_accessor :document #[String] document (ドキュメント)
23
+ end
24
+ end