nokogiri 1.6.2.rc1-x64-mingw32

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 (263) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +26 -0
  3. data/.editorconfig +17 -0
  4. data/.gemtest +0 -0
  5. data/.travis.yml +25 -0
  6. data/CHANGELOG.ja.rdoc +857 -0
  7. data/CHANGELOG.rdoc +880 -0
  8. data/C_CODING_STYLE.rdoc +33 -0
  9. data/Gemfile +21 -0
  10. data/Manifest.txt +371 -0
  11. data/README.ja.rdoc +112 -0
  12. data/README.rdoc +180 -0
  13. data/ROADMAP.md +89 -0
  14. data/Rakefile +351 -0
  15. data/STANDARD_RESPONSES.md +47 -0
  16. data/Y_U_NO_GEMSPEC.md +155 -0
  17. data/bin/nokogiri +78 -0
  18. data/build_all +130 -0
  19. data/dependencies.yml +4 -0
  20. data/ext/nokogiri/depend +358 -0
  21. data/ext/nokogiri/extconf.rb +453 -0
  22. data/ext/nokogiri/html_document.c +170 -0
  23. data/ext/nokogiri/html_document.h +10 -0
  24. data/ext/nokogiri/html_element_description.c +279 -0
  25. data/ext/nokogiri/html_element_description.h +10 -0
  26. data/ext/nokogiri/html_entity_lookup.c +32 -0
  27. data/ext/nokogiri/html_entity_lookup.h +8 -0
  28. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  29. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  30. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  31. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  32. data/ext/nokogiri/nokogiri.c +148 -0
  33. data/ext/nokogiri/nokogiri.h +164 -0
  34. data/ext/nokogiri/xml_attr.c +94 -0
  35. data/ext/nokogiri/xml_attr.h +9 -0
  36. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  37. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  38. data/ext/nokogiri/xml_cdata.c +56 -0
  39. data/ext/nokogiri/xml_cdata.h +9 -0
  40. data/ext/nokogiri/xml_comment.c +54 -0
  41. data/ext/nokogiri/xml_comment.h +9 -0
  42. data/ext/nokogiri/xml_document.c +577 -0
  43. data/ext/nokogiri/xml_document.h +23 -0
  44. data/ext/nokogiri/xml_document_fragment.c +48 -0
  45. data/ext/nokogiri/xml_document_fragment.h +10 -0
  46. data/ext/nokogiri/xml_dtd.c +202 -0
  47. data/ext/nokogiri/xml_dtd.h +10 -0
  48. data/ext/nokogiri/xml_element_content.c +123 -0
  49. data/ext/nokogiri/xml_element_content.h +10 -0
  50. data/ext/nokogiri/xml_element_decl.c +69 -0
  51. data/ext/nokogiri/xml_element_decl.h +9 -0
  52. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  53. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  54. data/ext/nokogiri/xml_entity_decl.c +110 -0
  55. data/ext/nokogiri/xml_entity_decl.h +10 -0
  56. data/ext/nokogiri/xml_entity_reference.c +52 -0
  57. data/ext/nokogiri/xml_entity_reference.h +9 -0
  58. data/ext/nokogiri/xml_io.c +56 -0
  59. data/ext/nokogiri/xml_io.h +11 -0
  60. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  61. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  62. data/ext/nokogiri/xml_namespace.c +78 -0
  63. data/ext/nokogiri/xml_namespace.h +13 -0
  64. data/ext/nokogiri/xml_node.c +1541 -0
  65. data/ext/nokogiri/xml_node.h +13 -0
  66. data/ext/nokogiri/xml_node_set.c +467 -0
  67. data/ext/nokogiri/xml_node_set.h +14 -0
  68. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  69. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  70. data/ext/nokogiri/xml_reader.c +681 -0
  71. data/ext/nokogiri/xml_reader.h +10 -0
  72. data/ext/nokogiri/xml_relax_ng.c +161 -0
  73. data/ext/nokogiri/xml_relax_ng.h +9 -0
  74. data/ext/nokogiri/xml_sax_parser.c +312 -0
  75. data/ext/nokogiri/xml_sax_parser.h +39 -0
  76. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  77. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  78. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  79. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  80. data/ext/nokogiri/xml_schema.c +205 -0
  81. data/ext/nokogiri/xml_schema.h +9 -0
  82. data/ext/nokogiri/xml_syntax_error.c +63 -0
  83. data/ext/nokogiri/xml_syntax_error.h +13 -0
  84. data/ext/nokogiri/xml_text.c +52 -0
  85. data/ext/nokogiri/xml_text.h +9 -0
  86. data/ext/nokogiri/xml_xpath_context.c +307 -0
  87. data/ext/nokogiri/xml_xpath_context.h +10 -0
  88. data/ext/nokogiri/xslt_stylesheet.c +270 -0
  89. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  90. data/lib/nokogiri.rb +137 -0
  91. data/lib/nokogiri/2.0/nokogiri.so +0 -0
  92. data/lib/nokogiri/2.1/nokogiri.so +0 -0
  93. data/lib/nokogiri/css.rb +27 -0
  94. data/lib/nokogiri/css/node.rb +52 -0
  95. data/lib/nokogiri/css/parser.rb +715 -0
  96. data/lib/nokogiri/css/parser.y +249 -0
  97. data/lib/nokogiri/css/parser_extras.rb +91 -0
  98. data/lib/nokogiri/css/syntax_error.rb +7 -0
  99. data/lib/nokogiri/css/tokenizer.rb +152 -0
  100. data/lib/nokogiri/css/tokenizer.rex +55 -0
  101. data/lib/nokogiri/css/xpath_visitor.rb +219 -0
  102. data/lib/nokogiri/decorators/slop.rb +35 -0
  103. data/lib/nokogiri/html.rb +37 -0
  104. data/lib/nokogiri/html/builder.rb +35 -0
  105. data/lib/nokogiri/html/document.rb +333 -0
  106. data/lib/nokogiri/html/document_fragment.rb +41 -0
  107. data/lib/nokogiri/html/element_description.rb +23 -0
  108. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  109. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  110. data/lib/nokogiri/html/sax/parser.rb +52 -0
  111. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  112. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  113. data/lib/nokogiri/syntax_error.rb +4 -0
  114. data/lib/nokogiri/version.rb +106 -0
  115. data/lib/nokogiri/xml.rb +73 -0
  116. data/lib/nokogiri/xml/attr.rb +14 -0
  117. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  118. data/lib/nokogiri/xml/builder.rb +443 -0
  119. data/lib/nokogiri/xml/cdata.rb +11 -0
  120. data/lib/nokogiri/xml/character_data.rb +7 -0
  121. data/lib/nokogiri/xml/document.rb +279 -0
  122. data/lib/nokogiri/xml/document_fragment.rb +112 -0
  123. data/lib/nokogiri/xml/dtd.rb +32 -0
  124. data/lib/nokogiri/xml/element_content.rb +36 -0
  125. data/lib/nokogiri/xml/element_decl.rb +13 -0
  126. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  127. data/lib/nokogiri/xml/namespace.rb +13 -0
  128. data/lib/nokogiri/xml/node.rb +982 -0
  129. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  130. data/lib/nokogiri/xml/node_set.rb +355 -0
  131. data/lib/nokogiri/xml/notation.rb +6 -0
  132. data/lib/nokogiri/xml/parse_options.rb +98 -0
  133. data/lib/nokogiri/xml/pp.rb +2 -0
  134. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  135. data/lib/nokogiri/xml/pp/node.rb +56 -0
  136. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  137. data/lib/nokogiri/xml/reader.rb +112 -0
  138. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  139. data/lib/nokogiri/xml/sax.rb +4 -0
  140. data/lib/nokogiri/xml/sax/document.rb +171 -0
  141. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  142. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  143. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  144. data/lib/nokogiri/xml/schema.rb +63 -0
  145. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  146. data/lib/nokogiri/xml/text.rb +9 -0
  147. data/lib/nokogiri/xml/xpath.rb +10 -0
  148. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  149. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  150. data/lib/nokogiri/xslt.rb +56 -0
  151. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  152. data/lib/xsd/xmlparser/nokogiri.rb +102 -0
  153. data/suppressions/README.txt +1 -0
  154. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  155. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  156. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  157. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  158. data/tasks/nokogiri.org.rb +24 -0
  159. data/tasks/test.rb +95 -0
  160. data/test/css/test_nthiness.rb +222 -0
  161. data/test/css/test_parser.rb +358 -0
  162. data/test/css/test_tokenizer.rb +198 -0
  163. data/test/css/test_xpath_visitor.rb +96 -0
  164. data/test/decorators/test_slop.rb +16 -0
  165. data/test/files/2ch.html +108 -0
  166. data/test/files/address_book.rlx +12 -0
  167. data/test/files/address_book.xml +10 -0
  168. data/test/files/atom.xml +344 -0
  169. data/test/files/bar/bar.xsd +4 -0
  170. data/test/files/bogus.xml +0 -0
  171. data/test/files/dont_hurt_em_why.xml +422 -0
  172. data/test/files/encoding.html +82 -0
  173. data/test/files/encoding.xhtml +84 -0
  174. data/test/files/exslt.xml +8 -0
  175. data/test/files/exslt.xslt +35 -0
  176. data/test/files/foo/foo.xsd +4 -0
  177. data/test/files/metacharset.html +10 -0
  178. data/test/files/noencoding.html +47 -0
  179. data/test/files/po.xml +32 -0
  180. data/test/files/po.xsd +66 -0
  181. data/test/files/saml/saml20assertion_schema.xsd +283 -0
  182. data/test/files/saml/saml20protocol_schema.xsd +302 -0
  183. data/test/files/saml/xenc_schema.xsd +146 -0
  184. data/test/files/saml/xmldsig_schema.xsd +318 -0
  185. data/test/files/shift_jis.html +10 -0
  186. data/test/files/shift_jis.xml +5 -0
  187. data/test/files/shift_jis_no_charset.html +9 -0
  188. data/test/files/snuggles.xml +3 -0
  189. data/test/files/staff.dtd +10 -0
  190. data/test/files/staff.xml +59 -0
  191. data/test/files/staff.xslt +32 -0
  192. data/test/files/test_document_url/bar.xml +2 -0
  193. data/test/files/test_document_url/document.dtd +4 -0
  194. data/test/files/test_document_url/document.xml +6 -0
  195. data/test/files/tlm.html +850 -0
  196. data/test/files/to_be_xincluded.xml +2 -0
  197. data/test/files/valid_bar.xml +2 -0
  198. data/test/files/xinclude.xml +4 -0
  199. data/test/helper.rb +164 -0
  200. data/test/html/sax/test_parser.rb +141 -0
  201. data/test/html/sax/test_parser_context.rb +46 -0
  202. data/test/html/test_builder.rb +164 -0
  203. data/test/html/test_document.rb +619 -0
  204. data/test/html/test_document_encoding.rb +148 -0
  205. data/test/html/test_document_fragment.rb +261 -0
  206. data/test/html/test_element_description.rb +105 -0
  207. data/test/html/test_named_characters.rb +14 -0
  208. data/test/html/test_node.rb +196 -0
  209. data/test/html/test_node_encoding.rb +27 -0
  210. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
  211. data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
  212. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  213. data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
  214. data/test/namespaces/test_namespaces_in_parsed_doc.rb +66 -0
  215. data/test/test_convert_xpath.rb +135 -0
  216. data/test/test_css_cache.rb +45 -0
  217. data/test/test_encoding_handler.rb +46 -0
  218. data/test/test_memory_leak.rb +156 -0
  219. data/test/test_nokogiri.rb +138 -0
  220. data/test/test_reader.rb +558 -0
  221. data/test/test_soap4r_sax.rb +52 -0
  222. data/test/test_xslt_transforms.rb +279 -0
  223. data/test/xml/node/test_save_options.rb +28 -0
  224. data/test/xml/node/test_subclass.rb +44 -0
  225. data/test/xml/sax/test_parser.rb +382 -0
  226. data/test/xml/sax/test_parser_context.rb +115 -0
  227. data/test/xml/sax/test_push_parser.rb +157 -0
  228. data/test/xml/test_attr.rb +64 -0
  229. data/test/xml/test_attribute_decl.rb +86 -0
  230. data/test/xml/test_builder.rb +315 -0
  231. data/test/xml/test_c14n.rb +161 -0
  232. data/test/xml/test_cdata.rb +48 -0
  233. data/test/xml/test_comment.rb +29 -0
  234. data/test/xml/test_document.rb +934 -0
  235. data/test/xml/test_document_encoding.rb +28 -0
  236. data/test/xml/test_document_fragment.rb +228 -0
  237. data/test/xml/test_dtd.rb +187 -0
  238. data/test/xml/test_dtd_encoding.rb +33 -0
  239. data/test/xml/test_element_content.rb +56 -0
  240. data/test/xml/test_element_decl.rb +73 -0
  241. data/test/xml/test_entity_decl.rb +122 -0
  242. data/test/xml/test_entity_reference.rb +245 -0
  243. data/test/xml/test_namespace.rb +95 -0
  244. data/test/xml/test_node.rb +1155 -0
  245. data/test/xml/test_node_attributes.rb +113 -0
  246. data/test/xml/test_node_encoding.rb +107 -0
  247. data/test/xml/test_node_inheritance.rb +32 -0
  248. data/test/xml/test_node_reparenting.rb +374 -0
  249. data/test/xml/test_node_set.rb +755 -0
  250. data/test/xml/test_parse_options.rb +64 -0
  251. data/test/xml/test_processing_instruction.rb +30 -0
  252. data/test/xml/test_reader_encoding.rb +142 -0
  253. data/test/xml/test_relax_ng.rb +60 -0
  254. data/test/xml/test_schema.rb +129 -0
  255. data/test/xml/test_syntax_error.rb +12 -0
  256. data/test/xml/test_text.rb +45 -0
  257. data/test/xml/test_unparented_node.rb +422 -0
  258. data/test/xml/test_xinclude.rb +83 -0
  259. data/test/xml/test_xpath.rb +376 -0
  260. data/test/xslt/test_custom_functions.rb +133 -0
  261. data/test/xslt/test_exception_handling.rb +37 -0
  262. data/test_all +81 -0
  263. metadata +601 -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,270 @@
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
+ int vasprintf (char **strp, const char *fmt, va_list ap);
11
+ void vasprintf_free (void *p);
12
+
13
+ static void mark(nokogiriXsltStylesheetTuple *wrapper)
14
+ {
15
+ rb_gc_mark(wrapper->func_instances);
16
+ }
17
+
18
+ static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
19
+ {
20
+ xsltStylesheetPtr doc = wrapper->ss;
21
+
22
+ NOKOGIRI_DEBUG_START(doc);
23
+ xsltFreeStylesheet(doc); /* commented out for now. */
24
+ NOKOGIRI_DEBUG_END(doc);
25
+
26
+ free(wrapper);
27
+ }
28
+
29
+ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
30
+ {
31
+ char * message;
32
+
33
+ va_list args;
34
+ va_start(args, msg);
35
+ vasprintf(&message, msg, args);
36
+ va_end(args);
37
+
38
+ rb_str_cat2((VALUE)ctx, message);
39
+
40
+ vasprintf_free(message);
41
+ }
42
+
43
+ VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
44
+ {
45
+ VALUE self;
46
+ nokogiriXsltStylesheetTuple *wrapper;
47
+
48
+ self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
49
+ mark, dealloc, wrapper);
50
+
51
+ ss->_private = (void *)self;
52
+ wrapper->ss = ss;
53
+ wrapper->func_instances = rb_ary_new();
54
+
55
+ return self;
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * parse_stylesheet_doc(document)
61
+ *
62
+ * Parse a stylesheet from +document+.
63
+ */
64
+ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
65
+ {
66
+ xmlDocPtr xml, xml_cpy;
67
+ VALUE errstr, exception;
68
+ xsltStylesheetPtr ss ;
69
+ Data_Get_Struct(xmldocobj, xmlDoc, xml);
70
+ exsltRegisterAll();
71
+
72
+ errstr = rb_str_new(0, 0);
73
+ xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
74
+
75
+ xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
76
+ ss = xsltParseStylesheetDoc(xml_cpy);
77
+
78
+ xsltSetGenericErrorFunc(NULL, NULL);
79
+
80
+ if (!ss) {
81
+ xmlFreeDoc(xml_cpy);
82
+ exception = rb_exc_new3(rb_eRuntimeError, errstr);
83
+ rb_exc_raise(exception);
84
+ }
85
+
86
+ return Nokogiri_wrap_xslt_stylesheet(ss);
87
+ }
88
+
89
+
90
+ /*
91
+ * call-seq:
92
+ * serialize(document)
93
+ *
94
+ * Serialize +document+ to an xml string.
95
+ */
96
+ static VALUE serialize(VALUE self, VALUE xmlobj)
97
+ {
98
+ xmlDocPtr xml ;
99
+ nokogiriXsltStylesheetTuple *wrapper;
100
+ xmlChar* doc_ptr ;
101
+ int doc_len ;
102
+ VALUE rval ;
103
+
104
+ Data_Get_Struct(xmlobj, xmlDoc, xml);
105
+ Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
106
+ xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
107
+ rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
108
+ xmlFree(doc_ptr);
109
+ return rval ;
110
+ }
111
+
112
+ static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, ...)
113
+ {
114
+ }
115
+
116
+ /*
117
+ * call-seq:
118
+ * transform(document, params = [])
119
+ *
120
+ * Apply an XSLT stylesheet to an XML::Document.
121
+ * +params+ is an array of strings used as XSLT parameters.
122
+ * returns Nokogiri::XML::Document
123
+ *
124
+ * Example:
125
+ *
126
+ * doc = Nokogiri::XML(File.read(ARGV[0]))
127
+ * xslt = Nokogiri::XSLT(File.read(ARGV[1]))
128
+ * puts xslt.transform(doc, ['key', 'value'])
129
+ *
130
+ */
131
+ static VALUE transform(int argc, VALUE* argv, VALUE self)
132
+ {
133
+ VALUE xmldoc, paramobj, errstr, exception ;
134
+ xmlDocPtr xml ;
135
+ xmlDocPtr result ;
136
+ nokogiriXsltStylesheetTuple *wrapper;
137
+ const char** params ;
138
+ long param_len, j ;
139
+ int parse_error_occurred ;
140
+
141
+ rb_scan_args(argc, argv, "11", &xmldoc, &paramobj);
142
+ if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
143
+ if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
144
+ rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
145
+
146
+ /* handle hashes as arguments. */
147
+ if(T_HASH == TYPE(paramobj)) {
148
+ paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
149
+ paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
150
+ }
151
+
152
+ Check_Type(paramobj, T_ARRAY);
153
+
154
+ Data_Get_Struct(xmldoc, xmlDoc, xml);
155
+ Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
156
+
157
+ param_len = RARRAY_LEN(paramobj);
158
+ params = calloc((size_t)param_len+1, sizeof(char*));
159
+ for (j = 0 ; j < param_len ; j++) {
160
+ VALUE entry = rb_ary_entry(paramobj, j);
161
+ const char * ptr = StringValuePtr(entry);
162
+ params[j] = ptr;
163
+ }
164
+ params[param_len] = 0 ;
165
+
166
+ errstr = rb_str_new(0, 0);
167
+ xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
168
+ xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)&swallow_superfluous_xml_errors);
169
+
170
+ result = xsltApplyStylesheet(wrapper->ss, xml, params);
171
+ free(params);
172
+
173
+ xsltSetGenericErrorFunc(NULL, NULL);
174
+ xmlSetGenericErrorFunc(NULL, NULL);
175
+
176
+ parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
177
+
178
+ if (parse_error_occurred) {
179
+ exception = rb_exc_new3(rb_eRuntimeError, errstr);
180
+ rb_exc_raise(exception);
181
+ }
182
+
183
+ return Nokogiri_wrap_xml_document((VALUE)0, result) ;
184
+ }
185
+
186
+ static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
187
+ {
188
+ VALUE handler;
189
+ const char *function_name;
190
+ xsltTransformContextPtr transform;
191
+ const xmlChar *functionURI;
192
+
193
+ transform = xsltXPathGetTransformContext(ctxt);
194
+ functionURI = ctxt->context->functionURI;
195
+ handler = (VALUE)xsltGetExtData(transform, functionURI);
196
+ function_name = (const char*)(ctxt->context->function);
197
+
198
+ Nokogiri_marshal_xpath_funcall_and_return_values(ctxt, nargs, handler, (const char*)function_name);
199
+ }
200
+
201
+ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
202
+ {
203
+ VALUE modules = rb_iv_get(xslt, "@modules");
204
+ VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
205
+ VALUE args = { Qfalse };
206
+ VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
207
+ VALUE inst;
208
+ nokogiriXsltStylesheetTuple *wrapper;
209
+ int i;
210
+
211
+ for(i = 0; i < RARRAY_LEN(methods); i++) {
212
+ VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
213
+ xsltRegisterExtFunction(ctxt,
214
+ (unsigned char *)StringValuePtr(method_name), uri, method_caller);
215
+ }
216
+
217
+ Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
218
+ wrapper);
219
+ inst = rb_class_new_instance(0, NULL, obj);
220
+ rb_ary_push(wrapper->func_instances, inst);
221
+
222
+ return (void *)inst;
223
+ }
224
+
225
+ static void shutdownFunc(xsltTransformContextPtr ctxt,
226
+ const xmlChar *uri, void *data)
227
+ {
228
+ nokogiriXsltStylesheetTuple *wrapper;
229
+
230
+ Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
231
+ wrapper);
232
+
233
+ rb_ary_clear(wrapper->func_instances);
234
+ }
235
+
236
+ /*
237
+ * call-seq:
238
+ * register(uri, custom_handler_class)
239
+ *
240
+ * Register a class that implements custom XSLT transformation functions.
241
+ */
242
+ static VALUE registr(VALUE self, VALUE uri, VALUE obj)
243
+ {
244
+ VALUE modules = rb_iv_get(self, "@modules");
245
+ if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
246
+
247
+ rb_hash_aset(modules, uri, obj);
248
+ xsltRegisterExtModule((unsigned char *)StringValuePtr(uri), initFunc, shutdownFunc);
249
+ return self;
250
+ }
251
+
252
+ VALUE cNokogiriXsltStylesheet ;
253
+ void init_xslt_stylesheet()
254
+ {
255
+ VALUE nokogiri;
256
+ VALUE klass;
257
+
258
+ nokogiri = rb_define_module("Nokogiri");
259
+ xslt = rb_define_module_under(nokogiri, "XSLT");
260
+ klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
261
+
262
+ rb_iv_set(xslt, "@modules", rb_hash_new());
263
+
264
+ cNokogiriXsltStylesheet = klass;
265
+
266
+ rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
267
+ rb_define_singleton_method(xslt, "register", registr, 2);
268
+ rb_define_method(klass, "serialize", serialize, 1);
269
+ rb_define_method(klass, "transform", transform, -1);
270
+ }
@@ -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,137 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Modify the PATH on windows so that the external DLLs will get loaded.
3
+
4
+ require 'rbconfig'
5
+
6
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
7
+ # The line below caused a problem on non-GAE rack environment.
8
+ # unless defined?(JRuby::Rack::VERSION) || defined?(AppEngine::ApiProxy)
9
+ #
10
+ # However, simply cutting defined?(JRuby::Rack::VERSION) off resulted in
11
+ # an unable-to-load-nokogiri problem. Thus, now, Nokogiri checks the presense
12
+ # of appengine-rack.jar in $LOAD_PATH. If Nokogiri is on GAE, Nokogiri
13
+ # should skip loading xml jars. This is because those are in WEB-INF/lib and
14
+ # already set in the classpath.
15
+ unless $LOAD_PATH.to_s.include?("appengine-rack")
16
+ require 'stringio'
17
+ require 'isorelax.jar'
18
+ require 'jing.jar'
19
+ require 'nekohtml.jar'
20
+ require 'nekodtd.jar'
21
+ require 'xercesImpl.jar'
22
+ end
23
+ end
24
+
25
+ begin
26
+ RUBY_VERSION =~ /(\d+.\d+)/
27
+ require "nokogiri/#{$1}/nokogiri"
28
+ rescue LoadError
29
+ require 'nokogiri/nokogiri'
30
+ end
31
+ require 'nokogiri/version'
32
+ require 'nokogiri/syntax_error'
33
+ require 'nokogiri/xml'
34
+ require 'nokogiri/xslt'
35
+ require 'nokogiri/html'
36
+ require 'nokogiri/decorators/slop'
37
+ require 'nokogiri/css'
38
+ require 'nokogiri/html/builder'
39
+
40
+ # Nokogiri parses and searches XML/HTML very quickly, and also has
41
+ # correctly implemented CSS3 selector support as well as XPath 1.0
42
+ # support.
43
+ #
44
+ # Parsing a document returns either a Nokogiri::XML::Document, or a
45
+ # Nokogiri::HTML::Document depending on the kind of document you parse.
46
+ #
47
+ # Here is an example:
48
+ #
49
+ # require 'nokogiri'
50
+ # require 'open-uri'
51
+ #
52
+ # # Get a Nokogiri::HTML:Document for the page we’re interested in...
53
+ #
54
+ # doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
55
+ #
56
+ # # Do funky things with it using Nokogiri::XML::Node methods...
57
+ #
58
+ # ####
59
+ # # Search for nodes by css
60
+ # doc.css('h3.r a.l').each do |link|
61
+ # puts link.content
62
+ # end
63
+ #
64
+ # See Nokogiri::XML::Node#css for more information about CSS searching.
65
+ # See Nokogiri::XML::Node#xpath for more information about XPath searching.
66
+ module Nokogiri
67
+ class << self
68
+ ###
69
+ # Parse an HTML or XML document. +string+ contains the document.
70
+ def parse string, url = nil, encoding = nil, options = nil
71
+ if string.respond_to?(:read) ||
72
+ /^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
73
+ # Expect an HTML indicator to appear within the first 512
74
+ # characters of a document. (<?xml ?> + <?xml-stylesheet ?>
75
+ # shouldn't be that long)
76
+ Nokogiri.HTML(string, url, encoding,
77
+ options || XML::ParseOptions::DEFAULT_HTML)
78
+ else
79
+ Nokogiri.XML(string, url, encoding,
80
+ options || XML::ParseOptions::DEFAULT_XML)
81
+ end.tap { |doc|
82
+ yield doc if block_given?
83
+ }
84
+ end
85
+
86
+ ###
87
+ # Create a new Nokogiri::XML::DocumentFragment
88
+ def make input = nil, opts = {}, &blk
89
+ if input
90
+ Nokogiri::HTML.fragment(input).children.first
91
+ else
92
+ Nokogiri(&blk)
93
+ end
94
+ end
95
+
96
+ ###
97
+ # Parse a document and add the Slop decorator. The Slop decorator
98
+ # implements method_missing such that methods may be used instead of CSS
99
+ # or XPath. For example:
100
+ #
101
+ # doc = Nokogiri::Slop(<<-eohtml)
102
+ # <html>
103
+ # <body>
104
+ # <p>first</p>
105
+ # <p>second</p>
106
+ # </body>
107
+ # </html>
108
+ # eohtml
109
+ # assert_equal('second', doc.html.body.p[1].text)
110
+ #
111
+ def Slop(*args, &block)
112
+ Nokogiri(*args, &block).slop!
113
+ end
114
+ end
115
+
116
+ # Make sure to support some popular encoding aliases not known by
117
+ # all iconv implementations.
118
+ {
119
+ 'Windows-31J' => 'CP932', # Windows-31J is the IANA registered name of CP932.
120
+ }.each { |alias_name, name|
121
+ EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
122
+ }
123
+ end
124
+
125
+ ###
126
+ # Parser a document contained in +args+. Nokogiri will try to guess what
127
+ # type of document you are attempting to parse. For more information, see
128
+ # Nokogiri.parse
129
+ #
130
+ # To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
131
+ def Nokogiri(*args, &block)
132
+ if block_given?
133
+ Nokogiri::HTML::Builder.new(&block).doc.root
134
+ else
135
+ Nokogiri.parse(*args)
136
+ end
137
+ end
@@ -0,0 +1,27 @@
1
+ require 'nokogiri/css/node'
2
+ require 'nokogiri/css/xpath_visitor'
3
+ x = $-w
4
+ $-w = false
5
+ require 'nokogiri/css/parser'
6
+ $-w = x
7
+
8
+ require 'nokogiri/css/tokenizer'
9
+ require 'nokogiri/css/syntax_error'
10
+
11
+ module Nokogiri
12
+ module CSS
13
+ class << self
14
+ ###
15
+ # Parse this CSS selector in +selector+. Returns an AST.
16
+ def parse selector
17
+ Parser.new.parse selector
18
+ end
19
+
20
+ ###
21
+ # Get the XPath for +selector+.
22
+ def xpath_for selector, options={}
23
+ Parser.new(options[:ns] || {}).xpath_for selector, options
24
+ end
25
+ end
26
+ end
27
+ end