nokolexbor 0.3.3 → 0.3.5
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/ext/nokolexbor/nl_attribute.c +201 -0
- data/ext/nokolexbor/nl_cdata.c +8 -0
- data/ext/nokolexbor/nl_comment.c +6 -0
- data/ext/nokolexbor/nl_document.c +53 -7
- data/ext/nokolexbor/nl_document_fragment.c +9 -0
- data/ext/nokolexbor/nl_error.c +21 -19
- data/ext/nokolexbor/nl_node.c +317 -48
- data/ext/nokolexbor/nl_node_set.c +56 -1
- data/ext/nokolexbor/nl_processing_instruction.c +6 -0
- data/ext/nokolexbor/nl_text.c +6 -0
- data/ext/nokolexbor/nokolexbor.c +1 -0
- data/ext/nokolexbor/nokolexbor.h +2 -0
- data/lib/nokolexbor/document.rb +52 -5
- data/lib/nokolexbor/document_fragment.rb +11 -0
- data/lib/nokolexbor/node.rb +370 -24
- data/lib/nokolexbor/node_set.rb +56 -0
- data/lib/nokolexbor/version.rb +1 -1
- data/lib/nokolexbor.rb +0 -1
- metadata +3 -25
- data/lib/nokolexbor/attribute.rb +0 -18
- data/vendor/lexbor/source/lexbor/encoding/base.h +0 -218
- data/vendor/lexbor/source/lexbor/encoding/big5.c +0 -42839
- data/vendor/lexbor/source/lexbor/encoding/config.cmake +0 -12
- data/vendor/lexbor/source/lexbor/encoding/const.h +0 -65
- data/vendor/lexbor/source/lexbor/encoding/decode.c +0 -3193
- data/vendor/lexbor/source/lexbor/encoding/decode.h +0 -370
- data/vendor/lexbor/source/lexbor/encoding/encode.c +0 -1931
- data/vendor/lexbor/source/lexbor/encoding/encode.h +0 -377
- data/vendor/lexbor/source/lexbor/encoding/encoding.c +0 -252
- data/vendor/lexbor/source/lexbor/encoding/encoding.h +0 -475
- data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +0 -53883
- data/vendor/lexbor/source/lexbor/encoding/gb18030.c +0 -47905
- data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +0 -159
- data/vendor/lexbor/source/lexbor/encoding/jis0208.c +0 -22477
- data/vendor/lexbor/source/lexbor/encoding/jis0212.c +0 -15787
- data/vendor/lexbor/source/lexbor/encoding/multi.h +0 -53
- data/vendor/lexbor/source/lexbor/encoding/range.c +0 -71
- data/vendor/lexbor/source/lexbor/encoding/range.h +0 -34
- data/vendor/lexbor/source/lexbor/encoding/res.c +0 -222
- data/vendor/lexbor/source/lexbor/encoding/res.h +0 -34
- data/vendor/lexbor/source/lexbor/encoding/single.c +0 -13748
- data/vendor/lexbor/source/lexbor/encoding/single.h +0 -116
@@ -63,12 +63,27 @@ nl_rb_node_set_create_with_data(lexbor_array_t *array, VALUE rb_document)
|
|
63
63
|
return ret;
|
64
64
|
}
|
65
65
|
|
66
|
+
/**
|
67
|
+
* Get the length of this NodeSet.
|
68
|
+
*
|
69
|
+
* @return [Integer]
|
70
|
+
*/
|
66
71
|
static VALUE
|
67
72
|
nl_node_set_length(VALUE self)
|
68
73
|
{
|
69
74
|
return INT2NUM(nl_rb_node_set_unwrap(self)->length);
|
70
75
|
}
|
71
76
|
|
77
|
+
/**
|
78
|
+
* call-seq:
|
79
|
+
* push(node)
|
80
|
+
*
|
81
|
+
* Append +node+ to the NodeSet.
|
82
|
+
*
|
83
|
+
* @param node [Node]
|
84
|
+
*
|
85
|
+
* @return [NodeSet] +self+, to support chaining of calls.
|
86
|
+
*/
|
72
87
|
static VALUE
|
73
88
|
nl_node_set_push(VALUE self, VALUE rb_node)
|
74
89
|
{
|
@@ -83,6 +98,16 @@ nl_node_set_push(VALUE self, VALUE rb_node)
|
|
83
98
|
return self;
|
84
99
|
}
|
85
100
|
|
101
|
+
/**
|
102
|
+
* call-seq:
|
103
|
+
* delete(node)
|
104
|
+
*
|
105
|
+
* Delete +node+ from the NodeSet.
|
106
|
+
*
|
107
|
+
* @param node [Node]
|
108
|
+
*
|
109
|
+
* @return [Node,nil] The deleted node if found, otherwise returns nil.
|
110
|
+
*/
|
86
111
|
static VALUE
|
87
112
|
nl_node_set_delete(VALUE self, VALUE rb_node)
|
88
113
|
{
|
@@ -103,6 +128,12 @@ nl_node_set_delete(VALUE self, VALUE rb_node)
|
|
103
128
|
return rb_node;
|
104
129
|
}
|
105
130
|
|
131
|
+
/**
|
132
|
+
* call-seq:
|
133
|
+
* include?(node)
|
134
|
+
*
|
135
|
+
* @return true if any member of this NodeSet equals +node+.
|
136
|
+
*/
|
106
137
|
static VALUE
|
107
138
|
nl_node_set_is_include(VALUE self, VALUE rb_node)
|
108
139
|
{
|
@@ -166,6 +197,18 @@ nl_node_set_subseq(VALUE self, long beg, long len)
|
|
166
197
|
return nl_rb_node_set_create_with_data(new_array, nl_rb_document_get(self));
|
167
198
|
}
|
168
199
|
|
200
|
+
/**
|
201
|
+
* call-seq:
|
202
|
+
* [](index) -> Node,nil
|
203
|
+
* [](start, length) -> NodeSet,nil
|
204
|
+
* [](range) -> NodeSet,nil
|
205
|
+
*
|
206
|
+
* @return [Node,NodeSet,nil] the {Node} at +index+, or returns a {NodeSet}
|
207
|
+
* containing nodes starting at +start+ and continuing for +length+ elements, or
|
208
|
+
* returns a {NodeSet} containing nodes specified by +range+. Negative +indices+
|
209
|
+
* count backward from the end of the +node_set+ (-1 is the last node). Returns
|
210
|
+
* nil if the +index+ (or +start+) are out of range.
|
211
|
+
*/
|
169
212
|
static VALUE
|
170
213
|
nl_node_set_slice(int argc, VALUE *argv, VALUE self)
|
171
214
|
{
|
@@ -205,6 +248,9 @@ nl_node_set_slice(int argc, VALUE *argv, VALUE self)
|
|
205
248
|
return nl_node_set_index_at(self, NUM2LONG(arg));
|
206
249
|
}
|
207
250
|
|
251
|
+
/**
|
252
|
+
* @return [Array<Node>] This list as an Array
|
253
|
+
*/
|
208
254
|
static VALUE
|
209
255
|
nl_node_set_to_array(VALUE self)
|
210
256
|
{
|
@@ -221,6 +267,9 @@ nl_node_set_to_array(VALUE self)
|
|
221
267
|
return list;
|
222
268
|
}
|
223
269
|
|
270
|
+
/**
|
271
|
+
* @return [NodeSet] A new set built by merging the +other+ set, excluding duplicates.
|
272
|
+
*/
|
224
273
|
static VALUE
|
225
274
|
nl_node_set_union(VALUE self, VALUE other)
|
226
275
|
{
|
@@ -301,6 +350,9 @@ nl_node_set_find(VALUE self, VALUE selector, lxb_selectors_cb_f cb, void *ctx)
|
|
301
350
|
return status;
|
302
351
|
}
|
303
352
|
|
353
|
+
/**
|
354
|
+
* (see Node#at_css)
|
355
|
+
*/
|
304
356
|
static VALUE
|
305
357
|
nl_node_set_at_css(VALUE self, VALUE selector)
|
306
358
|
{
|
@@ -328,6 +380,9 @@ nl_node_set_at_css(VALUE self, VALUE selector)
|
|
328
380
|
return ret;
|
329
381
|
}
|
330
382
|
|
383
|
+
/**
|
384
|
+
* (see Node#css)
|
385
|
+
*/
|
331
386
|
static VALUE
|
332
387
|
nl_node_set_css(VALUE self, VALUE selector)
|
333
388
|
{
|
@@ -353,7 +408,6 @@ void Init_nl_node_set(void)
|
|
353
408
|
|
354
409
|
rb_define_method(cNokolexborNodeSet, "length", nl_node_set_length, 0);
|
355
410
|
rb_define_method(cNokolexborNodeSet, "[]", nl_node_set_slice, -1);
|
356
|
-
rb_define_method(cNokolexborNodeSet, "slice", nl_node_set_slice, -1);
|
357
411
|
rb_define_method(cNokolexborNodeSet, "push", nl_node_set_push, 1);
|
358
412
|
rb_define_method(cNokolexborNodeSet, "|", nl_node_set_union, 1);
|
359
413
|
rb_define_method(cNokolexborNodeSet, "to_a", nl_node_set_to_array, 0);
|
@@ -362,6 +416,7 @@ void Init_nl_node_set(void)
|
|
362
416
|
rb_define_method(cNokolexborNodeSet, "at_css", nl_node_set_at_css, 1);
|
363
417
|
rb_define_method(cNokolexborNodeSet, "css", nl_node_set_css, 1);
|
364
418
|
|
419
|
+
rb_define_alias(cNokolexborNodeSet, "slice", "[]");
|
365
420
|
rb_define_alias(cNokolexborNodeSet, "<<", "push");
|
366
421
|
rb_define_alias(cNokolexborNodeSet, "size", "length");
|
367
422
|
rb_define_alias(cNokolexborNodeSet, "+", "|");
|
@@ -4,6 +4,12 @@ VALUE cNokolexborProcessingInstruction;
|
|
4
4
|
extern VALUE cNokolexborNode;
|
5
5
|
extern VALUE mNokolexbor;
|
6
6
|
|
7
|
+
/**
|
8
|
+
* call-seq:
|
9
|
+
* new(name, content, document) { |ProcessingInstruction| ... } -> ProcessingInstruction
|
10
|
+
*
|
11
|
+
* Create a new ProcessingInstruction from +name+ and +content+.
|
12
|
+
*/
|
7
13
|
static VALUE
|
8
14
|
nl_processing_instruction_new(int argc, VALUE *argv, VALUE klass)
|
9
15
|
{
|
data/ext/nokolexbor/nl_text.c
CHANGED
@@ -4,6 +4,12 @@ VALUE cNokolexborText;
|
|
4
4
|
extern VALUE cNokolexborCharacterData;
|
5
5
|
extern VALUE mNokolexbor;
|
6
6
|
|
7
|
+
/**
|
8
|
+
* call-seq:
|
9
|
+
* new(text, document) { |Text| ... } -> Text
|
10
|
+
*
|
11
|
+
* Create a new Text from +text+.
|
12
|
+
*/
|
7
13
|
static VALUE
|
8
14
|
nl_text_new(int argc, VALUE *argv, VALUE klass)
|
9
15
|
{
|
data/ext/nokolexbor/nokolexbor.c
CHANGED
data/ext/nokolexbor/nokolexbor.h
CHANGED
@@ -18,6 +18,7 @@ void Init_nl_cdata(void);
|
|
18
18
|
void Init_nl_processing_instruction(void);
|
19
19
|
void Init_nl_node_set(void);
|
20
20
|
void Init_nl_document_fragment(void);
|
21
|
+
void Init_nl_attribute(void);
|
21
22
|
void Init_nl_xpath_context(void);
|
22
23
|
|
23
24
|
void nl_raise_lexbor_error(lxb_status_t error);
|
@@ -34,6 +35,7 @@ lxb_inline VALUE nl_rb_document_get(VALUE rb_node_or_doc)
|
|
34
35
|
}
|
35
36
|
|
36
37
|
lxb_dom_document_t *nl_rb_document_unwrap(VALUE rb_doc);
|
38
|
+
lexbor_array_t *nl_rb_node_set_unwrap(VALUE rb_node_set);
|
37
39
|
|
38
40
|
const lxb_char_t *
|
39
41
|
lxb_dom_node_name_qualified(lxb_dom_node_t *node, size_t *len);
|
data/lib/nokolexbor/document.rb
CHANGED
@@ -2,6 +2,33 @@
|
|
2
2
|
|
3
3
|
module Nokolexbor
|
4
4
|
class Document < Nokolexbor::Node
|
5
|
+
# Create an {Element} with +name+ belonging to this document, optionally setting contents or
|
6
|
+
# attributes.
|
7
|
+
#
|
8
|
+
# @param name [String]
|
9
|
+
# @param contents_or_attrs [#to_s, Hash]
|
10
|
+
#
|
11
|
+
# @return [Element]
|
12
|
+
#
|
13
|
+
# @example An empty element without attributes
|
14
|
+
# doc.create_element("div")
|
15
|
+
# # => <div></div>
|
16
|
+
#
|
17
|
+
# @example An element with contents
|
18
|
+
# doc.create_element("div", "contents")
|
19
|
+
# # => <div>contents</div>
|
20
|
+
#
|
21
|
+
# @example An element with attributes
|
22
|
+
# doc.create_element("div", {"class" => "container"})
|
23
|
+
# # => <div class='container'></div>
|
24
|
+
#
|
25
|
+
# @example An element with contents and attributes
|
26
|
+
# doc.create_element("div", "contents", {"class" => "container"})
|
27
|
+
# # => <div class='container'>contents</div>
|
28
|
+
#
|
29
|
+
# @example Passing a block to mutate the element
|
30
|
+
# doc.create_element("div") { |node| node["class"] = "blue" }
|
31
|
+
# # => <div class='blue'></div>
|
5
32
|
def create_element(name, *contents_or_attrs, &block)
|
6
33
|
elm = Nokolexbor::Element.new(name, self, &block)
|
7
34
|
contents_or_attrs.each do |arg|
|
@@ -11,32 +38,43 @@ module Nokolexbor
|
|
11
38
|
elm[k.to_s] = v.to_s
|
12
39
|
end
|
13
40
|
else
|
14
|
-
elm.content = arg
|
41
|
+
elm.content = arg.to_s
|
15
42
|
end
|
16
43
|
end
|
17
44
|
elm
|
18
45
|
end
|
19
46
|
|
20
|
-
# Create a Text
|
47
|
+
# Create a {Text} with +string+.
|
48
|
+
#
|
49
|
+
# @return [Text]
|
21
50
|
def create_text_node(string, &block)
|
22
51
|
Nokolexbor::Text.new(string.to_s, self, &block)
|
23
52
|
end
|
24
53
|
|
25
|
-
# Create a CDATA
|
54
|
+
# Create a {CDATA} containing +string+.
|
55
|
+
#
|
56
|
+
# @return [CDATA]
|
26
57
|
def create_cdata(string, &block)
|
27
58
|
Nokolexbor::CDATA.new(string.to_s, self, &block)
|
28
59
|
end
|
29
60
|
|
30
|
-
# Create a Comment
|
61
|
+
# Create a {Comment} containing +string+.
|
62
|
+
#
|
63
|
+
# @return [Comment]
|
31
64
|
def create_comment(string, &block)
|
32
65
|
Nokolexbor::Comment.new(string.to_s, self, &block)
|
33
66
|
end
|
34
67
|
|
35
|
-
# A reference to +self
|
68
|
+
# A reference to +self+.
|
69
|
+
#
|
70
|
+
# @return [Document]
|
36
71
|
def document
|
37
72
|
self
|
38
73
|
end
|
39
74
|
|
75
|
+
# Get the meta tag encoding for this document. If there is no meta tag, nil is returned.
|
76
|
+
#
|
77
|
+
# @return [String]
|
40
78
|
def meta_encoding
|
41
79
|
if (meta = at_css("meta[charset]"))
|
42
80
|
meta[:charset]
|
@@ -45,6 +83,15 @@ module Nokolexbor
|
|
45
83
|
end
|
46
84
|
end
|
47
85
|
|
86
|
+
# Set the meta tag encoding for this document.
|
87
|
+
#
|
88
|
+
# If an meta encoding tag is already present, its content is
|
89
|
+
# replaced with the given text.
|
90
|
+
#
|
91
|
+
# Otherwise, this method tries to create one at an appropriate
|
92
|
+
# place supplying head and/or html elements as necessary, which
|
93
|
+
# is inside a head element if any, and before any text node or
|
94
|
+
# content element (typically <body>) if any.
|
48
95
|
def meta_encoding=(encoding)
|
49
96
|
if (meta = meta_content_type)
|
50
97
|
meta["content"] = format("text/html; charset=%s", encoding)
|
@@ -2,10 +2,17 @@
|
|
2
2
|
|
3
3
|
module Nokolexbor
|
4
4
|
class DocumentFragment < Nokolexbor::Node
|
5
|
+
# Create a {DocumentFragment} from +tags+.
|
6
|
+
#
|
7
|
+
# @return [DocumentFragment]
|
5
8
|
def self.parse(tags)
|
6
9
|
new(Nokolexbor::Document.new, tags, nil)
|
7
10
|
end
|
8
11
|
|
12
|
+
# Create a new {DocumentFragment} from +tags+.
|
13
|
+
#
|
14
|
+
# If +ctx+ is present, it is used as a context node for the
|
15
|
+
# subtree created.
|
9
16
|
def initialize(document, tags = nil, ctx = nil)
|
10
17
|
return self unless tags
|
11
18
|
|
@@ -15,6 +22,7 @@ module Nokolexbor
|
|
15
22
|
nil
|
16
23
|
end
|
17
24
|
|
25
|
+
# @return [String] The name of {DocumentFragment}
|
18
26
|
def name
|
19
27
|
"#document-fragment"
|
20
28
|
end
|
@@ -24,6 +32,9 @@ module Nokolexbor
|
|
24
32
|
alias_method :to_s, :outer_html
|
25
33
|
alias_method :serialize, :outer_html
|
26
34
|
|
35
|
+
# Create a {DocumentFragment} from +data+.
|
36
|
+
#
|
37
|
+
# @return [DocumentFragment]
|
27
38
|
def fragment(data)
|
28
39
|
document.fragment(data)
|
29
40
|
end
|