nokogiri 1.11.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1682 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +272 -0
  6. data/bin/nokogiri +118 -0
  7. data/dependencies.yml +74 -0
  8. data/ext/nokogiri/depend +477 -0
  9. data/ext/nokogiri/extconf.rb +836 -0
  10. data/ext/nokogiri/html_document.c +171 -0
  11. data/ext/nokogiri/html_document.h +10 -0
  12. data/ext/nokogiri/html_element_description.c +279 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.c +32 -0
  15. data/ext/nokogiri/html_entity_lookup.h +8 -0
  16. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  17. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  18. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  19. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  20. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  21. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  22. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  23. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  24. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  25. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  26. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  27. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  28. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  29. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  30. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  31. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  32. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  33. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  34. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  35. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  36. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  37. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  38. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  39. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  40. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  41. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  42. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  43. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  44. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  45. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  46. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  47. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  48. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  49. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  66. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  67. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  68. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  69. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  70. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  71. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  72. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  73. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  74. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  75. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  76. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  77. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  78. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  79. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  80. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  81. data/ext/nokogiri/include/libxslt/security.h +104 -0
  82. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  83. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  84. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  85. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  86. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  87. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  88. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  89. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  90. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  91. data/ext/nokogiri/nokogiri.c +135 -0
  92. data/ext/nokogiri/nokogiri.h +130 -0
  93. data/ext/nokogiri/xml_attr.c +103 -0
  94. data/ext/nokogiri/xml_attr.h +9 -0
  95. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  96. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  97. data/ext/nokogiri/xml_cdata.c +62 -0
  98. data/ext/nokogiri/xml_cdata.h +9 -0
  99. data/ext/nokogiri/xml_comment.c +69 -0
  100. data/ext/nokogiri/xml_comment.h +9 -0
  101. data/ext/nokogiri/xml_document.c +622 -0
  102. data/ext/nokogiri/xml_document.h +23 -0
  103. data/ext/nokogiri/xml_document_fragment.c +48 -0
  104. data/ext/nokogiri/xml_document_fragment.h +10 -0
  105. data/ext/nokogiri/xml_dtd.c +202 -0
  106. data/ext/nokogiri/xml_dtd.h +10 -0
  107. data/ext/nokogiri/xml_element_content.c +123 -0
  108. data/ext/nokogiri/xml_element_content.h +10 -0
  109. data/ext/nokogiri/xml_element_decl.c +69 -0
  110. data/ext/nokogiri/xml_element_decl.h +9 -0
  111. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  112. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  113. data/ext/nokogiri/xml_entity_decl.c +110 -0
  114. data/ext/nokogiri/xml_entity_decl.h +10 -0
  115. data/ext/nokogiri/xml_entity_reference.c +52 -0
  116. data/ext/nokogiri/xml_entity_reference.h +9 -0
  117. data/ext/nokogiri/xml_io.c +63 -0
  118. data/ext/nokogiri/xml_io.h +11 -0
  119. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  120. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  121. data/ext/nokogiri/xml_namespace.c +111 -0
  122. data/ext/nokogiri/xml_namespace.h +14 -0
  123. data/ext/nokogiri/xml_node.c +1773 -0
  124. data/ext/nokogiri/xml_node.h +13 -0
  125. data/ext/nokogiri/xml_node_set.c +486 -0
  126. data/ext/nokogiri/xml_node_set.h +12 -0
  127. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  128. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  129. data/ext/nokogiri/xml_reader.c +657 -0
  130. data/ext/nokogiri/xml_reader.h +10 -0
  131. data/ext/nokogiri/xml_relax_ng.c +179 -0
  132. data/ext/nokogiri/xml_relax_ng.h +9 -0
  133. data/ext/nokogiri/xml_sax_parser.c +305 -0
  134. data/ext/nokogiri/xml_sax_parser.h +39 -0
  135. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  136. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  137. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  138. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  139. data/ext/nokogiri/xml_schema.c +276 -0
  140. data/ext/nokogiri/xml_schema.h +9 -0
  141. data/ext/nokogiri/xml_syntax_error.c +64 -0
  142. data/ext/nokogiri/xml_syntax_error.h +13 -0
  143. data/ext/nokogiri/xml_text.c +52 -0
  144. data/ext/nokogiri/xml_text.h +9 -0
  145. data/ext/nokogiri/xml_xpath_context.c +374 -0
  146. data/ext/nokogiri/xml_xpath_context.h +10 -0
  147. data/ext/nokogiri/xslt_stylesheet.c +263 -0
  148. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  149. data/lib/nokogiri.rb +144 -0
  150. data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
  151. data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
  152. data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
  153. data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
  154. data/lib/nokogiri/css.rb +28 -0
  155. data/lib/nokogiri/css/node.rb +53 -0
  156. data/lib/nokogiri/css/parser.rb +751 -0
  157. data/lib/nokogiri/css/parser.y +272 -0
  158. data/lib/nokogiri/css/parser_extras.rb +94 -0
  159. data/lib/nokogiri/css/syntax_error.rb +8 -0
  160. data/lib/nokogiri/css/tokenizer.rb +154 -0
  161. data/lib/nokogiri/css/tokenizer.rex +55 -0
  162. data/lib/nokogiri/css/xpath_visitor.rb +260 -0
  163. data/lib/nokogiri/decorators/slop.rb +43 -0
  164. data/lib/nokogiri/html.rb +38 -0
  165. data/lib/nokogiri/html/builder.rb +36 -0
  166. data/lib/nokogiri/html/document.rb +322 -0
  167. data/lib/nokogiri/html/document_fragment.rb +50 -0
  168. data/lib/nokogiri/html/element_description.rb +24 -0
  169. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  170. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  171. data/lib/nokogiri/html/sax/parser.rb +63 -0
  172. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  173. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  174. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  175. data/lib/nokogiri/syntax_error.rb +5 -0
  176. data/lib/nokogiri/version.rb +3 -0
  177. data/lib/nokogiri/version/constant.rb +5 -0
  178. data/lib/nokogiri/version/info.rb +182 -0
  179. data/lib/nokogiri/xml.rb +76 -0
  180. data/lib/nokogiri/xml/attr.rb +15 -0
  181. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  182. data/lib/nokogiri/xml/builder.rb +447 -0
  183. data/lib/nokogiri/xml/cdata.rb +12 -0
  184. data/lib/nokogiri/xml/character_data.rb +8 -0
  185. data/lib/nokogiri/xml/document.rb +290 -0
  186. data/lib/nokogiri/xml/document_fragment.rb +159 -0
  187. data/lib/nokogiri/xml/dtd.rb +33 -0
  188. data/lib/nokogiri/xml/element_content.rb +37 -0
  189. data/lib/nokogiri/xml/element_decl.rb +14 -0
  190. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  191. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  192. data/lib/nokogiri/xml/namespace.rb +14 -0
  193. data/lib/nokogiri/xml/node.rb +1240 -0
  194. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  195. data/lib/nokogiri/xml/node_set.rb +372 -0
  196. data/lib/nokogiri/xml/notation.rb +7 -0
  197. data/lib/nokogiri/xml/parse_options.rb +127 -0
  198. data/lib/nokogiri/xml/pp.rb +3 -0
  199. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  200. data/lib/nokogiri/xml/pp/node.rb +57 -0
  201. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  202. data/lib/nokogiri/xml/reader.rb +116 -0
  203. data/lib/nokogiri/xml/relax_ng.rb +37 -0
  204. data/lib/nokogiri/xml/sax.rb +5 -0
  205. data/lib/nokogiri/xml/sax/document.rb +172 -0
  206. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  207. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  208. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  209. data/lib/nokogiri/xml/schema.rb +72 -0
  210. data/lib/nokogiri/xml/searchable.rb +239 -0
  211. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  212. data/lib/nokogiri/xml/text.rb +10 -0
  213. data/lib/nokogiri/xml/xpath.rb +11 -0
  214. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  215. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  216. data/lib/nokogiri/xslt.rb +57 -0
  217. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  218. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  219. metadata +499 -0
@@ -0,0 +1,10 @@
1
+ #ifndef NOKOGIRI_XML_XPATH_CONTEXT
2
+ #define NOKOGIRI_XML_XPATH_CONTEXT
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_xpath_context();
7
+ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name) ;
8
+
9
+ extern VALUE cNokogiriXmlXpathContext;
10
+ #endif
@@ -0,0 +1,263 @@
1
+ #include <xslt_stylesheet.h>
2
+
3
+ #include <libxslt/xsltInternals.h>
4
+ #include <libxslt/xsltutils.h>
5
+ #include <libxslt/transform.h>
6
+ #include <libexslt/exslt.h>
7
+
8
+ VALUE xslt;
9
+
10
+ static void mark(nokogiriXsltStylesheetTuple *wrapper)
11
+ {
12
+ rb_gc_mark(wrapper->func_instances);
13
+ }
14
+
15
+ static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
16
+ {
17
+ xsltStylesheetPtr doc = wrapper->ss;
18
+
19
+ NOKOGIRI_DEBUG_START(doc);
20
+ xsltFreeStylesheet(doc); /* commented out for now. */
21
+ NOKOGIRI_DEBUG_END(doc);
22
+
23
+ free(wrapper);
24
+ }
25
+
26
+ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
27
+ {
28
+ char * message;
29
+
30
+ va_list args;
31
+ va_start(args, msg);
32
+ vasprintf(&message, msg, args);
33
+ va_end(args);
34
+
35
+ rb_str_cat2((VALUE)ctx, message);
36
+
37
+ free(message);
38
+ }
39
+
40
+ VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
41
+ {
42
+ VALUE self;
43
+ nokogiriXsltStylesheetTuple *wrapper;
44
+
45
+ self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
46
+ mark, dealloc, wrapper);
47
+
48
+ ss->_private = (void *)self;
49
+ wrapper->ss = ss;
50
+ wrapper->func_instances = rb_ary_new();
51
+
52
+ return self;
53
+ }
54
+
55
+ /*
56
+ * call-seq:
57
+ * parse_stylesheet_doc(document)
58
+ *
59
+ * Parse a stylesheet from +document+.
60
+ */
61
+ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
62
+ {
63
+ xmlDocPtr xml, xml_cpy;
64
+ VALUE errstr, exception;
65
+ xsltStylesheetPtr ss ;
66
+ Data_Get_Struct(xmldocobj, xmlDoc, xml);
67
+ exsltRegisterAll();
68
+
69
+ errstr = rb_str_new(0, 0);
70
+ xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
71
+
72
+ xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
73
+ ss = xsltParseStylesheetDoc(xml_cpy);
74
+
75
+ xsltSetGenericErrorFunc(NULL, NULL);
76
+
77
+ if (!ss) {
78
+ xmlFreeDoc(xml_cpy);
79
+ exception = rb_exc_new3(rb_eRuntimeError, errstr);
80
+ rb_exc_raise(exception);
81
+ }
82
+
83
+ return Nokogiri_wrap_xslt_stylesheet(ss);
84
+ }
85
+
86
+
87
+ /*
88
+ * call-seq:
89
+ * serialize(document)
90
+ *
91
+ * Serialize +document+ to an xml string.
92
+ */
93
+ static VALUE serialize(VALUE self, VALUE xmlobj)
94
+ {
95
+ xmlDocPtr xml ;
96
+ nokogiriXsltStylesheetTuple *wrapper;
97
+ xmlChar* doc_ptr ;
98
+ int doc_len ;
99
+ VALUE rval ;
100
+
101
+ Data_Get_Struct(xmlobj, xmlDoc, xml);
102
+ Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
103
+ xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
104
+ rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
105
+ xmlFree(doc_ptr);
106
+ return rval ;
107
+ }
108
+
109
+ /*
110
+ * call-seq:
111
+ * transform(document, params = [])
112
+ *
113
+ * Apply an XSLT stylesheet to an XML::Document.
114
+ * +params+ is an array of strings used as XSLT parameters.
115
+ * returns Nokogiri::XML::Document
116
+ *
117
+ * Example:
118
+ *
119
+ * doc = Nokogiri::XML(File.read(ARGV[0]))
120
+ * xslt = Nokogiri::XSLT(File.read(ARGV[1]))
121
+ * puts xslt.transform(doc, ['key', 'value'])
122
+ *
123
+ */
124
+ static VALUE transform(int argc, VALUE* argv, VALUE self)
125
+ {
126
+ VALUE xmldoc, paramobj, errstr, exception ;
127
+ xmlDocPtr xml ;
128
+ xmlDocPtr result ;
129
+ nokogiriXsltStylesheetTuple *wrapper;
130
+ const char** params ;
131
+ long param_len, j ;
132
+ int parse_error_occurred ;
133
+
134
+ rb_scan_args(argc, argv, "11", &xmldoc, &paramobj);
135
+ if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
136
+ if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
137
+ rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
138
+
139
+ /* handle hashes as arguments. */
140
+ if(T_HASH == TYPE(paramobj)) {
141
+ paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
142
+ paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
143
+ }
144
+
145
+ Check_Type(paramobj, T_ARRAY);
146
+
147
+ Data_Get_Struct(xmldoc, xmlDoc, xml);
148
+ Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
149
+
150
+ param_len = RARRAY_LEN(paramobj);
151
+ params = calloc((size_t)param_len+1, sizeof(char*));
152
+ for (j = 0 ; j < param_len ; j++) {
153
+ VALUE entry = rb_ary_entry(paramobj, j);
154
+ const char * ptr = StringValueCStr(entry);
155
+ params[j] = ptr;
156
+ }
157
+ params[param_len] = 0 ;
158
+
159
+ errstr = rb_str_new(0, 0);
160
+ xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
161
+ xmlSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
162
+
163
+ result = xsltApplyStylesheet(wrapper->ss, xml, params);
164
+ free(params);
165
+
166
+ xsltSetGenericErrorFunc(NULL, NULL);
167
+ xmlSetGenericErrorFunc(NULL, NULL);
168
+
169
+ parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
170
+
171
+ if (parse_error_occurred) {
172
+ exception = rb_exc_new3(rb_eRuntimeError, errstr);
173
+ rb_exc_raise(exception);
174
+ }
175
+
176
+ return Nokogiri_wrap_xml_document((VALUE)0, result) ;
177
+ }
178
+
179
+ static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
180
+ {
181
+ VALUE handler;
182
+ const char *function_name;
183
+ xsltTransformContextPtr transform;
184
+ const xmlChar *functionURI;
185
+
186
+ transform = xsltXPathGetTransformContext(ctxt);
187
+ functionURI = ctxt->context->functionURI;
188
+ handler = (VALUE)xsltGetExtData(transform, functionURI);
189
+ function_name = (const char*)(ctxt->context->function);
190
+
191
+ Nokogiri_marshal_xpath_funcall_and_return_values(ctxt, nargs, handler, (const char*)function_name);
192
+ }
193
+
194
+ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
195
+ {
196
+ VALUE modules = rb_iv_get(xslt, "@modules");
197
+ VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
198
+ VALUE args = { Qfalse };
199
+ VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
200
+ VALUE inst;
201
+ nokogiriXsltStylesheetTuple *wrapper;
202
+ int i;
203
+
204
+ for(i = 0; i < RARRAY_LEN(methods); i++) {
205
+ VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
206
+ xsltRegisterExtFunction(ctxt,
207
+ (unsigned char *)StringValueCStr(method_name), uri, method_caller);
208
+ }
209
+
210
+ Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
211
+ wrapper);
212
+ inst = rb_class_new_instance(0, NULL, obj);
213
+ rb_ary_push(wrapper->func_instances, inst);
214
+
215
+ return (void *)inst;
216
+ }
217
+
218
+ static void shutdownFunc(xsltTransformContextPtr ctxt,
219
+ const xmlChar *uri, void *data)
220
+ {
221
+ nokogiriXsltStylesheetTuple *wrapper;
222
+
223
+ Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
224
+ wrapper);
225
+
226
+ rb_ary_clear(wrapper->func_instances);
227
+ }
228
+
229
+ /*
230
+ * call-seq:
231
+ * register(uri, custom_handler_class)
232
+ *
233
+ * Register a class that implements custom XSLT transformation functions.
234
+ */
235
+ static VALUE registr(VALUE self, VALUE uri, VALUE obj)
236
+ {
237
+ VALUE modules = rb_iv_get(self, "@modules");
238
+ if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
239
+
240
+ rb_hash_aset(modules, uri, obj);
241
+ xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc);
242
+ return self;
243
+ }
244
+
245
+ VALUE cNokogiriXsltStylesheet ;
246
+ void init_xslt_stylesheet()
247
+ {
248
+ VALUE nokogiri;
249
+ VALUE klass;
250
+
251
+ nokogiri = rb_define_module("Nokogiri");
252
+ xslt = rb_define_module_under(nokogiri, "XSLT");
253
+ klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
254
+
255
+ rb_iv_set(xslt, "@modules", rb_hash_new());
256
+
257
+ cNokogiriXsltStylesheet = klass;
258
+
259
+ rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
260
+ rb_define_singleton_method(xslt, "register", registr, 2);
261
+ rb_define_method(klass, "serialize", serialize, 1);
262
+ rb_define_method(klass, "transform", transform, -1);
263
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef NOKOGIRI_XSLT_STYLESHEET
2
+ #define NOKOGIRI_XSLT_STYLESHEET
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xslt_stylesheet();
7
+
8
+ extern VALUE cNokogiriXsltStylesheet ;
9
+
10
+ typedef struct _nokogiriXsltStylesheetTuple {
11
+ xsltStylesheetPtr ss;
12
+ VALUE func_instances;
13
+ } nokogiriXsltStylesheetTuple;
14
+ #endif
@@ -0,0 +1,144 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ # Modify the PATH on windows so that the external DLLs will get loaded.
4
+
5
+ require 'rbconfig'
6
+
7
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
8
+ require 'nokogiri/jruby/dependencies'
9
+ end
10
+
11
+ begin
12
+ RUBY_VERSION =~ /(\d+\.\d+)/
13
+ require "nokogiri/#{$1}/nokogiri"
14
+ rescue LoadError => e
15
+ if e.message =~ /GLIBC/
16
+ warn <<~EOM
17
+
18
+ ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:
19
+
20
+ #{e.message}
21
+
22
+ If that's the case, then please install Nokogiri via the `ruby` platform gem:
23
+ gem install nokogiri --platform=ruby
24
+ or:
25
+ bundle config set force_ruby_platform true
26
+
27
+ Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.
28
+
29
+ EOM
30
+ raise e
31
+ end
32
+ require 'nokogiri/nokogiri'
33
+ end
34
+ require 'nokogiri/version'
35
+ require 'nokogiri/syntax_error'
36
+ require 'nokogiri/xml'
37
+ require 'nokogiri/xslt'
38
+ require 'nokogiri/html'
39
+ require 'nokogiri/decorators/slop'
40
+ require 'nokogiri/css'
41
+ require 'nokogiri/html/builder'
42
+
43
+ # Nokogiri parses and searches XML/HTML very quickly, and also has
44
+ # correctly implemented CSS3 selector support as well as XPath 1.0
45
+ # support.
46
+ #
47
+ # Parsing a document returns either a Nokogiri::XML::Document, or a
48
+ # Nokogiri::HTML::Document depending on the kind of document you parse.
49
+ #
50
+ # Here is an example:
51
+ #
52
+ # require 'nokogiri'
53
+ # require 'open-uri'
54
+ #
55
+ # # Get a Nokogiri::HTML:Document for the page we’re interested in...
56
+ #
57
+ # doc = Nokogiri::HTML(URI.open('http://www.google.com/search?q=tenderlove'))
58
+ #
59
+ # # Do funky things with it using Nokogiri::XML::Node methods...
60
+ #
61
+ # ####
62
+ # # Search for nodes by css
63
+ # doc.css('h3.r a.l').each do |link|
64
+ # puts link.content
65
+ # end
66
+ #
67
+ # See Nokogiri::XML::Searchable#css for more information about CSS searching.
68
+ # See Nokogiri::XML::Searchable#xpath for more information about XPath searching.
69
+ module Nokogiri
70
+ class << self
71
+ ###
72
+ # Parse an HTML or XML document. +string+ contains the document.
73
+ def parse string, url = nil, encoding = nil, options = nil
74
+ if string.respond_to?(:read) ||
75
+ /^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
76
+ # Expect an HTML indicator to appear within the first 512
77
+ # characters of a document. (<?xml ?> + <?xml-stylesheet ?>
78
+ # shouldn't be that long)
79
+ Nokogiri.HTML(string, url, encoding,
80
+ options || XML::ParseOptions::DEFAULT_HTML)
81
+ else
82
+ Nokogiri.XML(string, url, encoding,
83
+ options || XML::ParseOptions::DEFAULT_XML)
84
+ end.tap { |doc|
85
+ yield doc if block_given?
86
+ }
87
+ end
88
+
89
+ ###
90
+ # Create a new Nokogiri::XML::DocumentFragment
91
+ def make input = nil, opts = {}, &blk
92
+ if input
93
+ Nokogiri::HTML.fragment(input).children.first
94
+ else
95
+ Nokogiri(&blk)
96
+ end
97
+ end
98
+
99
+ ###
100
+ # Parse a document and add the Slop decorator. The Slop decorator
101
+ # implements method_missing such that methods may be used instead of CSS
102
+ # or XPath. For example:
103
+ #
104
+ # doc = Nokogiri::Slop(<<-eohtml)
105
+ # <html>
106
+ # <body>
107
+ # <p>first</p>
108
+ # <p>second</p>
109
+ # </body>
110
+ # </html>
111
+ # eohtml
112
+ # assert_equal('second', doc.html.body.p[1].text)
113
+ #
114
+ def Slop(*args, &block)
115
+ Nokogiri(*args, &block).slop!
116
+ end
117
+
118
+ def install_default_aliases
119
+ # Make sure to support some popular encoding aliases not known by
120
+ # all iconv implementations.
121
+ {
122
+ 'Windows-31J' => 'CP932', # Windows-31J is the IANA registered name of CP932.
123
+ }.each { |alias_name, name|
124
+ EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
125
+ }
126
+ end
127
+ end
128
+
129
+ Nokogiri.install_default_aliases
130
+ end
131
+
132
+ ###
133
+ # Parse a document contained in +args+. Nokogiri will try to guess what
134
+ # type of document you are attempting to parse. For more information, see
135
+ # Nokogiri.parse
136
+ #
137
+ # To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
138
+ def Nokogiri(*args, &block)
139
+ if block_given?
140
+ Nokogiri::HTML::Builder.new(&block).doc.root
141
+ else
142
+ Nokogiri.parse(*args)
143
+ end
144
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri/css/node'
3
+ require 'nokogiri/css/xpath_visitor'
4
+ x = $-w
5
+ $-w = false
6
+ require 'nokogiri/css/parser'
7
+ $-w = x
8
+
9
+ require 'nokogiri/css/tokenizer'
10
+ require 'nokogiri/css/syntax_error'
11
+
12
+ module Nokogiri
13
+ module CSS
14
+ class << self
15
+ ###
16
+ # Parse this CSS selector in +selector+. Returns an AST.
17
+ def parse selector
18
+ Parser.new.parse selector
19
+ end
20
+
21
+ ###
22
+ # Get the XPath for +selector+.
23
+ def xpath_for selector, options={}
24
+ Parser.new(options[:ns] || {}).xpath_for selector, options
25
+ end
26
+ end
27
+ end
28
+ end