meteor 0.9.12 → 0.9.14

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,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
@@ -0,0 +1,84 @@
1
+ # -* coding: UTF-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ module Meteor
5
+ module Exception
6
+ #
7
+ # Element Search Exception (要素検索例外)
8
+ #
9
+ # @!attribute [rw] message
10
+ # @return [String] message (メッセージ)
11
+ #
12
+ class NoSuchElementException
13
+ attr_accessor :message
14
+
15
+ #
16
+ # initializer (イニシャライザ)
17
+ # @overload initialize(name)
18
+ # @param [String,Symbol] name tag name (タグ名)
19
+ # @overload initialize(attr_name,attr_value)
20
+ # @param [String,Symbol] attr_name attribute name (属性名)
21
+ # @param [String] attr_value attribute value (属性値)
22
+ # @overload initialize(name,attr_name,attr_value)
23
+ # @param [String,Symbol] name tag name (タグ名)
24
+ # @param [String,Symbol] attr_name attribute name (属性名)
25
+ # @param [String] attr_value attribute value (属性値)
26
+ # @overload initialize(attr_name1,attr_value1,attr_name2,attr_value2)
27
+ # @param [String,Symbol] attr_name1 attribute name1 (属性名1)
28
+ # @param [String] attr_value1 attribute value1 (属性値1)
29
+ # @param [String,Symbol] attr_name2 attribute name2 (属性名2)
30
+ # @param [String] attr_value2 attribute value2 (属性値2)
31
+ # @overload initialize(name,attr_name1,attr_value1,attr_name2,attr_value2)
32
+ # @param [String,Symbol] name tag name (タグ名)
33
+ # @param [String,Symbol] attr_name1 attribute name1 (属性名1)
34
+ # @param [String] attr_value1 attribute value1 (属性値1)
35
+ # @param [String,Symbol] attr_name2 attribute name2 (属性名2)
36
+ # @param [String] attr_value2 attribute value2 (属性値2)
37
+ #
38
+ def initialize(*args)
39
+ case args.length
40
+ when ONE
41
+ initialize_1(args[0])
42
+ when TWO
43
+ initialize_2(args[0], args[1])
44
+ when THREE
45
+ initialize_3(args[0], args[1], args[2])
46
+ when FOUR
47
+ initialize_4(args[0], args[1], args[2], args[3])
48
+ when FIVE
49
+ initialize_5(args[0], args[1], args[2], args[3], args[4])
50
+ end
51
+ end
52
+
53
+ def initialize_1(name)
54
+ self.message = "element not found : #{name}"
55
+ end
56
+
57
+ private :initialize_1
58
+
59
+ def initialize_2(attr_name, attr_value)
60
+ self.message = "element not found : [#{attr_name}=#{attr_value}]"
61
+ end
62
+
63
+ private :initialize_2
64
+
65
+ def initialize_3(name, attr_name, attr_value)
66
+ self.message = "element not found : #{name}[#{attr_name}=#{attr_value}]"
67
+ end
68
+
69
+ private :initialize_3
70
+
71
+ def initialize_4(attr_name1, attr_value1, attr_name2, attr_value2)
72
+ self.message = "element not found : [#{attr_name1}=#{attr_value1}][#{attr_name2}=#{attr_value2}]"
73
+ end
74
+
75
+ private :initialize_4
76
+
77
+ def initialize_5(name, attr_name1, attr_value1, attr_name2, attr_value2)
78
+ self.message = "element not found : #{name}[#{attr_name1}=#{attr_value1}][#{attr_name2}=#{attr_value2}]"
79
+ end
80
+
81
+ private :initialize_5
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,167 @@
1
+ # -* coding: UTF-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ module Meteor
5
+ module Ml
6
+ module Html
7
+ #
8
+ # HTML parser (HTMLパーサ)
9
+ #
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_SNG = [
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_LOGIC = ["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$"
45
+ # REQUIRED_M = [' required ',' required',' REQUIRED ',' REQUIRED']
46
+ REQUIRED_R = "required\\s|required$|REQUIRED\\s|REQUIRED$"
47
+
48
+ @@pattern_required_m = Regexp.new(REQUIRED_M)
49
+ @@pattern_required_r = Regexp.new(REQUIRED_R)
50
+
51
+ #
52
+ # initializer (イニシャライザ)
53
+ # @overload initialize
54
+ # @overload initialize(ps)
55
+ # @param [Meteor::Parser] ps paser (パーサ)
56
+ #
57
+ def initialize(*args)
58
+ super()
59
+ @@match_tag = MATCH_TAG
60
+ @@match_tag_sng = MATCH_TAG_SNG
61
+ @@attr_logic = ATTR_LOGIC
62
+ @doc_type = Parser::HTML
63
+ case args.length
64
+ when ZERO
65
+ # initialize_0
66
+ when ONE
67
+ initialize_1(args[0])
68
+ else
69
+ raise ArgumentError
70
+ end
71
+ end
72
+
73
+ #
74
+ # initializer (イニシャライザ)
75
+ #
76
+ # def initialize_0
77
+ # end
78
+ #
79
+ # private :initialize_0
80
+
81
+ #
82
+ # initializer (イニシャライザ)
83
+ # @param [Meteor::Parser] ps parser (パーサ)
84
+ #
85
+ def initialize_1(ps)
86
+ @root.document = String.new(ps.document)
87
+ self.document_hook = String.new(ps.document_hook)
88
+ @root.content_type = String.new(ps.root_element.content_type)
89
+ @root.charset = ps.root_element.charset
90
+ @root.kaigyo_code = ps.root_element.kaigyo_code
91
+ end
92
+
93
+ private :initialize_1
94
+
95
+ #
96
+ # analyze document , set content type (ドキュメントをパースし、コンテントタイプをセットする)
97
+ #
98
+ def analyze_content_type
99
+ @error_check = false
100
+
101
+ element_3("meta", "charset", "[a-zA-Z-]+", false)
102
+
103
+ if !@elm_
104
+ element_3("meta", "charset", "[a-zA-Z-]+", false)
105
+ end
106
+
107
+ @error_check = true
108
+
109
+ if @elm_
110
+ @root.charset = @elm_.attr("charset")
111
+ if !@root.charset
112
+ @root.charset = "utf-8"
113
+ end
114
+ else
115
+ @root.charset = "utf-8"
116
+ end
117
+
118
+ @root.content_type = "text/html"
119
+ end
120
+
121
+ private :analyze_content_type
122
+
123
+ def edit_attrs_(elm, attr_name, attr_value)
124
+ if is_match("selected", attr_name) && is_match("option", elm.name)
125
+ 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)
127
+ 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)
129
+ 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))
131
+ 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))))
134
+ 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)
136
+ edit_attrs_5(elm, attr_name, attr_value, @@pattern_required_m, @@pattern_required_r)
137
+ else
138
+ super(elm, attr_name, attr_value)
139
+ end
140
+ end
141
+
142
+ private :edit_attrs_
143
+
144
+ def get_attr_value_(elm, attr_name)
145
+ if is_match("selected", attr_name) && is_match("option", elm.name)
146
+ get_attr_value_r(elm, @@pattern_selected_m)
147
+ elsif is_match("multiple", attr_name) && is_match("select", elm.name)
148
+ get_attr_value_r(elm, @@pattern_multiple_m)
149
+ elsif is_match("disabled", attr_name) && is_match(DISABLE_ELEMENT, elm.name)
150
+ 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))
152
+ 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))))
155
+ get_attr_value_r(elm, @@pattern_readonly_m)
156
+ elsif is_match("required", attr_name) && is_match(REQUIRE_ELEMENT, elm.name)
157
+ get_attr_value_r(elm, @@pattern_required_m)
158
+ else
159
+ super(elm, attr_name)
160
+ end
161
+ end
162
+
163
+ private :get_attr_value_
164
+ end
165
+ end
166
+ end
167
+ end