nokolexbor 0.3.2 → 0.3.3
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_cdata.c +1 -1
- data/ext/nokolexbor/nl_comment.c +1 -1
- data/ext/nokolexbor/nl_document.c +2 -0
- data/ext/nokolexbor/nl_document_fragment.c +39 -0
- data/ext/nokolexbor/nl_error.c +93 -0
- data/ext/nokolexbor/nl_node.c +32 -18
- data/ext/nokolexbor/nl_processing_instruction.c +47 -0
- data/ext/nokolexbor/nl_text.c +1 -1
- data/ext/nokolexbor/nl_xpath_context.c +2 -2
- data/ext/nokolexbor/nokolexbor.c +3 -52
- data/ext/nokolexbor/nokolexbor.h +4 -1
- data/lib/nokolexbor/document_fragment.rb +31 -0
- data/lib/nokolexbor/node.rb +4 -0
- data/lib/nokolexbor/version.rb +1 -1
- data/lib/nokolexbor.rb +1 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042127a2ed4027c52d3718c148921604cae07c274dddb7f3702c7caf0708863f
|
4
|
+
data.tar.gz: 60230b55b773ef41abdca313adc3ffdba38a0b8462c9d23c3365e57c68b63bd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06063b84e62e23ba093a397ba6ffdbd802480e711ca24966d5b78be8bc8a7299754ab8bb4cd5d77d6dfe39efa7c21c705b105fe9d626d62eddc5e2e5a6ec9fb
|
7
|
+
data.tar.gz: 86ddfdb650b78827071385cfca708ddbffcd35204a71f439315f800e8e60ee73c2d49ce46e28192ac454df8bab7ef8cbc937b97830e0b488290dbadccd8e51d6
|
data/ext/nokolexbor/nl_cdata.c
CHANGED
@@ -20,7 +20,7 @@ nl_cdata_new(int argc, VALUE *argv, VALUE klass)
|
|
20
20
|
|
21
21
|
document = nl_rb_document_unwrap(rb_document);
|
22
22
|
|
23
|
-
const char*
|
23
|
+
const char *c_content = StringValuePtr(rb_content);
|
24
24
|
size_t content_len = RSTRING_LEN(rb_content);
|
25
25
|
lxb_dom_cdata_section_t *element = lxb_dom_document_create_cdata_section(document, (const lxb_char_t *)c_content, content_len);
|
26
26
|
if (element == NULL) {
|
data/ext/nokolexbor/nl_comment.c
CHANGED
@@ -20,7 +20,7 @@ nl_comment_new(int argc, VALUE *argv, VALUE klass)
|
|
20
20
|
|
21
21
|
document = nl_rb_document_unwrap(rb_document);
|
22
22
|
|
23
|
-
const char*
|
23
|
+
const char *c_content = StringValuePtr(rb_content);
|
24
24
|
size_t content_len = RSTRING_LEN(rb_content);
|
25
25
|
lxb_dom_comment_t *element = lxb_dom_document_create_comment(document, (const lxb_char_t *)c_content, content_len);
|
26
26
|
if (element == NULL) {
|
@@ -41,6 +41,8 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
|
|
41
41
|
rb_raise(rb_eRuntimeError, "Error creating document");
|
42
42
|
}
|
43
43
|
|
44
|
+
lxb_dom_document_scripting_set(lxb_dom_interface_document(document), true);
|
45
|
+
|
44
46
|
lxb_status_t status = lxb_html_document_parse(document, (const lxb_char_t *)html_c, html_len);
|
45
47
|
if (status != LXB_STATUS_OK) {
|
46
48
|
nl_raise_lexbor_error(status);
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#include "nokolexbor.h"
|
2
|
+
|
3
|
+
VALUE cNokolexborDocumentFragment;
|
4
|
+
extern VALUE cNokolexborNode;
|
5
|
+
extern VALUE mNokolexbor;
|
6
|
+
|
7
|
+
static VALUE
|
8
|
+
nl_document_fragment_new(int argc, VALUE *argv, VALUE klass)
|
9
|
+
{
|
10
|
+
lxb_dom_document_t *document;
|
11
|
+
VALUE rb_document;
|
12
|
+
VALUE rest;
|
13
|
+
|
14
|
+
rb_scan_args(argc, argv, "1*", &rb_document, &rest);
|
15
|
+
|
16
|
+
if (!rb_obj_is_kind_of(rb_document, cNokolexborDocument)) {
|
17
|
+
rb_raise(rb_eArgError, "Document must be a Nokolexbor::Document");
|
18
|
+
}
|
19
|
+
|
20
|
+
document = nl_rb_document_unwrap(rb_document);
|
21
|
+
|
22
|
+
lxb_dom_document_fragment_t *node = lxb_dom_document_create_document_fragment(document);
|
23
|
+
if (node == NULL) {
|
24
|
+
rb_raise(rb_eRuntimeError, "Error creating document fragment");
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE rb_node = nl_rb_node_create(&node->node, rb_document);
|
28
|
+
|
29
|
+
rb_obj_call_init(rb_node, argc, argv);
|
30
|
+
|
31
|
+
return rb_node;
|
32
|
+
}
|
33
|
+
|
34
|
+
void Init_nl_document_fragment(void)
|
35
|
+
{
|
36
|
+
cNokolexborDocumentFragment = rb_define_class_under(mNokolexbor, "DocumentFragment", cNokolexborNode);
|
37
|
+
|
38
|
+
rb_define_singleton_method(cNokolexborDocumentFragment, "new", nl_document_fragment_new, -1);
|
39
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#include "nokolexbor.h"
|
2
|
+
|
3
|
+
VALUE eLexborError;
|
4
|
+
VALUE eLexborMemoryAllocationError;
|
5
|
+
VALUE eLexborSmallBufferError;
|
6
|
+
VALUE eLexborObjectIsNullError;
|
7
|
+
VALUE eLexborIncompleteObjectError;
|
8
|
+
VALUE eLexborNoFreeSlotError;
|
9
|
+
VALUE eLexborTooSmallSizeError;
|
10
|
+
VALUE eLexborNotExistsError;
|
11
|
+
VALUE eLexborWrongArgsError;
|
12
|
+
VALUE eLexborWrongStageError;
|
13
|
+
VALUE eLexborUnexpectedResultError;
|
14
|
+
VALUE eLexborUnexpectedDataError;
|
15
|
+
VALUE eLexborOverflowError;
|
16
|
+
VALUE eLexborContinueStatus;
|
17
|
+
VALUE eLexborSmallBufferStatus;
|
18
|
+
VALUE eLexborAbortedStatus;
|
19
|
+
VALUE eLexborStoppedStatus;
|
20
|
+
VALUE eLexborNextStatus;
|
21
|
+
VALUE eLexborStopStatus;
|
22
|
+
extern VALUE mNokolexbor;
|
23
|
+
|
24
|
+
void nl_raise_lexbor_error(lxb_status_t error)
|
25
|
+
{
|
26
|
+
switch (error) {
|
27
|
+
case LXB_STATUS_ERROR:
|
28
|
+
rb_exc_raise(eLexborError);
|
29
|
+
case LXB_STATUS_ERROR_MEMORY_ALLOCATION:
|
30
|
+
rb_exc_raise(eLexborMemoryAllocationError);
|
31
|
+
case LXB_STATUS_ERROR_OBJECT_IS_NULL:
|
32
|
+
rb_exc_raise(eLexborObjectIsNullError);
|
33
|
+
case LXB_STATUS_ERROR_SMALL_BUFFER:
|
34
|
+
rb_exc_raise(eLexborSmallBufferError);
|
35
|
+
case LXB_STATUS_ERROR_INCOMPLETE_OBJECT:
|
36
|
+
rb_exc_raise(eLexborIncompleteObjectError);
|
37
|
+
case LXB_STATUS_ERROR_NO_FREE_SLOT:
|
38
|
+
rb_exc_raise(eLexborNoFreeSlotError);
|
39
|
+
case LXB_STATUS_ERROR_TOO_SMALL_SIZE:
|
40
|
+
rb_exc_raise(eLexborTooSmallSizeError);
|
41
|
+
case LXB_STATUS_ERROR_NOT_EXISTS:
|
42
|
+
rb_exc_raise(eLexborNotExistsError);
|
43
|
+
case LXB_STATUS_ERROR_WRONG_ARGS:
|
44
|
+
rb_exc_raise(eLexborWrongArgsError);
|
45
|
+
case LXB_STATUS_ERROR_WRONG_STAGE:
|
46
|
+
rb_exc_raise(eLexborWrongStageError);
|
47
|
+
case LXB_STATUS_ERROR_UNEXPECTED_RESULT:
|
48
|
+
rb_exc_raise(eLexborUnexpectedResultError);
|
49
|
+
case LXB_STATUS_ERROR_UNEXPECTED_DATA:
|
50
|
+
rb_raise(eLexborUnexpectedDataError, "Invalid syntax");
|
51
|
+
case LXB_STATUS_ERROR_OVERFLOW:
|
52
|
+
rb_exc_raise(eLexborOverflowError);
|
53
|
+
case LXB_STATUS_CONTINUE:
|
54
|
+
rb_exc_raise(eLexborContinueStatus);
|
55
|
+
case LXB_STATUS_SMALL_BUFFER:
|
56
|
+
rb_exc_raise(eLexborSmallBufferStatus);
|
57
|
+
case LXB_STATUS_ABORTED:
|
58
|
+
rb_exc_raise(eLexborAbortedStatus);
|
59
|
+
case LXB_STATUS_STOPPED:
|
60
|
+
rb_exc_raise(eLexborStoppedStatus);
|
61
|
+
case LXB_STATUS_NEXT:
|
62
|
+
rb_exc_raise(eLexborNextStatus);
|
63
|
+
case LXB_STATUS_STOP:
|
64
|
+
rb_exc_raise(eLexborStopStatus);
|
65
|
+
case LXB_STATUS_OK:
|
66
|
+
return;
|
67
|
+
default:
|
68
|
+
rb_raise(eLexborError, "Unknown error (%d)", error);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
void Init_nl_error(void)
|
73
|
+
{
|
74
|
+
eLexborError = rb_define_class_under(mNokolexbor, "LexborError", rb_eStandardError);
|
75
|
+
eLexborMemoryAllocationError = rb_define_class_under(mNokolexbor, "LexborMemoryAllocationError", eLexborError);
|
76
|
+
eLexborSmallBufferError = rb_define_class_under(mNokolexbor, "LexborSmallBufferError", eLexborError);
|
77
|
+
eLexborObjectIsNullError = rb_define_class_under(mNokolexbor, "LexborObjectIsNullError", eLexborError);
|
78
|
+
eLexborIncompleteObjectError = rb_define_class_under(mNokolexbor, "LexborIncompleteObjectError", eLexborError);
|
79
|
+
eLexborNoFreeSlotError = rb_define_class_under(mNokolexbor, "LexborNoFreeSlotError", eLexborError);
|
80
|
+
eLexborTooSmallSizeError = rb_define_class_under(mNokolexbor, "LexborTooSmallSizeError", eLexborError);
|
81
|
+
eLexborNotExistsError = rb_define_class_under(mNokolexbor, "LexborNotExistsError", eLexborError);
|
82
|
+
eLexborWrongArgsError = rb_define_class_under(mNokolexbor, "LexborWrongArgsError", eLexborError);
|
83
|
+
eLexborWrongStageError = rb_define_class_under(mNokolexbor, "LexborWrongStageError", eLexborError);
|
84
|
+
eLexborUnexpectedResultError = rb_define_class_under(mNokolexbor, "LexborUnexpectedResultError", eLexborError);
|
85
|
+
eLexborUnexpectedDataError = rb_define_class_under(mNokolexbor, "LexborUnexpectedDataError", eLexborError);
|
86
|
+
eLexborOverflowError = rb_define_class_under(mNokolexbor, "LexborOverflowError", eLexborError);
|
87
|
+
eLexborContinueStatus = rb_define_class_under(mNokolexbor, "LexborContinueStatus", eLexborError);
|
88
|
+
eLexborSmallBufferStatus = rb_define_class_under(mNokolexbor, "LexborSmallBufferStatus", eLexborError);
|
89
|
+
eLexborAbortedStatus = rb_define_class_under(mNokolexbor, "LexborAbortedStatus", eLexborError);
|
90
|
+
eLexborStoppedStatus = rb_define_class_under(mNokolexbor, "LexborStoppedStatus", eLexborError);
|
91
|
+
eLexborNextStatus = rb_define_class_under(mNokolexbor, "LexborNextStatus", eLexborError);
|
92
|
+
eLexborStopStatus = rb_define_class_under(mNokolexbor, "LexborStopStatus", eLexborError);
|
93
|
+
}
|
data/ext/nokolexbor/nl_node.c
CHANGED
@@ -9,7 +9,9 @@ extern VALUE mNokolexbor;
|
|
9
9
|
extern VALUE cNokolexborDocument;
|
10
10
|
extern VALUE cNokolexborText;
|
11
11
|
extern VALUE cNokolexborComment;
|
12
|
+
extern VALUE cNokolexborProcessingInstruction;
|
12
13
|
extern VALUE cNokolexborNodeSet;
|
14
|
+
extern VALUE cNokolexborDocumentFragment;
|
13
15
|
extern VALUE eLexborError;
|
14
16
|
VALUE cNokolexborNode;
|
15
17
|
VALUE cNokolexborElement;
|
@@ -41,8 +43,9 @@ nl_rb_node_create(lxb_dom_node_t *node, VALUE rb_document)
|
|
41
43
|
// break;
|
42
44
|
// case LXB_DOM_NODE_TYPE_ENTITY:
|
43
45
|
// break;
|
44
|
-
|
45
|
-
|
46
|
+
case LXB_DOM_NODE_TYPE_PROCESSING_INSTRUCTION:
|
47
|
+
rb_class = cNokolexborProcessingInstruction;
|
48
|
+
break;
|
46
49
|
case LXB_DOM_NODE_TYPE_COMMENT:
|
47
50
|
rb_class = cNokolexborComment;
|
48
51
|
break;
|
@@ -50,8 +53,9 @@ nl_rb_node_create(lxb_dom_node_t *node, VALUE rb_document)
|
|
50
53
|
// break;
|
51
54
|
// case LXB_DOM_NODE_TYPE_DOCUMENT_TYPE:
|
52
55
|
// break;
|
53
|
-
|
54
|
-
|
56
|
+
case LXB_DOM_NODE_TYPE_DOCUMENT_FRAGMENT:
|
57
|
+
rb_class = cNokolexborDocumentFragment;
|
58
|
+
break;
|
55
59
|
// case LXB_DOM_NODE_TYPE_NOTATION:
|
56
60
|
// break;
|
57
61
|
default:
|
@@ -91,7 +95,7 @@ nl_node_new(int argc, VALUE *argv, VALUE klass)
|
|
91
95
|
|
92
96
|
document = nl_rb_document_unwrap(rb_document);
|
93
97
|
|
94
|
-
const char*
|
98
|
+
const char *c_name = StringValuePtr(rb_name);
|
95
99
|
size_t name_len = RSTRING_LEN(rb_name);
|
96
100
|
lxb_dom_element_t *element = lxb_dom_document_create_element(document, (const lxb_char_t *)c_name, name_len, NULL);
|
97
101
|
if (element == NULL) {
|
@@ -657,17 +661,19 @@ nl_node_name(VALUE self)
|
|
657
661
|
}
|
658
662
|
|
659
663
|
static lxb_dom_node_t *
|
660
|
-
nl_node_parse_fragment(lxb_dom_document_t *doc, lxb_char_t *html, size_t size)
|
664
|
+
nl_node_parse_fragment(lxb_dom_document_t *doc, lxb_dom_element_t *element, lxb_char_t *html, size_t size)
|
661
665
|
{
|
662
666
|
size_t tag_name_len;
|
663
667
|
lxb_html_document_t *html_doc = lxb_html_interface_document(doc);
|
664
|
-
const lxb_char_t *tag_name = lxb_tag_name_by_id(lxb_html_document_tags(html_doc), LXB_TAG__UNDEF, &tag_name_len);
|
665
|
-
if (tag_name == NULL) {
|
666
|
-
rb_raise(rb_eRuntimeError, "Error getting tag name");
|
667
|
-
}
|
668
|
-
lxb_dom_element_t *element = lxb_dom_document_create_element(doc, tag_name, tag_name_len, NULL);
|
669
668
|
if (element == NULL) {
|
670
|
-
|
669
|
+
const lxb_char_t *tag_name = lxb_tag_name_by_id(lxb_html_document_tags(html_doc), LXB_TAG__UNDEF, &tag_name_len);
|
670
|
+
if (tag_name == NULL) {
|
671
|
+
rb_raise(rb_eRuntimeError, "Error getting tag name");
|
672
|
+
}
|
673
|
+
element = lxb_dom_document_create_element(doc, tag_name, tag_name_len, NULL);
|
674
|
+
if (element == NULL) {
|
675
|
+
rb_raise(rb_eRuntimeError, "Error creating element");
|
676
|
+
}
|
671
677
|
}
|
672
678
|
lxb_dom_node_t *frag_root = lxb_html_document_parse_fragment(html_doc, element, html, size);
|
673
679
|
if (frag_root == NULL) {
|
@@ -677,14 +683,22 @@ nl_node_parse_fragment(lxb_dom_document_t *doc, lxb_char_t *html, size_t size)
|
|
677
683
|
}
|
678
684
|
|
679
685
|
static VALUE
|
680
|
-
|
686
|
+
nl_node_parse(VALUE self, VALUE html)
|
681
687
|
{
|
682
688
|
Check_Type(html, T_STRING);
|
683
689
|
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
|
684
690
|
lxb_dom_document_t *doc = node->owner_document;
|
685
691
|
|
686
|
-
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, (lxb_char_t *)RSTRING_PTR(html), RSTRING_LEN(html));
|
687
|
-
|
692
|
+
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, lxb_dom_interface_element(node), (lxb_char_t *)RSTRING_PTR(html), RSTRING_LEN(html));
|
693
|
+
lexbor_array_t *array = lexbor_array_create();
|
694
|
+
|
695
|
+
while (frag_root->first_child != NULL) {
|
696
|
+
lxb_dom_node_t *child = frag_root->first_child;
|
697
|
+
lxb_dom_node_remove(child);
|
698
|
+
lexbor_array_push(array, child);
|
699
|
+
}
|
700
|
+
lxb_dom_node_destroy(frag_root);
|
701
|
+
return nl_rb_node_set_create_with_data(array, nl_rb_document_get(self));
|
688
702
|
}
|
689
703
|
|
690
704
|
static VALUE
|
@@ -703,7 +717,7 @@ nl_node_add_sibling(VALUE self, VALUE next_or_previous, VALUE new)
|
|
703
717
|
}
|
704
718
|
|
705
719
|
if (TYPE(new) == T_STRING) {
|
706
|
-
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, (lxb_char_t *)RSTRING_PTR(new), RSTRING_LEN(new));
|
720
|
+
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, NULL, (lxb_char_t *)RSTRING_PTR(new), RSTRING_LEN(new));
|
707
721
|
lexbor_array_t *array = lexbor_array_create();
|
708
722
|
|
709
723
|
while (frag_root->first_child != NULL) {
|
@@ -734,7 +748,7 @@ nl_node_add_child(VALUE self, VALUE new)
|
|
734
748
|
lxb_dom_document_t *doc = node->owner_document;
|
735
749
|
|
736
750
|
if (TYPE(new) == T_STRING) {
|
737
|
-
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, (lxb_char_t *)RSTRING_PTR(new), RSTRING_LEN(new));
|
751
|
+
lxb_dom_node_t *frag_root = nl_node_parse_fragment(doc, NULL, (lxb_char_t *)RSTRING_PTR(new), RSTRING_LEN(new));
|
738
752
|
lexbor_array_t *array = lexbor_array_create();
|
739
753
|
|
740
754
|
while (frag_root->first_child != NULL) {
|
@@ -859,7 +873,7 @@ void Init_nl_node(void)
|
|
859
873
|
rb_define_method(cNokolexborNode, "destroy", nl_node_destroy, 0);
|
860
874
|
rb_define_method(cNokolexborNode, "attrs", nl_node_attrs, 0);
|
861
875
|
rb_define_method(cNokolexborNode, "name", nl_node_name, 0);
|
862
|
-
rb_define_method(cNokolexborNode, "
|
876
|
+
rb_define_method(cNokolexborNode, "parse", nl_node_parse, 1);
|
863
877
|
rb_define_method(cNokolexborNode, "add_sibling", nl_node_add_sibling, 2);
|
864
878
|
rb_define_method(cNokolexborNode, "add_child", nl_node_add_child, 1);
|
865
879
|
rb_define_method(cNokolexborNode, "node_type", nl_node_get_type, 0);
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#include "nokolexbor.h"
|
2
|
+
|
3
|
+
VALUE cNokolexborProcessingInstruction;
|
4
|
+
extern VALUE cNokolexborNode;
|
5
|
+
extern VALUE mNokolexbor;
|
6
|
+
|
7
|
+
static VALUE
|
8
|
+
nl_processing_instruction_new(int argc, VALUE *argv, VALUE klass)
|
9
|
+
{
|
10
|
+
lxb_dom_document_t *document;
|
11
|
+
VALUE rb_name;
|
12
|
+
VALUE rb_content;
|
13
|
+
VALUE rb_document;
|
14
|
+
VALUE rest;
|
15
|
+
|
16
|
+
rb_scan_args(argc, argv, "3*", &rb_name, &rb_content, &rb_document, &rest);
|
17
|
+
|
18
|
+
if (!rb_obj_is_kind_of(rb_document, cNokolexborDocument)) {
|
19
|
+
rb_raise(rb_eArgError, "Document must be a Nokolexbor::Document");
|
20
|
+
}
|
21
|
+
|
22
|
+
document = nl_rb_document_unwrap(rb_document);
|
23
|
+
|
24
|
+
const char *c_name = StringValuePtr(rb_name);
|
25
|
+
size_t name_len = RSTRING_LEN(rb_name);
|
26
|
+
const char *c_content = StringValuePtr(rb_content);
|
27
|
+
size_t content_len = RSTRING_LEN(rb_content);
|
28
|
+
lxb_dom_processing_instruction_t *node = lxb_dom_document_create_processing_instruction(document, (const lxb_char_t *)c_name, name_len, (const lxb_char_t *)c_content, content_len);
|
29
|
+
if (node == NULL) {
|
30
|
+
rb_raise(rb_eRuntimeError, "Error creating processing instruction");
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE rb_node = nl_rb_node_create(&node->char_data.node, rb_document);
|
34
|
+
|
35
|
+
if (rb_block_given_p()) {
|
36
|
+
rb_yield(rb_node);
|
37
|
+
}
|
38
|
+
|
39
|
+
return rb_node;
|
40
|
+
}
|
41
|
+
|
42
|
+
void Init_nl_processing_instruction(void)
|
43
|
+
{
|
44
|
+
cNokolexborProcessingInstruction = rb_define_class_under(mNokolexbor, "ProcessingInstruction", cNokolexborNode);
|
45
|
+
|
46
|
+
rb_define_singleton_method(cNokolexborProcessingInstruction, "new", nl_processing_instruction_new, -1);
|
47
|
+
}
|
data/ext/nokolexbor/nl_text.c
CHANGED
@@ -20,7 +20,7 @@ nl_text_new(int argc, VALUE *argv, VALUE klass)
|
|
20
20
|
|
21
21
|
document = nl_rb_document_unwrap(rb_document);
|
22
22
|
|
23
|
-
const char*
|
23
|
+
const char *c_text = StringValuePtr(rb_text);
|
24
24
|
size_t text_len = RSTRING_LEN(rb_text);
|
25
25
|
lxb_dom_text_t *element = lxb_dom_document_create_text_node(document, (const lxb_char_t *)c_text, text_len);
|
26
26
|
if (element == NULL) {
|
@@ -329,9 +329,9 @@ nl_xpath_context_new(VALUE klass, VALUE rb_node)
|
|
329
329
|
nl_xmlXPathRegisterNs(ctx, NOKOGIRI_PREFIX, NOKOGIRI_URI);
|
330
330
|
nl_xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
331
331
|
nl_xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
|
332
|
-
|
332
|
+
xpath_builtin_css_class);
|
333
333
|
nl_xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
|
334
|
-
|
334
|
+
xpath_builtin_local_name_is);
|
335
335
|
|
336
336
|
self = Data_Wrap_Struct(klass, 0, free_xml_xpath_context, ctx);
|
337
337
|
rb_iv_set(self, "@document", nl_rb_document_get(rb_node));
|
data/ext/nokolexbor/nokolexbor.c
CHANGED
@@ -1,56 +1,6 @@
|
|
1
1
|
#include "nokolexbor.h"
|
2
2
|
|
3
3
|
VALUE mNokolexbor;
|
4
|
-
VALUE eLexborError;
|
5
|
-
VALUE eLexborSyntaxError;
|
6
|
-
|
7
|
-
void nl_raise_lexbor_error(lxb_status_t error)
|
8
|
-
{
|
9
|
-
switch (error) {
|
10
|
-
case LXB_STATUS_ERROR:
|
11
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR");
|
12
|
-
case LXB_STATUS_ERROR_MEMORY_ALLOCATION:
|
13
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_MEMORY_ALLOCATION");
|
14
|
-
case LXB_STATUS_ERROR_OBJECT_IS_NULL:
|
15
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_OBJECT_IS_NULL");
|
16
|
-
case LXB_STATUS_ERROR_SMALL_BUFFER:
|
17
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_SMALL_BUFFER");
|
18
|
-
case LXB_STATUS_ERROR_INCOMPLETE_OBJECT:
|
19
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_INCOMPLETE_OBJECT");
|
20
|
-
case LXB_STATUS_ERROR_NO_FREE_SLOT:
|
21
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_NO_FREE_SLOT");
|
22
|
-
case LXB_STATUS_ERROR_TOO_SMALL_SIZE:
|
23
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_TOO_SMALL_SIZE");
|
24
|
-
case LXB_STATUS_ERROR_NOT_EXISTS:
|
25
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_NOT_EXISTS");
|
26
|
-
case LXB_STATUS_ERROR_WRONG_ARGS:
|
27
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_WRONG_ARGS");
|
28
|
-
case LXB_STATUS_ERROR_WRONG_STAGE:
|
29
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_WRONG_STAGE");
|
30
|
-
case LXB_STATUS_ERROR_UNEXPECTED_RESULT:
|
31
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_UNEXPECTED_RESULT");
|
32
|
-
case LXB_STATUS_ERROR_UNEXPECTED_DATA:
|
33
|
-
rb_raise(eLexborSyntaxError, "LXB_STATUS_ERROR_UNEXPECTED_DATA");
|
34
|
-
case LXB_STATUS_ERROR_OVERFLOW:
|
35
|
-
rb_raise(eLexborError, "LXB_STATUS_ERROR_OVERFLOW");
|
36
|
-
case LXB_STATUS_CONTINUE:
|
37
|
-
rb_raise(eLexborError, "LXB_STATUS_CONTINUE");
|
38
|
-
case LXB_STATUS_SMALL_BUFFER:
|
39
|
-
rb_raise(eLexborError, "LXB_STATUS_SMALL_BUFFER");
|
40
|
-
case LXB_STATUS_ABORTED:
|
41
|
-
rb_raise(eLexborError, "LXB_STATUS_ABORTED");
|
42
|
-
case LXB_STATUS_STOPPED:
|
43
|
-
rb_raise(eLexborError, "LXB_STATUS_STOPPED");
|
44
|
-
case LXB_STATUS_NEXT:
|
45
|
-
rb_raise(eLexborError, "LXB_STATUS_NEXT");
|
46
|
-
case LXB_STATUS_STOP:
|
47
|
-
rb_raise(eLexborError, "LXB_STATUS_STOP");
|
48
|
-
case LXB_STATUS_OK:
|
49
|
-
return;
|
50
|
-
default:
|
51
|
-
rb_raise(eLexborError, "LXB_ERROR_UKNOWN(%d)", error);
|
52
|
-
}
|
53
|
-
}
|
54
4
|
|
55
5
|
void Init_nokolexbor(void)
|
56
6
|
{
|
@@ -58,13 +8,14 @@ void Init_nokolexbor(void)
|
|
58
8
|
lexbor_memory_setup(ruby_xmalloc, ruby_xrealloc, ruby_xcalloc, ruby_xfree);
|
59
9
|
#endif
|
60
10
|
mNokolexbor = rb_define_module("Nokolexbor");
|
61
|
-
|
62
|
-
eLexborSyntaxError = rb_define_class_under(mNokolexbor, "LexborSyntaxError", eLexborError);
|
11
|
+
Init_nl_error();
|
63
12
|
Init_nl_node();
|
64
13
|
Init_nl_document();
|
65
14
|
Init_nl_text();
|
66
15
|
Init_nl_comment();
|
67
16
|
Init_nl_cdata();
|
17
|
+
Init_nl_processing_instruction();
|
68
18
|
Init_nl_node_set();
|
19
|
+
Init_nl_document_fragment();
|
69
20
|
Init_nl_xpath_context();
|
70
21
|
}
|
data/ext/nokolexbor/nokolexbor.h
CHANGED
@@ -9,12 +9,15 @@
|
|
9
9
|
|
10
10
|
extern VALUE cNokolexborDocument;
|
11
11
|
|
12
|
+
void Init_nl_error(void);
|
12
13
|
void Init_nl_document(void);
|
13
14
|
void Init_nl_node(void);
|
14
|
-
void Init_nl_node_set(void);
|
15
15
|
void Init_nl_text(void);
|
16
16
|
void Init_nl_comment(void);
|
17
17
|
void Init_nl_cdata(void);
|
18
|
+
void Init_nl_processing_instruction(void);
|
19
|
+
void Init_nl_node_set(void);
|
20
|
+
void Init_nl_document_fragment(void);
|
18
21
|
void Init_nl_xpath_context(void);
|
19
22
|
|
20
23
|
void nl_raise_lexbor_error(lxb_status_t error);
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nokolexbor
|
4
|
+
class DocumentFragment < Nokolexbor::Node
|
5
|
+
def self.parse(tags)
|
6
|
+
new(Nokolexbor::Document.new, tags, nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(document, tags = nil, ctx = nil)
|
10
|
+
return self unless tags
|
11
|
+
|
12
|
+
ctx ||= document
|
13
|
+
node_set = ctx.parse(tags)
|
14
|
+
node_set.each { |child| child.parent = self } unless node_set.empty?
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
"#document-fragment"
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :outer_html, :inner_html
|
23
|
+
alias_method :to_html, :outer_html
|
24
|
+
alias_method :to_s, :outer_html
|
25
|
+
alias_method :serialize, :outer_html
|
26
|
+
|
27
|
+
def fragment(data)
|
28
|
+
document.fragment(data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/nokolexbor/node.rb
CHANGED
data/lib/nokolexbor/version.rb
CHANGED
data/lib/nokolexbor.rb
CHANGED
@@ -25,6 +25,7 @@ require 'nokolexbor/version'
|
|
25
25
|
require 'nokolexbor/node'
|
26
26
|
require 'nokolexbor/document'
|
27
27
|
require 'nokolexbor/node_set'
|
28
|
+
require 'nokolexbor/document_fragment'
|
28
29
|
require 'nokolexbor/attribute'
|
29
30
|
require 'nokolexbor/xpath'
|
30
31
|
require 'nokolexbor/xpath_context'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokolexbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yicheng Zhou
|
@@ -81,8 +81,11 @@ files:
|
|
81
81
|
- ext/nokolexbor/nl_cdata.c
|
82
82
|
- ext/nokolexbor/nl_comment.c
|
83
83
|
- ext/nokolexbor/nl_document.c
|
84
|
+
- ext/nokolexbor/nl_document_fragment.c
|
85
|
+
- ext/nokolexbor/nl_error.c
|
84
86
|
- ext/nokolexbor/nl_node.c
|
85
87
|
- ext/nokolexbor/nl_node_set.c
|
88
|
+
- ext/nokolexbor/nl_processing_instruction.c
|
86
89
|
- ext/nokolexbor/nl_text.c
|
87
90
|
- ext/nokolexbor/nl_xpath_context.c
|
88
91
|
- ext/nokolexbor/nokolexbor.c
|
@@ -118,6 +121,7 @@ files:
|
|
118
121
|
- lib/nokolexbor.rb
|
119
122
|
- lib/nokolexbor/attribute.rb
|
120
123
|
- lib/nokolexbor/document.rb
|
124
|
+
- lib/nokolexbor/document_fragment.rb
|
121
125
|
- lib/nokolexbor/node.rb
|
122
126
|
- lib/nokolexbor/node_set.rb
|
123
127
|
- lib/nokolexbor/version.rb
|