nokogiri 1.1.1-java

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 (142) hide show
  1. data/History.ja.txt +99 -0
  2. data/History.txt +99 -0
  3. data/Manifest.txt +141 -0
  4. data/README.ja.txt +100 -0
  5. data/README.txt +109 -0
  6. data/Rakefile +354 -0
  7. data/ext/nokogiri/extconf.rb +93 -0
  8. data/ext/nokogiri/html_document.c +86 -0
  9. data/ext/nokogiri/html_document.h +10 -0
  10. data/ext/nokogiri/html_sax_parser.c +36 -0
  11. data/ext/nokogiri/html_sax_parser.h +11 -0
  12. data/ext/nokogiri/native.c +41 -0
  13. data/ext/nokogiri/native.h +50 -0
  14. data/ext/nokogiri/xml_cdata.c +44 -0
  15. data/ext/nokogiri/xml_cdata.h +9 -0
  16. data/ext/nokogiri/xml_comment.c +42 -0
  17. data/ext/nokogiri/xml_comment.h +9 -0
  18. data/ext/nokogiri/xml_document.c +206 -0
  19. data/ext/nokogiri/xml_document.h +10 -0
  20. data/ext/nokogiri/xml_dtd.c +121 -0
  21. data/ext/nokogiri/xml_dtd.h +8 -0
  22. data/ext/nokogiri/xml_io.c +17 -0
  23. data/ext/nokogiri/xml_io.h +9 -0
  24. data/ext/nokogiri/xml_node.c +727 -0
  25. data/ext/nokogiri/xml_node.h +13 -0
  26. data/ext/nokogiri/xml_node_set.c +118 -0
  27. data/ext/nokogiri/xml_node_set.h +9 -0
  28. data/ext/nokogiri/xml_reader.c +465 -0
  29. data/ext/nokogiri/xml_reader.h +10 -0
  30. data/ext/nokogiri/xml_sax_parser.c +201 -0
  31. data/ext/nokogiri/xml_sax_parser.h +10 -0
  32. data/ext/nokogiri/xml_syntax_error.c +199 -0
  33. data/ext/nokogiri/xml_syntax_error.h +11 -0
  34. data/ext/nokogiri/xml_text.c +40 -0
  35. data/ext/nokogiri/xml_text.h +9 -0
  36. data/ext/nokogiri/xml_xpath.c +53 -0
  37. data/ext/nokogiri/xml_xpath.h +11 -0
  38. data/ext/nokogiri/xml_xpath_context.c +214 -0
  39. data/ext/nokogiri/xml_xpath_context.h +9 -0
  40. data/ext/nokogiri/xslt_stylesheet.c +123 -0
  41. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  42. data/lib/action-nokogiri.rb +30 -0
  43. data/lib/nokogiri.rb +72 -0
  44. data/lib/nokogiri/css.rb +25 -0
  45. data/lib/nokogiri/css/generated_parser.rb +721 -0
  46. data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
  47. data/lib/nokogiri/css/node.rb +97 -0
  48. data/lib/nokogiri/css/parser.rb +64 -0
  49. data/lib/nokogiri/css/parser.y +216 -0
  50. data/lib/nokogiri/css/syntax_error.rb +6 -0
  51. data/lib/nokogiri/css/tokenizer.rb +9 -0
  52. data/lib/nokogiri/css/tokenizer.rex +63 -0
  53. data/lib/nokogiri/css/xpath_visitor.rb +168 -0
  54. data/lib/nokogiri/decorators.rb +2 -0
  55. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  56. data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
  57. data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
  58. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +28 -0
  59. data/lib/nokogiri/decorators/slop.rb +31 -0
  60. data/lib/nokogiri/hpricot.rb +51 -0
  61. data/lib/nokogiri/html.rb +105 -0
  62. data/lib/nokogiri/html/builder.rb +9 -0
  63. data/lib/nokogiri/html/document.rb +9 -0
  64. data/lib/nokogiri/html/sax/parser.rb +21 -0
  65. data/lib/nokogiri/version.rb +3 -0
  66. data/lib/nokogiri/xml.rb +83 -0
  67. data/lib/nokogiri/xml/after_handler.rb +18 -0
  68. data/lib/nokogiri/xml/attr.rb +10 -0
  69. data/lib/nokogiri/xml/before_handler.rb +33 -0
  70. data/lib/nokogiri/xml/builder.rb +84 -0
  71. data/lib/nokogiri/xml/cdata.rb +9 -0
  72. data/lib/nokogiri/xml/comment.rb +6 -0
  73. data/lib/nokogiri/xml/document.rb +55 -0
  74. data/lib/nokogiri/xml/dtd.rb +6 -0
  75. data/lib/nokogiri/xml/element.rb +6 -0
  76. data/lib/nokogiri/xml/entity_declaration.rb +9 -0
  77. data/lib/nokogiri/xml/node.rb +333 -0
  78. data/lib/nokogiri/xml/node_set.rb +197 -0
  79. data/lib/nokogiri/xml/notation.rb +6 -0
  80. data/lib/nokogiri/xml/reader.rb +20 -0
  81. data/lib/nokogiri/xml/sax.rb +9 -0
  82. data/lib/nokogiri/xml/sax/document.rb +59 -0
  83. data/lib/nokogiri/xml/sax/parser.rb +37 -0
  84. data/lib/nokogiri/xml/syntax_error.rb +21 -0
  85. data/lib/nokogiri/xml/text.rb +6 -0
  86. data/lib/nokogiri/xml/xpath.rb +10 -0
  87. data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
  88. data/lib/nokogiri/xml/xpath_context.rb +14 -0
  89. data/lib/nokogiri/xslt.rb +28 -0
  90. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  91. data/test/css/test_nthiness.rb +159 -0
  92. data/test/css/test_parser.rb +237 -0
  93. data/test/css/test_tokenizer.rb +162 -0
  94. data/test/css/test_xpath_visitor.rb +64 -0
  95. data/test/files/dont_hurt_em_why.xml +422 -0
  96. data/test/files/exslt.xml +8 -0
  97. data/test/files/exslt.xslt +35 -0
  98. data/test/files/staff.xml +59 -0
  99. data/test/files/staff.xslt +32 -0
  100. data/test/files/tlm.html +850 -0
  101. data/test/helper.rb +78 -0
  102. data/test/hpricot/files/basic.xhtml +17 -0
  103. data/test/hpricot/files/boingboing.html +2266 -0
  104. data/test/hpricot/files/cy0.html +3653 -0
  105. data/test/hpricot/files/immob.html +400 -0
  106. data/test/hpricot/files/pace_application.html +1320 -0
  107. data/test/hpricot/files/tenderlove.html +16 -0
  108. data/test/hpricot/files/uswebgen.html +220 -0
  109. data/test/hpricot/files/utf8.html +1054 -0
  110. data/test/hpricot/files/week9.html +1723 -0
  111. data/test/hpricot/files/why.xml +19 -0
  112. data/test/hpricot/load_files.rb +11 -0
  113. data/test/hpricot/test_alter.rb +67 -0
  114. data/test/hpricot/test_builder.rb +27 -0
  115. data/test/hpricot/test_parser.rb +426 -0
  116. data/test/hpricot/test_paths.rb +15 -0
  117. data/test/hpricot/test_preserved.rb +77 -0
  118. data/test/hpricot/test_xml.rb +30 -0
  119. data/test/html/sax/test_parser.rb +27 -0
  120. data/test/html/test_builder.rb +89 -0
  121. data/test/html/test_document.rb +150 -0
  122. data/test/html/test_node.rb +21 -0
  123. data/test/test_convert_xpath.rb +185 -0
  124. data/test/test_css_cache.rb +57 -0
  125. data/test/test_gc.rb +15 -0
  126. data/test/test_memory_leak.rb +38 -0
  127. data/test/test_nokogiri.rb +97 -0
  128. data/test/test_reader.rb +222 -0
  129. data/test/test_xslt_transforms.rb +93 -0
  130. data/test/xml/sax/test_parser.rb +95 -0
  131. data/test/xml/test_attr.rb +15 -0
  132. data/test/xml/test_builder.rb +16 -0
  133. data/test/xml/test_cdata.rb +18 -0
  134. data/test/xml/test_comment.rb +16 -0
  135. data/test/xml/test_document.rb +195 -0
  136. data/test/xml/test_dtd.rb +43 -0
  137. data/test/xml/test_node.rb +394 -0
  138. data/test/xml/test_node_set.rb +143 -0
  139. data/test/xml/test_text.rb +13 -0
  140. data/test/xml/test_xpath.rb +105 -0
  141. data/vendor/hoe.rb +1020 -0
  142. metadata +233 -0
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_TEXT
2
+ #define NOKOGIRI_XML_TEXT
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_text();
7
+
8
+ extern VALUE cNokogiriXmlText ;
9
+ #endif
@@ -0,0 +1,53 @@
1
+ #include <xml_xpath.h>
2
+
3
+ static void deallocate(xmlXPathObjectPtr xpath)
4
+ {
5
+ NOKOGIRI_DEBUG_START(xpath);
6
+ xmlXPathFreeNodeSetList(xpath); // despite the name, this frees the xpath but not the contained node set
7
+ NOKOGIRI_DEBUG_END(xpath);
8
+ }
9
+
10
+ VALUE Nokogiri_wrap_xml_xpath(xmlXPathObjectPtr xpath)
11
+ {
12
+ return Data_Wrap_Struct(cNokogiriXmlXpath, 0, deallocate, xpath);
13
+ }
14
+
15
+ /*
16
+ * call-seq:
17
+ * node_set
18
+ *
19
+ * Fetch the node set associated with this xpath context.
20
+ */
21
+ static VALUE node_set(VALUE self)
22
+ {
23
+ xmlXPathObjectPtr xpath;
24
+ Data_Get_Struct(self, xmlXPathObject, xpath);
25
+
26
+ VALUE node_set = Qnil;
27
+
28
+ if (xpath->nodesetval)
29
+ node_set = Nokogiri_wrap_xml_node_set(xpath->nodesetval);
30
+
31
+ if(Qnil == node_set)
32
+ node_set = Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL));
33
+
34
+ rb_funcall(node_set, rb_intern("document="), 1, rb_iv_get(self, "@document"));
35
+
36
+ return node_set;
37
+ }
38
+
39
+ VALUE cNokogiriXmlXpath;
40
+ void init_xml_xpath(void)
41
+ {
42
+ VALUE module = rb_define_module("Nokogiri");
43
+ VALUE xml = rb_define_module_under(module, "XML");
44
+
45
+ /*
46
+ * This class wraps an XPath object and should only be instantiated from
47
+ * XPathContext.
48
+ */
49
+ VALUE klass = rb_define_class_under(xml, "XPath", rb_cObject);
50
+
51
+ cNokogiriXmlXpath = klass;
52
+ rb_define_method(klass, "node_set", node_set, 0);
53
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef NOKOGIRI_XML_XPATH
2
+ #define NOKOGIRI_XML_XPATH
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_xpath();
7
+ VALUE Nokogiri_wrap_xml_xpath(xmlXPathObjectPtr xpath);
8
+
9
+ extern VALUE cNokogiriXmlXpath;
10
+ #endif
11
+
@@ -0,0 +1,214 @@
1
+ #include <xml_xpath_context.h>
2
+
3
+ static void deallocate(xmlXPathContextPtr ctx)
4
+ {
5
+ NOKOGIRI_DEBUG_START(ctx);
6
+ xmlXPathFreeContext(ctx);
7
+ NOKOGIRI_DEBUG_END(ctx);
8
+ }
9
+
10
+ /*
11
+ * call-seq:
12
+ * register_ns(prefix, uri)
13
+ *
14
+ * Register the namespace with +prefix+ and +uri+.
15
+ */
16
+ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
17
+ {
18
+ xmlXPathContextPtr ctx;
19
+ Data_Get_Struct(self, xmlXPathContext, ctx);
20
+
21
+ xmlXPathRegisterNs( ctx,
22
+ (const xmlChar *)StringValuePtr(prefix),
23
+ (const xmlChar *)StringValuePtr(uri)
24
+ );
25
+ return self;
26
+ }
27
+
28
+ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
29
+ {
30
+ VALUE xpath_handler = Qnil;
31
+ xmlXPathObjectPtr obj;
32
+
33
+ assert(ctx);
34
+ assert(ctx->context);
35
+ assert(ctx->context->userData);
36
+ assert(ctx->context->doc);
37
+ assert(ctx->context->doc->_private);
38
+
39
+ xpath_handler = (VALUE)(ctx->context->userData);
40
+
41
+ VALUE * argv = (VALUE *)calloc((unsigned int)nargs, sizeof(VALUE));
42
+ VALUE doc = (VALUE)ctx->context->doc->_private;
43
+
44
+ int i = nargs - 1;
45
+ do {
46
+ obj = valuePop(ctx);
47
+ switch(obj->type) {
48
+ case XPATH_STRING:
49
+ argv[i] = rb_str_new2((char *)obj->stringval);
50
+ break;
51
+ case XPATH_BOOLEAN:
52
+ argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
53
+ break;
54
+ case XPATH_NUMBER:
55
+ argv[i] = rb_float_new(obj->floatval);
56
+ break;
57
+ case XPATH_NODESET:
58
+ argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval);
59
+ break;
60
+ default:
61
+ argv[i] = rb_str_new2((char *)xmlXPathCastToString(obj));
62
+ }
63
+ xmlXPathFreeNodeSetList(obj);
64
+ } while(i-- > 0);
65
+
66
+ VALUE result = rb_funcall2(
67
+ xpath_handler,
68
+ rb_intern((const char *)ctx->context->function),
69
+ nargs,
70
+ argv
71
+ );
72
+ free(argv);
73
+
74
+ VALUE node_set = Qnil;
75
+ xmlNodeSetPtr xml_node_set = NULL;
76
+
77
+ switch(TYPE(result)) {
78
+ case T_FLOAT:
79
+ case T_BIGNUM:
80
+ case T_FIXNUM:
81
+ xmlXPathReturnNumber(ctx, NUM2DBL(result));
82
+ break;
83
+ case T_STRING:
84
+ xmlXPathReturnString(
85
+ ctx,
86
+ (xmlChar *)xmlXPathWrapCString(StringValuePtr(result))
87
+ );
88
+ break;
89
+ case T_TRUE:
90
+ xmlXPathReturnTrue(ctx);
91
+ break;
92
+ case T_FALSE:
93
+ xmlXPathReturnFalse(ctx);
94
+ break;
95
+ case T_NIL:
96
+ break;
97
+ case T_ARRAY:
98
+ node_set = rb_funcall(
99
+ cNokogiriXmlNodeSet,
100
+ rb_intern("new"),
101
+ 2,
102
+ doc,
103
+ result
104
+ );
105
+ Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
106
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
107
+ break;
108
+ case T_DATA:
109
+ if(rb_funcall(result, rb_intern("is_a?"), 1, cNokogiriXmlNodeSet)) {
110
+ Data_Get_Struct(result, xmlNodeSet, xml_node_set);
111
+ // Copy the node set, otherwise it will get GC'd.
112
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
113
+ break;
114
+ }
115
+ default:
116
+ rb_raise(rb_eRuntimeError, "Invalid return type");
117
+ }
118
+ }
119
+
120
+ static xmlXPathFunction lookup( void *ctx,
121
+ const xmlChar * name,
122
+ const xmlChar* ns_uri )
123
+ {
124
+ VALUE xpath_handler = (VALUE)ctx;
125
+ if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
126
+ return ruby_funcall;
127
+
128
+ return NULL;
129
+ }
130
+
131
+ /*
132
+ * call-seq:
133
+ * evaluate(search_path)
134
+ *
135
+ * Evaluate the +search_path+ returning an XML::XPath object.
136
+ */
137
+ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
138
+ {
139
+ VALUE search_path, xpath_handler;
140
+ xmlXPathContextPtr ctx;
141
+ Data_Get_Struct(self, xmlXPathContext, ctx);
142
+
143
+ if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
144
+ xpath_handler = Qnil;
145
+
146
+ xmlChar* query = (xmlChar *)StringValuePtr(search_path);
147
+
148
+ if(Qnil != xpath_handler) {
149
+ // FIXME: not sure if this is the correct place to shove private data.
150
+ ctx->userData = (void *)xpath_handler;
151
+ xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
152
+ }
153
+
154
+ xmlXPathObjectPtr xpath = xmlXPathEvalExpression(query, ctx);
155
+ if(xpath == NULL) {
156
+ VALUE xpath = rb_const_get(mNokogiriXml, rb_intern("XPath"));
157
+ VALUE error = rb_const_get(xpath, rb_intern("SyntaxError"));
158
+ rb_raise(error, "Couldn't evaluate expression '%s'", query);
159
+ }
160
+
161
+ VALUE xpath_object = Nokogiri_wrap_xml_xpath(xpath);
162
+
163
+ assert(ctx->doc);
164
+ assert(ctx->doc->_private);
165
+
166
+ rb_funcall( xpath_object,
167
+ rb_intern("document="),
168
+ 1,
169
+ (VALUE)ctx->doc->_private
170
+ );
171
+ return xpath_object;
172
+ }
173
+
174
+ /*
175
+ * call-seq:
176
+ * new(node)
177
+ *
178
+ * Create a new XPathContext with +node+ as the reference point.
179
+ */
180
+ static VALUE new(VALUE klass, VALUE nodeobj)
181
+ {
182
+ xmlXPathInit();
183
+
184
+ xmlNodePtr node ;
185
+ Data_Get_Struct(nodeobj, xmlNode, node);
186
+
187
+ xmlXPathContextPtr ctx = xmlXPathNewContext(node->doc);
188
+ ctx->node = node;
189
+ VALUE self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
190
+ //rb_iv_set(self, "@xpath_handler", Qnil);
191
+ return self;
192
+ }
193
+
194
+ VALUE cNokogiriXmlXpathContext;
195
+ void init_xml_xpath_context(void)
196
+ {
197
+ VALUE module = rb_define_module("Nokogiri");
198
+
199
+ /*
200
+ * Nokogiri::XML
201
+ */
202
+ VALUE xml = rb_define_module_under(module, "XML");
203
+
204
+ /*
205
+ * XPathContext is the entry point for searching a Document by using XPath.
206
+ */
207
+ VALUE klass = rb_define_class_under(xml, "XPathContext", rb_cObject);
208
+
209
+ cNokogiriXmlXpathContext = klass;
210
+
211
+ rb_define_singleton_method(klass, "new", new, 1);
212
+ rb_define_method(klass, "evaluate", evaluate, -1);
213
+ rb_define_method(klass, "register_ns", register_ns, 2);
214
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_XPATH_CONTEXT
2
+ #define NOKOGIRI_XML_XPATH_CONTEXT
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_xpath_context();
7
+
8
+ extern VALUE cNokogiriXmlXpathContext;
9
+ #endif
@@ -0,0 +1,123 @@
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
+ static void dealloc(xsltStylesheetPtr doc)
9
+ {
10
+ NOKOGIRI_DEBUG_START(doc);
11
+ xsltFreeStylesheet(doc); // commented out for now.
12
+ NOKOGIRI_DEBUG_END(doc);
13
+ }
14
+
15
+ /*
16
+ * call-seq:
17
+ * parse_stylesheet_doc(document)
18
+ *
19
+ * Parse a stylesheet from +document+.
20
+ */
21
+ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
22
+ {
23
+ xmlDocPtr xml ;
24
+ xsltStylesheetPtr ss ;
25
+ Data_Get_Struct(xmldocobj, xmlDoc, xml);
26
+ exsltRegisterAll();
27
+ ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */
28
+ return Data_Wrap_Struct(klass, NULL, dealloc, ss);
29
+ }
30
+
31
+
32
+ /*
33
+ * call-seq:
34
+ * serialize(document)
35
+ *
36
+ * Serialize +document+ to an xml string.
37
+ */
38
+ static VALUE serialize(VALUE self, VALUE xmlobj)
39
+ {
40
+ xmlDocPtr xml ;
41
+ xsltStylesheetPtr ss ;
42
+ xmlChar* doc_ptr ;
43
+ int doc_len ;
44
+ VALUE rval ;
45
+
46
+ Data_Get_Struct(xmlobj, xmlDoc, xml);
47
+ Data_Get_Struct(self, xsltStylesheet, ss);
48
+ xsltSaveResultToString(&doc_ptr, &doc_len, xml, ss);
49
+ rval = rb_str_new((char*)doc_ptr, doc_len);
50
+ xmlFree(doc_ptr);
51
+ return rval ;
52
+ }
53
+ /*
54
+ * call-seq:
55
+ * transform(document, params)
56
+ *
57
+ * Apply an XSLT stylesheet to an XML::Document.
58
+ * +params+ is an array of strings used as XSLT parameters.
59
+ * returns Nokogiri::XML::Document
60
+ */
61
+ static VALUE transform(int argc, VALUE* argv, VALUE self)
62
+ {
63
+ VALUE xmldoc, paramobj ;
64
+ xmlDocPtr xml ;
65
+ xmlDocPtr result ;
66
+ xsltStylesheetPtr ss ;
67
+ const char** params ;
68
+ int param_len, j ;
69
+
70
+ rb_scan_args(argc, argv, "11", &xmldoc, &paramobj);
71
+ if (paramobj == Qnil) { paramobj = rb_ary_new2(0) ; }
72
+
73
+ Data_Get_Struct(xmldoc, xmlDoc, xml);
74
+ Data_Get_Struct(self, xsltStylesheet, ss);
75
+
76
+ param_len = NUM2INT(rb_funcall(paramobj, rb_intern("length"), 0));
77
+ params = calloc((size_t)param_len+1, sizeof(char*));
78
+ for (j = 0 ; j < param_len ; j++) {
79
+ VALUE entry = rb_ary_entry(paramobj, j);
80
+ const char * ptr = StringValuePtr(entry);
81
+ params[j] = ptr;
82
+ }
83
+ params[param_len] = 0 ;
84
+
85
+ result = xsltApplyStylesheet(ss, xml, params);
86
+ free(params);
87
+
88
+ return Nokogiri_wrap_xml_document(0, result) ;
89
+ }
90
+
91
+ /*
92
+ * call-seq:
93
+ * apply_to(document, params)
94
+ *
95
+ * Apply an XSLT stylesheet to an XML::Document.
96
+ * +params+ is an array of strings used as XSLT parameters.
97
+ * returns serialized document
98
+ */
99
+ static VALUE apply_to(int argc, VALUE* argv, VALUE self)
100
+ {
101
+ return rb_funcall(self, rb_intern("serialize"), 1,
102
+ transform(argc, argv, self));
103
+ }
104
+
105
+ VALUE cNokogiriXsltStylesheet ;
106
+ void init_xslt_stylesheet()
107
+ {
108
+ /*
109
+ * HACK. This is so that rdoc will work with this C file.
110
+ */
111
+ /*
112
+ VALUE nokogiri = rb_define_module("Nokogiri");
113
+ VALUE xslt = rb_define_module_under(nokogiri, "XSLT");
114
+ VALUE klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
115
+ */
116
+
117
+ VALUE klass = cNokogiriXsltStylesheet = rb_const_get(mNokogiriXslt, rb_intern("Stylesheet"));
118
+
119
+ rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
120
+ rb_define_method(klass, "serialize", serialize, 1);
121
+ rb_define_method(klass, "apply_to", apply_to, -1);
122
+ rb_define_method(klass, "transform", transform, -1);
123
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XSLT_STYLESHEET
2
+ #define NOKOGIRI_XSLT_STYLESHEET
3
+
4
+ #include <native.h>
5
+
6
+ void init_xslt_stylesheet();
7
+
8
+ extern VALUE cNokogiriXsltStylesheet ;
9
+ #endif
@@ -0,0 +1,30 @@
1
+ require 'nokogiri'
2
+
3
+ #
4
+ # to use this in your Rails view or controller tests, simply:
5
+ #
6
+ # require 'action-nokogiri'
7
+ #
8
+ # class KittehControllerTest < ActionController::TestCase
9
+ # def test_i_can_does_test_with_nokogiri
10
+ # get(:index, {:wants => "cheezburgers"})
11
+ # assert @response.html.at("h2.lolcats")
12
+ # end
13
+ #
14
+ module ActionController
15
+ module TestResponseBehavior
16
+
17
+ def html(flavor=nil)
18
+ if flavor == :hpricot
19
+ @_nokogiri_html_hpricot ||= Nokogiri::Hpricot(body)
20
+ else
21
+ @_nokogiri_html_vanilla ||= Nokogiri::HTML(body)
22
+ end
23
+ end
24
+
25
+ def xml
26
+ @_nokogiri_xml ||= Nokogiri::XML(body)
27
+ end
28
+
29
+ end
30
+ end