nokolexbor 0.2.5 → 0.3.1

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/ext/nokolexbor/CMakeLists.txt +7 -4
  3. data/ext/nokolexbor/config.h.cmake.in +2 -0
  4. data/ext/nokolexbor/extconf.rb +47 -25
  5. data/ext/nokolexbor/libxml/SAX2.h +4 -4
  6. data/ext/nokolexbor/libxml/chvalid.h +21 -21
  7. data/ext/nokolexbor/libxml/dict.h +13 -13
  8. data/ext/nokolexbor/libxml/globals.h +202 -202
  9. data/ext/nokolexbor/libxml/hash.h +25 -25
  10. data/ext/nokolexbor/libxml/parser.h +5 -5
  11. data/ext/nokolexbor/libxml/parserInternals.h +4 -4
  12. data/ext/nokolexbor/libxml/pattern.h +14 -14
  13. data/ext/nokolexbor/libxml/threads.h +15 -15
  14. data/ext/nokolexbor/libxml/tree.h +5 -5
  15. data/ext/nokolexbor/libxml/xmlerror.h +5 -5
  16. data/ext/nokolexbor/libxml/xmlmemory.h +16 -16
  17. data/ext/nokolexbor/libxml/xmlstring.h +30 -30
  18. data/ext/nokolexbor/libxml/xpath.h +43 -43
  19. data/ext/nokolexbor/libxml/xpathInternals.h +128 -128
  20. data/ext/nokolexbor/memory.c +6 -6
  21. data/ext/nokolexbor/nl_cdata.c +44 -0
  22. data/ext/nokolexbor/nl_comment.c +44 -0
  23. data/ext/nokolexbor/nl_document.c +23 -9
  24. data/ext/nokolexbor/nl_node.c +191 -178
  25. data/ext/nokolexbor/nl_node_set.c +38 -73
  26. data/ext/nokolexbor/nl_text.c +44 -0
  27. data/ext/nokolexbor/nl_xpath_context.c +33 -42
  28. data/ext/nokolexbor/nokolexbor.c +7 -3
  29. data/ext/nokolexbor/nokolexbor.h +9 -7
  30. data/ext/nokolexbor/private/buf.h +1 -1
  31. data/ext/nokolexbor/private/error.h +3 -3
  32. data/ext/nokolexbor/xml_SAX2.c +8 -8
  33. data/ext/nokolexbor/xml_buf.c +19 -19
  34. data/ext/nokolexbor/xml_chvalid.c +25 -25
  35. data/ext/nokolexbor/xml_dict.c +69 -69
  36. data/ext/nokolexbor/xml_encoding.c +2 -2
  37. data/ext/nokolexbor/xml_error.c +51 -51
  38. data/ext/nokolexbor/xml_globals.c +329 -329
  39. data/ext/nokolexbor/xml_hash.c +131 -131
  40. data/ext/nokolexbor/xml_memory.c +25 -25
  41. data/ext/nokolexbor/xml_parser.c +3 -3
  42. data/ext/nokolexbor/xml_parserInternals.c +15 -15
  43. data/ext/nokolexbor/xml_pattern.c +103 -103
  44. data/ext/nokolexbor/xml_string.c +93 -93
  45. data/ext/nokolexbor/xml_threads.c +61 -61
  46. data/ext/nokolexbor/xml_tree.c +12 -12
  47. data/ext/nokolexbor/xml_xpath.c +1194 -1203
  48. data/lib/nokolexbor/document.rb +92 -1
  49. data/lib/nokolexbor/node.rb +64 -0
  50. data/lib/nokolexbor/node_set.rb +6 -5
  51. data/lib/nokolexbor/version.rb +1 -1
  52. data/lib/nokolexbor.rb +21 -1
  53. data/patches/0001-lexbor-support-text-pseudo-element.patch +1 -1
  54. metadata +7 -4
@@ -26,12 +26,9 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
26
26
  {
27
27
  VALUE id_read = rb_intern("read");
28
28
  VALUE rb_html;
29
- if (rb_respond_to(rb_string_or_io, id_read))
30
- {
29
+ if (rb_respond_to(rb_string_or_io, id_read)) {
31
30
  rb_html = rb_funcall(rb_string_or_io, id_read, 0);
32
- }
33
- else
34
- {
31
+ } else {
35
32
  rb_html = rb_string_or_io;
36
33
  }
37
34
  const char *html_c = StringValuePtr(rb_html);
@@ -40,14 +37,12 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
40
37
  lxb_html_document_t *document;
41
38
 
42
39
  document = lxb_html_document_create();
43
- if (document == NULL)
44
- {
40
+ if (document == NULL) {
45
41
  rb_raise(rb_eRuntimeError, "Error creating document");
46
42
  }
47
43
 
48
44
  lxb_status_t status = lxb_html_document_parse(document, (const lxb_char_t *)html_c, html_len);
49
- if (status != LXB_STATUS_OK)
50
- {
45
+ if (status != LXB_STATUS_OK) {
51
46
  nl_raise_lexbor_error(status);
52
47
  }
53
48
 
@@ -68,9 +63,28 @@ nl_rb_document_unwrap(VALUE rb_doc)
68
63
  return doc;
69
64
  }
70
65
 
66
+ VALUE
67
+ nl_document_get_title(VALUE rb_doc)
68
+ {
69
+ size_t len;
70
+ lxb_char_t *str = lxb_html_document_title(nl_rb_document_unwrap(rb_doc), &len);
71
+ return str == NULL ? rb_str_new("", 0) : rb_utf8_str_new(str, len);
72
+ }
73
+
74
+ VALUE
75
+ nl_document_set_title(VALUE rb_doc, VALUE rb_title)
76
+ {
77
+ const char *c_title = StringValuePtr(rb_title);
78
+ size_t len = RSTRING_LEN(rb_title);
79
+ lxb_char_t *str = lxb_html_document_title_set(nl_rb_document_unwrap(rb_doc), (const lxb_char_t *)c_title, len);
80
+ return Qnil;
81
+ }
82
+
71
83
  void Init_nl_document(void)
72
84
  {
73
85
  cNokolexborDocument = rb_define_class_under(mNokolexbor, "Document", cNokolexborNode);
74
86
  rb_define_singleton_method(cNokolexborDocument, "new", nl_document_new, 0);
75
87
  rb_define_singleton_method(cNokolexborDocument, "parse", nl_document_parse, 1);
88
+ rb_define_method(cNokolexborDocument, "title", nl_document_get_title, 0);
89
+ rb_define_method(cNokolexborDocument, "title=", nl_document_set_title, 1);
76
90
  }