nokogiri 1.2.3-java → 1.3.0-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.
- data/.autotest +14 -2
- data/CHANGELOG.ja.rdoc +38 -0
- data/CHANGELOG.rdoc +43 -0
- data/Manifest.txt +80 -5
- data/README.ja.rdoc +12 -11
- data/README.rdoc +4 -2
- data/Rakefile +103 -173
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +19 -13
- data/ext/nokogiri/html_document.c +39 -3
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.h +1 -1
- data/ext/nokogiri/html_sax_parser.h +1 -1
- data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
- data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
- data/ext/nokogiri/xml_attr.c +14 -5
- data/ext/nokogiri/xml_attr.h +1 -1
- data/ext/nokogiri/xml_cdata.c +15 -6
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +13 -4
- data/ext/nokogiri/xml_comment.h +1 -1
- data/ext/nokogiri/xml_document.c +50 -41
- data/ext/nokogiri/xml_document.h +1 -1
- data/ext/nokogiri/xml_document_fragment.c +12 -4
- data/ext/nokogiri/xml_document_fragment.h +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_dtd.h +1 -1
- data/ext/nokogiri/xml_entity_reference.c +13 -4
- data/ext/nokogiri/xml_entity_reference.h +1 -1
- data/ext/nokogiri/xml_io.h +1 -1
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +232 -124
- data/ext/nokogiri/xml_node.h +3 -4
- data/ext/nokogiri/xml_node_set.c +204 -17
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +14 -4
- data/ext/nokogiri/xml_processing_instruction.h +1 -1
- data/ext/nokogiri/xml_reader.c +87 -7
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +106 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +122 -2
- data/ext/nokogiri/xml_sax_parser.h +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -0
- data/ext/nokogiri/xml_sax_push_parser.h +1 -1
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +10 -3
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath.h +1 -1
- data/ext/nokogiri/xml_xpath_context.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +29 -16
- data/ext/nokogiri/xslt_stylesheet.h +1 -1
- data/lib/action-nokogiri.rb +7 -1
- data/lib/nokogiri.rb +21 -5
- data/lib/nokogiri/css/generated_parser.rb +49 -14
- data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
- data/lib/nokogiri/css/node.rb +13 -3
- data/lib/nokogiri/css/parser.rb +8 -0
- data/lib/nokogiri/css/parser.y +7 -7
- data/lib/nokogiri/css/tokenizer.rb +2 -0
- data/lib/nokogiri/css/xpath_visitor.rb +10 -6
- data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
- data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
- data/lib/nokogiri/decorators/slop.rb +3 -1
- data/lib/nokogiri/ffi/html/document.rb +37 -0
- data/lib/nokogiri/ffi/html/element_description.rb +85 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
- data/lib/nokogiri/ffi/libxml.rb +314 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +107 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
- data/lib/nokogiri/ffi/xml/node.rb +380 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +217 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
- data/lib/nokogiri/ffi/xml/schema.rb +55 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
- data/lib/nokogiri/hpricot.rb +14 -3
- data/lib/nokogiri/html.rb +11 -46
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +62 -6
- data/lib/nokogiri/html/document_fragment.rb +15 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/entity_lookup.rb +2 -0
- data/lib/nokogiri/html/sax/parser.rb +27 -1
- data/lib/nokogiri/version.rb +26 -1
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +25 -51
- data/lib/nokogiri/xml/builder.rb +166 -10
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/document.rb +39 -6
- data/lib/nokogiri/xml/document_fragment.rb +41 -1
- data/lib/nokogiri/xml/dtd.rb +3 -1
- data/lib/nokogiri/xml/entity_declaration.rb +3 -1
- data/lib/nokogiri/xml/fragment_handler.rb +24 -3
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +314 -65
- data/lib/nokogiri/xml/node/save_options.rb +12 -2
- data/lib/nokogiri/xml/node_set.rb +58 -8
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -0
- data/lib/nokogiri/xml/reader.rb +42 -3
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +0 -7
- data/lib/nokogiri/xml/sax/document.rb +84 -0
- data/lib/nokogiri/xml/sax/parser.rb +38 -2
- data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath.rb +1 -1
- data/lib/nokogiri/xml/xpath_context.rb +2 -0
- data/lib/nokogiri/xslt.rb +21 -1
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/xsd/xmlparser/nokogiri.rb +12 -2
- data/tasks/test.rb +42 -19
- data/test/css/test_parser.rb +29 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/helper.rb +38 -8
- data/test/html/sax/test_parser.rb +12 -0
- data/test/html/test_builder.rb +25 -2
- data/test/html/test_document.rb +91 -20
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_node.rb +66 -3
- data/test/test_convert_xpath.rb +1 -1
- data/test/test_memory_leak.rb +57 -18
- data/test/test_nokogiri.rb +24 -2
- data/test/test_reader.rb +77 -0
- data/test/test_xslt_transforms.rb +120 -82
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +9 -0
- data/test/xml/sax/test_push_parser.rb +24 -0
- data/test/xml/test_attr.rb +7 -0
- data/test/xml/test_builder.rb +48 -0
- data/test/xml/test_cdata.rb +19 -0
- data/test/xml/test_comment.rb +6 -0
- data/test/xml/test_document.rb +101 -2
- data/test/xml/test_document_fragment.rb +55 -3
- data/test/xml/test_entity_reference.rb +4 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +255 -8
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +9 -2
- data/test/xml/test_node_set.rb +197 -1
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +5 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +5 -0
- data/test/xml/test_unparented_node.rb +3 -3
- metadata +129 -13
- data/lib/nokogiri/xml/comment.rb +0 -6
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/text.rb +0 -6
data/ext/nokogiri/xml_text.h
CHANGED
data/ext/nokogiri/xml_xpath.h
CHANGED
@@ -12,6 +12,18 @@ static void dealloc(xsltStylesheetPtr doc)
|
|
12
12
|
NOKOGIRI_DEBUG_END(doc);
|
13
13
|
}
|
14
14
|
|
15
|
+
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
16
|
+
{
|
17
|
+
char * message;
|
18
|
+
|
19
|
+
va_list args;
|
20
|
+
va_start(args, msg);
|
21
|
+
vasprintf(&message, msg, args);
|
22
|
+
va_end(args);
|
23
|
+
|
24
|
+
rb_raise(rb_eRuntimeError, message);
|
25
|
+
}
|
26
|
+
|
15
27
|
/*
|
16
28
|
* call-seq:
|
17
29
|
* parse_stylesheet_doc(document)
|
@@ -24,7 +36,13 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
|
24
36
|
xsltStylesheetPtr ss ;
|
25
37
|
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
26
38
|
exsltRegisterAll();
|
39
|
+
|
40
|
+
xsltSetGenericErrorFunc(NULL, xslt_generic_error_handler);
|
41
|
+
|
27
42
|
ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */
|
43
|
+
|
44
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
45
|
+
|
28
46
|
return Data_Wrap_Struct(klass, NULL, dealloc, ss);
|
29
47
|
}
|
30
48
|
|
@@ -50,13 +68,21 @@ static VALUE serialize(VALUE self, VALUE xmlobj)
|
|
50
68
|
xmlFree(doc_ptr);
|
51
69
|
return rval ;
|
52
70
|
}
|
71
|
+
|
53
72
|
/*
|
54
73
|
* call-seq:
|
55
|
-
* transform(document, params)
|
74
|
+
* transform(document, params = [])
|
56
75
|
*
|
57
76
|
* Apply an XSLT stylesheet to an XML::Document.
|
58
77
|
* +params+ is an array of strings used as XSLT parameters.
|
59
78
|
* returns Nokogiri::XML::Document
|
79
|
+
*
|
80
|
+
* Example:
|
81
|
+
*
|
82
|
+
* doc = Nokogiri::XML(File.read(ARGV[0]))
|
83
|
+
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
|
84
|
+
* puts xslt.transform(doc, ['key', 'value'])
|
85
|
+
*
|
60
86
|
*/
|
61
87
|
static VALUE transform(int argc, VALUE* argv, VALUE self)
|
62
88
|
{
|
@@ -85,21 +111,9 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
|
|
85
111
|
result = xsltApplyStylesheet(ss, xml, params);
|
86
112
|
free(params);
|
87
113
|
|
88
|
-
|
89
|
-
}
|
114
|
+
if (!result) rb_raise(rb_eRuntimeError, "could not perform xslt transform on document");
|
90
115
|
|
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));
|
116
|
+
return Nokogiri_wrap_xml_document(0, result) ;
|
103
117
|
}
|
104
118
|
|
105
119
|
VALUE cNokogiriXsltStylesheet ;
|
@@ -113,6 +127,5 @@ void init_xslt_stylesheet()
|
|
113
127
|
|
114
128
|
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
115
129
|
rb_define_method(klass, "serialize", serialize, 1);
|
116
|
-
rb_define_method(klass, "apply_to", apply_to, -1);
|
117
130
|
rb_define_method(klass, "transform", transform, -1);
|
118
131
|
}
|
data/lib/action-nokogiri.rb
CHANGED
@@ -12,8 +12,11 @@ require 'nokogiri'
|
|
12
12
|
# end
|
13
13
|
#
|
14
14
|
module ActionController
|
15
|
-
module TestResponseBehavior
|
15
|
+
module TestResponseBehavior # :nodoc:
|
16
16
|
|
17
|
+
###
|
18
|
+
# Get your response as a Nokogiri::XML::Document using the
|
19
|
+
# Nokogiri.HTML parser
|
17
20
|
def html(flavor=nil)
|
18
21
|
if flavor == :hpricot
|
19
22
|
@_nokogiri_html_hpricot ||= Nokogiri::Hpricot(body)
|
@@ -22,6 +25,9 @@ module ActionController
|
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
28
|
+
###
|
29
|
+
# Get your response as a Nokogiri::XML::Document using the
|
30
|
+
# Nokogiri.XML parser
|
25
31
|
def xml
|
26
32
|
@_nokogiri_xml ||= Nokogiri::XML(body)
|
27
33
|
end
|
data/lib/nokogiri.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# Modify the PATH on windows so that the external DLLs will get loaded.
|
2
3
|
ENV['PATH'] = [File.expand_path(
|
3
4
|
File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
|
4
|
-
), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /mswin/i
|
5
|
+
), ENV['PATH']].compact.join(';') if RUBY_PLATFORM =~ /(mswin|mingw)/i
|
5
6
|
|
6
|
-
|
7
|
+
if ENV['NOKOGIRI_FFI'] || RUBY_PLATFORM =~ /java/
|
8
|
+
gem 'ffi', '>=0.4.0' unless RUBY_PLATFORM =~ /java/
|
9
|
+
require 'ffi'
|
10
|
+
require 'nokogiri/ffi/libxml'
|
11
|
+
else
|
12
|
+
require 'nokogiri/nokogiri'
|
13
|
+
end
|
7
14
|
|
8
15
|
require 'nokogiri/version'
|
16
|
+
require 'nokogiri/version_warning'
|
9
17
|
require 'nokogiri/syntax_error'
|
10
18
|
require 'nokogiri/xml'
|
11
19
|
require 'nokogiri/xslt'
|
@@ -47,14 +55,16 @@ module Nokogiri
|
|
47
55
|
def parse string, url = nil, encoding = nil, options = nil
|
48
56
|
doc =
|
49
57
|
if string =~ /^\s*<[^Hh>]*html/i # Probably html
|
50
|
-
Nokogiri::HTML.parse(string, url, encoding, options || 2145)
|
58
|
+
Nokogiri::HTML::Document.parse(string, url, encoding, options || 2145)
|
51
59
|
else
|
52
|
-
Nokogiri::XML.parse(string, url, encoding, options || 2159)
|
60
|
+
Nokogiri::XML::Document.parse(string, url, encoding, options || 2159)
|
53
61
|
end
|
54
62
|
yield doc if block_given?
|
55
63
|
doc
|
56
64
|
end
|
57
65
|
|
66
|
+
###
|
67
|
+
# Create a new Nokogiri::XML::DocumentFragment
|
58
68
|
def make input = nil, opts = {}, &blk
|
59
69
|
if input
|
60
70
|
Nokogiri::HTML.fragment(input).children.first
|
@@ -62,7 +72,7 @@ module Nokogiri
|
|
62
72
|
Nokogiri(&blk)
|
63
73
|
end
|
64
74
|
end
|
65
|
-
|
75
|
+
|
66
76
|
###
|
67
77
|
# Parse a document and add the Slop decorator. The Slop decorator
|
68
78
|
# implements method_missing such that methods may be used instead of CSS
|
@@ -84,6 +94,12 @@ module Nokogiri
|
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
97
|
+
###
|
98
|
+
# Parser a document contained in +args+. Nokogiri will try to guess what
|
99
|
+
# type of document you are attempting to parse. For more information, see
|
100
|
+
# Nokogiri.parse
|
101
|
+
#
|
102
|
+
# To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
|
87
103
|
def Nokogiri(*args, &block)
|
88
104
|
if block_given?
|
89
105
|
builder = Nokogiri::HTML::Builder.new(&block)
|
@@ -147,13 +147,13 @@ racc_reduce_table = [
|
|
147
147
|
2, 43, :_reduce_53,
|
148
148
|
2, 43, :_reduce_54,
|
149
149
|
0, 43, :_reduce_none,
|
150
|
-
1, 48, :
|
151
|
-
1, 48, :
|
152
|
-
1, 48, :
|
153
|
-
1, 48, :
|
154
|
-
1, 48, :
|
155
|
-
1, 48, :
|
156
|
-
1, 48, :
|
150
|
+
1, 48, :_reduce_56,
|
151
|
+
1, 48, :_reduce_57,
|
152
|
+
1, 48, :_reduce_58,
|
153
|
+
1, 48, :_reduce_59,
|
154
|
+
1, 48, :_reduce_60,
|
155
|
+
1, 48, :_reduce_61,
|
156
|
+
1, 48, :_reduce_62,
|
157
157
|
3, 38, :_reduce_63,
|
158
158
|
1, 49, :_reduce_none ]
|
159
159
|
|
@@ -680,19 +680,54 @@ module_eval(<<'.,.,', 'parser.y', 203)
|
|
680
680
|
|
681
681
|
# reduce 55 omitted
|
682
682
|
|
683
|
-
|
683
|
+
module_eval(<<'.,.,', 'parser.y', 207)
|
684
|
+
def _reduce_56(val, _values, result)
|
685
|
+
result = :equal
|
686
|
+
result
|
687
|
+
end
|
688
|
+
.,.,
|
684
689
|
|
685
|
-
|
690
|
+
module_eval(<<'.,.,', 'parser.y', 208)
|
691
|
+
def _reduce_57(val, _values, result)
|
692
|
+
result = :prefix_match
|
693
|
+
result
|
694
|
+
end
|
695
|
+
.,.,
|
686
696
|
|
687
|
-
|
697
|
+
module_eval(<<'.,.,', 'parser.y', 209)
|
698
|
+
def _reduce_58(val, _values, result)
|
699
|
+
result = :suffix_match
|
700
|
+
result
|
701
|
+
end
|
702
|
+
.,.,
|
688
703
|
|
689
|
-
|
704
|
+
module_eval(<<'.,.,', 'parser.y', 210)
|
705
|
+
def _reduce_59(val, _values, result)
|
706
|
+
result = :substring_match
|
707
|
+
result
|
708
|
+
end
|
709
|
+
.,.,
|
690
710
|
|
691
|
-
|
711
|
+
module_eval(<<'.,.,', 'parser.y', 211)
|
712
|
+
def _reduce_60(val, _values, result)
|
713
|
+
result = :not_equal
|
714
|
+
result
|
715
|
+
end
|
716
|
+
.,.,
|
692
717
|
|
693
|
-
|
718
|
+
module_eval(<<'.,.,', 'parser.y', 212)
|
719
|
+
def _reduce_61(val, _values, result)
|
720
|
+
result = :includes
|
721
|
+
result
|
722
|
+
end
|
723
|
+
.,.,
|
694
724
|
|
695
|
-
|
725
|
+
module_eval(<<'.,.,', 'parser.y', 213)
|
726
|
+
def _reduce_62(val, _values, result)
|
727
|
+
result = :dash_match
|
728
|
+
result
|
729
|
+
end
|
730
|
+
.,.,
|
696
731
|
|
697
732
|
module_eval(<<'.,.,', 'parser.y', 217)
|
698
733
|
def _reduce_63(val, _values, result)
|
data/lib/nokogiri/css/node.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
module CSS
|
3
3
|
class Node
|
4
|
-
|
4
|
+
# Get the type of this node
|
5
|
+
attr_accessor :type
|
6
|
+
# Get the value of this node
|
7
|
+
attr_accessor :value
|
8
|
+
|
9
|
+
# Create a new Node with +type+ and +value+
|
5
10
|
def initialize type, value
|
6
11
|
@type = type
|
7
12
|
@value = value
|
8
13
|
end
|
9
14
|
|
15
|
+
# Accept +visitor+
|
10
16
|
def accept visitor
|
11
17
|
visitor.send(:"visit_#{type.to_s.downcase}", self)
|
12
18
|
end
|
@@ -18,6 +24,7 @@ module Nokogiri
|
|
18
24
|
prefix + visitor.accept(self)
|
19
25
|
end
|
20
26
|
|
27
|
+
# Preprocess this node tree
|
21
28
|
def preprocess!
|
22
29
|
### Deal with nth-child
|
23
30
|
matches = find_by_type(
|
@@ -67,14 +74,15 @@ module Nokogiri
|
|
67
74
|
match.value[1] = Node.new(:COMBINATOR, [
|
68
75
|
Node.new(:FUNCTION, ["#{match.value[1].value.first}("]),
|
69
76
|
Node.new(:FUNCTION, ['self(', tag_name])
|
70
|
-
])
|
77
|
+
])
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
74
81
|
self
|
75
82
|
end
|
76
83
|
|
77
|
-
|
84
|
+
# Find a node by type using +types+
|
85
|
+
def find_by_type types
|
78
86
|
matches = []
|
79
87
|
matches << self if to_type == types
|
80
88
|
@value.each do |v|
|
@@ -83,12 +91,14 @@ module Nokogiri
|
|
83
91
|
matches
|
84
92
|
end
|
85
93
|
|
94
|
+
# Convert to_type
|
86
95
|
def to_type
|
87
96
|
[@type] + @value.map { |n|
|
88
97
|
n.to_type if n.respond_to?(:to_type)
|
89
98
|
}.compact
|
90
99
|
end
|
91
100
|
|
101
|
+
# Convert to array
|
92
102
|
def to_a
|
93
103
|
[@type] + @value.map { |n| n.respond_to?(:to_a) ? n.to_a : [n] }
|
94
104
|
end
|
data/lib/nokogiri/css/parser.rb
CHANGED
@@ -8,24 +8,29 @@ module Nokogiri
|
|
8
8
|
@mutex = Mutex.new
|
9
9
|
|
10
10
|
class << self
|
11
|
+
# Turn on CSS parse caching
|
11
12
|
attr_accessor :cache_on
|
12
13
|
alias :cache_on? :cache_on
|
13
14
|
alias :set_cache :cache_on=
|
14
15
|
|
16
|
+
# Get the css selector in +string+ from the cache
|
15
17
|
def [] string
|
16
18
|
return unless @cache_on
|
17
19
|
@mutex.synchronize { @cache[string] }
|
18
20
|
end
|
19
21
|
|
22
|
+
# Set the css selector in +string+ in the cache to +value+
|
20
23
|
def []= string, value
|
21
24
|
return value unless @cache_on
|
22
25
|
@mutex.synchronize { @cache[string] = value }
|
23
26
|
end
|
24
27
|
|
28
|
+
# Clear the cache
|
25
29
|
def clear_cache
|
26
30
|
@mutex.synchronize { @cache = {} }
|
27
31
|
end
|
28
32
|
|
33
|
+
# Execute +block+ without cache
|
29
34
|
def without_cache &block
|
30
35
|
tmp = @cache_on
|
31
36
|
@cache_on = false
|
@@ -45,12 +50,14 @@ module Nokogiri
|
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
53
|
+
# Create a new CSS parser with respect to +namespaces+
|
48
54
|
def initialize namespaces = {}
|
49
55
|
@namespaces = namespaces
|
50
56
|
super()
|
51
57
|
end
|
52
58
|
alias :parse :scan_str
|
53
59
|
|
60
|
+
# Get the xpath for +string+ using +options+
|
54
61
|
def xpath_for string, options={}
|
55
62
|
key = string + options[:ns].to_s
|
56
63
|
v = self.class[key]
|
@@ -65,6 +72,7 @@ module Nokogiri
|
|
65
72
|
}
|
66
73
|
end
|
67
74
|
|
75
|
+
# On CSS parser error, raise an exception
|
68
76
|
def on_error error_token_id, error_value, value_stack
|
69
77
|
after = value_stack.compact.last
|
70
78
|
raise SyntaxError.new("unexpected '#{error_value}' after '#{after}'")
|
data/lib/nokogiri/css/parser.y
CHANGED
@@ -205,13 +205,13 @@ rule
|
|
205
205
|
|
|
206
206
|
;
|
207
207
|
eql_incl_dash
|
208
|
-
: EQUAL
|
209
|
-
| PREFIXMATCH
|
210
|
-
| SUFFIXMATCH
|
211
|
-
| SUBSTRINGMATCH
|
212
|
-
| NOT_EQUAL
|
213
|
-
| INCLUDES
|
214
|
-
| DASHMATCH
|
208
|
+
: EQUAL { result = :equal }
|
209
|
+
| PREFIXMATCH { result = :prefix_match }
|
210
|
+
| SUFFIXMATCH { result = :suffix_match }
|
211
|
+
| SUBSTRINGMATCH { result = :substring_match }
|
212
|
+
| NOT_EQUAL { result = :not_equal }
|
213
|
+
| INCLUDES { result = :includes }
|
214
|
+
| DASHMATCH { result = :dash_match }
|
215
215
|
;
|
216
216
|
negation
|
217
217
|
: NOT negation_arg RPAREN {
|