nokogiri 1.0.0-x86-mswin32-60

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 (127) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +120 -0
  3. data/README.ja.txt +86 -0
  4. data/README.txt +87 -0
  5. data/Rakefile +264 -0
  6. data/ext/nokogiri/extconf.rb +59 -0
  7. data/ext/nokogiri/html_document.c +83 -0
  8. data/ext/nokogiri/html_document.h +10 -0
  9. data/ext/nokogiri/html_sax_parser.c +32 -0
  10. data/ext/nokogiri/html_sax_parser.h +11 -0
  11. data/ext/nokogiri/iconv.dll +0 -0
  12. data/ext/nokogiri/libexslt.dll +0 -0
  13. data/ext/nokogiri/libxml2.dll +0 -0
  14. data/ext/nokogiri/libxslt.dll +0 -0
  15. data/ext/nokogiri/native.c +40 -0
  16. data/ext/nokogiri/native.h +51 -0
  17. data/ext/nokogiri/native.so +0 -0
  18. data/ext/nokogiri/xml_cdata.c +52 -0
  19. data/ext/nokogiri/xml_cdata.h +9 -0
  20. data/ext/nokogiri/xml_document.c +159 -0
  21. data/ext/nokogiri/xml_document.h +10 -0
  22. data/ext/nokogiri/xml_dtd.c +117 -0
  23. data/ext/nokogiri/xml_dtd.h +8 -0
  24. data/ext/nokogiri/xml_node.c +709 -0
  25. data/ext/nokogiri/xml_node.h +15 -0
  26. data/ext/nokogiri/xml_node_set.c +124 -0
  27. data/ext/nokogiri/xml_node_set.h +9 -0
  28. data/ext/nokogiri/xml_reader.c +429 -0
  29. data/ext/nokogiri/xml_reader.h +10 -0
  30. data/ext/nokogiri/xml_sax_parser.c +174 -0
  31. data/ext/nokogiri/xml_sax_parser.h +10 -0
  32. data/ext/nokogiri/xml_syntax_error.c +194 -0
  33. data/ext/nokogiri/xml_syntax_error.h +11 -0
  34. data/ext/nokogiri/xml_text.c +29 -0
  35. data/ext/nokogiri/xml_text.h +9 -0
  36. data/ext/nokogiri/xml_xpath.c +46 -0
  37. data/ext/nokogiri/xml_xpath.h +11 -0
  38. data/ext/nokogiri/xml_xpath_context.c +81 -0
  39. data/ext/nokogiri/xml_xpath_context.h +9 -0
  40. data/ext/nokogiri/xslt_stylesheet.c +108 -0
  41. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  42. data/ext/nokogiri/zlib1.dll +0 -0
  43. data/lib/nokogiri.rb +51 -0
  44. data/lib/nokogiri/css.rb +6 -0
  45. data/lib/nokogiri/css/generated_parser.rb +653 -0
  46. data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
  47. data/lib/nokogiri/css/node.rb +95 -0
  48. data/lib/nokogiri/css/parser.rb +24 -0
  49. data/lib/nokogiri/css/parser.y +198 -0
  50. data/lib/nokogiri/css/tokenizer.rb +9 -0
  51. data/lib/nokogiri/css/tokenizer.rex +63 -0
  52. data/lib/nokogiri/css/xpath_visitor.rb +165 -0
  53. data/lib/nokogiri/decorators.rb +1 -0
  54. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  55. data/lib/nokogiri/decorators/hpricot/node.rb +58 -0
  56. data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
  57. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +17 -0
  58. data/lib/nokogiri/hpricot.rb +47 -0
  59. data/lib/nokogiri/html.rb +95 -0
  60. data/lib/nokogiri/html/builder.rb +9 -0
  61. data/lib/nokogiri/html/document.rb +9 -0
  62. data/lib/nokogiri/html/sax/parser.rb +21 -0
  63. data/lib/nokogiri/version.rb +3 -0
  64. data/lib/nokogiri/xml.rb +67 -0
  65. data/lib/nokogiri/xml/after_handler.rb +18 -0
  66. data/lib/nokogiri/xml/before_handler.rb +32 -0
  67. data/lib/nokogiri/xml/builder.rb +79 -0
  68. data/lib/nokogiri/xml/cdata.rb +9 -0
  69. data/lib/nokogiri/xml/document.rb +30 -0
  70. data/lib/nokogiri/xml/dtd.rb +6 -0
  71. data/lib/nokogiri/xml/element.rb +6 -0
  72. data/lib/nokogiri/xml/entity_declaration.rb +9 -0
  73. data/lib/nokogiri/xml/node.rb +195 -0
  74. data/lib/nokogiri/xml/node_set.rb +183 -0
  75. data/lib/nokogiri/xml/notation.rb +6 -0
  76. data/lib/nokogiri/xml/reader.rb +14 -0
  77. data/lib/nokogiri/xml/sax.rb +9 -0
  78. data/lib/nokogiri/xml/sax/document.rb +59 -0
  79. data/lib/nokogiri/xml/sax/parser.rb +33 -0
  80. data/lib/nokogiri/xml/syntax_error.rb +21 -0
  81. data/lib/nokogiri/xml/text.rb +6 -0
  82. data/lib/nokogiri/xml/xpath.rb +6 -0
  83. data/lib/nokogiri/xml/xpath_context.rb +14 -0
  84. data/lib/nokogiri/xslt.rb +11 -0
  85. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  86. data/nokogiri.gemspec +34 -0
  87. data/test/css/test_nthiness.rb +159 -0
  88. data/test/css/test_parser.rb +224 -0
  89. data/test/css/test_tokenizer.rb +162 -0
  90. data/test/css/test_xpath_visitor.rb +54 -0
  91. data/test/files/staff.xml +59 -0
  92. data/test/files/staff.xslt +32 -0
  93. data/test/files/tlm.html +850 -0
  94. data/test/helper.rb +70 -0
  95. data/test/hpricot/files/basic.xhtml +17 -0
  96. data/test/hpricot/files/boingboing.html +2266 -0
  97. data/test/hpricot/files/cy0.html +3653 -0
  98. data/test/hpricot/files/immob.html +400 -0
  99. data/test/hpricot/files/pace_application.html +1320 -0
  100. data/test/hpricot/files/tenderlove.html +16 -0
  101. data/test/hpricot/files/uswebgen.html +220 -0
  102. data/test/hpricot/files/utf8.html +1054 -0
  103. data/test/hpricot/files/week9.html +1723 -0
  104. data/test/hpricot/files/why.xml +19 -0
  105. data/test/hpricot/load_files.rb +7 -0
  106. data/test/hpricot/test_alter.rb +67 -0
  107. data/test/hpricot/test_builder.rb +27 -0
  108. data/test/hpricot/test_parser.rb +423 -0
  109. data/test/hpricot/test_paths.rb +15 -0
  110. data/test/hpricot/test_preserved.rb +78 -0
  111. data/test/hpricot/test_xml.rb +30 -0
  112. data/test/html/sax/test_parser.rb +27 -0
  113. data/test/html/test_builder.rb +78 -0
  114. data/test/html/test_document.rb +86 -0
  115. data/test/test_convert_xpath.rb +180 -0
  116. data/test/test_nokogiri.rb +36 -0
  117. data/test/test_reader.rb +222 -0
  118. data/test/test_xslt_transforms.rb +29 -0
  119. data/test/xml/sax/test_parser.rb +93 -0
  120. data/test/xml/test_builder.rb +16 -0
  121. data/test/xml/test_cdata.rb +18 -0
  122. data/test/xml/test_document.rb +171 -0
  123. data/test/xml/test_dtd.rb +43 -0
  124. data/test/xml/test_node.rb +223 -0
  125. data/test/xml/test_node_set.rb +116 -0
  126. data/test/xml/test_text.rb +13 -0
  127. metadata +217 -0
@@ -0,0 +1,183 @@
1
+ module Nokogiri
2
+ module XML
3
+ class NodeSet
4
+ include Enumerable
5
+
6
+ attr_accessor :document
7
+
8
+ def initialize
9
+ yield self if block_given?
10
+ end
11
+
12
+ ###
13
+ # Get the first element of the NodeSet.
14
+ def first
15
+ self[0]
16
+ end
17
+
18
+ ###
19
+ # Get the last element of the NodeSet.
20
+ def last
21
+ self[length - 1]
22
+ end
23
+
24
+ ###
25
+ # Is this NodeSet empty?
26
+ def empty?
27
+ length == 0
28
+ end
29
+
30
+ ###
31
+ # Insert +datum+ before the first Node in this NodeSet
32
+ def before datum
33
+ first.before datum
34
+ end
35
+
36
+ ###
37
+ # Insert +datum+ after the last Node in this NodeSet
38
+ def after datum
39
+ last.after datum
40
+ end
41
+
42
+ ###
43
+ # Append +node+ to the NodeSet.
44
+ def << node
45
+ push(node)
46
+ end
47
+
48
+ ###
49
+ # Unlink this NodeSet and all Node objects it contains from their
50
+ # current context.
51
+ def unlink
52
+ each { |node| node.unlink }
53
+ self.document = nil
54
+ self
55
+ end
56
+ alias :remove :unlink
57
+
58
+ ###
59
+ # Search this document for +paths+
60
+ def search *paths
61
+ sub_set = NodeSet.new
62
+ document.decorate(sub_set)
63
+ each do |node|
64
+ node.search(*paths).each do |sub_node|
65
+ sub_set << sub_node
66
+ end
67
+ end
68
+ sub_set.document = document
69
+ sub_set
70
+ end
71
+ alias :/ :search
72
+ alias :xpath :search
73
+ alias :css :search
74
+
75
+ ###
76
+ # If path is a string, search this document for +path+ returning the
77
+ # first Node. Otherwise, index in to the array with +path+.
78
+ def at path, ns = {}
79
+ return self[path] if path.is_a?(Numeric)
80
+ search(path, ns).first
81
+ end
82
+
83
+ ###
84
+ # Append the class attribute +name+ to all Node objects in the NodeSet.
85
+ def add_class name
86
+ each do |el|
87
+ next unless el.respond_to? :get_attribute
88
+ classes = el.get_attribute('class').to_s.split(" ")
89
+ el.set_attribute('class', classes.push(name).uniq.join(" "))
90
+ end
91
+ self
92
+ end
93
+
94
+ ###
95
+ # Remove the class attribute +name+ from all Node objects in the NodeSet.
96
+ def remove_class name = nil
97
+ each do |el|
98
+ next unless el.respond_to? :get_attribute
99
+ if name
100
+ classes = el.get_attribute('class').to_s.split(" ")
101
+ el.set_attribute('class', (classes - [name]).uniq.join(" "))
102
+ else
103
+ el.remove_attribute("class")
104
+ end
105
+ end
106
+ self
107
+ end
108
+
109
+ ###
110
+ # Set the attribute +key+ to +value+ or the return value of +blk+
111
+ # on all Node objects in the NodeSet.
112
+ def attr key, value = nil, &blk
113
+ if value or blk
114
+ each do |el|
115
+ el.set_attribute(key, value || blk[el])
116
+ end
117
+ return self
118
+ end
119
+ if key.is_a? Hash
120
+ key.each { |k,v| self.attr(k,v) }
121
+ return self
122
+ else
123
+ return self[0].get_attribute(key)
124
+ end
125
+ end
126
+ alias_method :set, :attr
127
+
128
+ ###
129
+ # Remove the attributed named +name+ from all Node objects in the NodeSet
130
+ def remove_attr name
131
+ each do |el|
132
+ next unless el.respond_to? :remove_attribute
133
+ el.remove_attribute(name)
134
+ end
135
+ self
136
+ end
137
+
138
+ ###
139
+ # Iterate over each node, yielding to +block+
140
+ def each(&block)
141
+ x = 0
142
+ while x < length
143
+ yield self[x]
144
+ x += 1
145
+ end
146
+ end
147
+
148
+ ###
149
+ # Get the inner text of all contained Node objects
150
+ def inner_text
151
+ collect{|j| j.inner_text}.join('')
152
+ end
153
+ alias :text :inner_text
154
+
155
+ ###
156
+ # Wrap this NodeSet with +html+ or the results of the builder in +blk+
157
+ def wrap(html, &blk)
158
+ each do |j|
159
+ new_parent = Nokogiri.make(html, &blk)
160
+ j.replace(new_parent)
161
+ nest = new_parent
162
+ if nest.child
163
+ nest = nest.child until nest.child.nil?
164
+ end
165
+ j.parent = nest
166
+ end
167
+ self
168
+ end
169
+
170
+ def to_s
171
+ map { |x| x.to_s }.join
172
+ end
173
+
174
+ def to_html
175
+ map { |x| x.to_html }.join('')
176
+ end
177
+
178
+ def size
179
+ length
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,6 @@
1
+ module Nokogiri
2
+ module XML
3
+ class Notation < Struct.new(:name, :public_id, :system_id)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module Nokogiri
2
+ module XML
3
+ class Reader
4
+ include Enumerable
5
+
6
+ def each(&block)
7
+ while node = self.read
8
+ block.call(node)
9
+ end
10
+ end
11
+ private :initialize
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'nokogiri/xml/sax/document'
2
+ require 'nokogiri/xml/sax/parser'
3
+
4
+ module Nokogiri
5
+ module XML
6
+ module SAX
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,59 @@
1
+ module Nokogiri
2
+ module XML
3
+ module SAX
4
+ class Document
5
+ ###
6
+ # Called when document starts parsing
7
+ def start_document
8
+ end
9
+
10
+ ###
11
+ # Called when document ends parsing
12
+ def end_document
13
+ end
14
+
15
+ ###
16
+ # Called at the beginning of an element
17
+ # +name+ is the name of the tag with +attrs+ as attributes
18
+ def start_element name, attrs = []
19
+ end
20
+
21
+ ###
22
+ # Called at the end of an element
23
+ # +name+ is the tag name
24
+ def end_element name
25
+ end
26
+
27
+ ###
28
+ # Characters read between a tag
29
+ # +string+ contains the character data
30
+ def characters string
31
+ end
32
+
33
+ ###
34
+ # Called when comments are encountered
35
+ # +string+ contains the comment data
36
+ def comment string
37
+ end
38
+
39
+ ###
40
+ # Called on document warnings
41
+ # +string+ contains the warning
42
+ def warning string
43
+ end
44
+
45
+ ###
46
+ # Called on document errors
47
+ # +string+ contains the error
48
+ def error string
49
+ end
50
+
51
+ ###
52
+ # Called when cdata blocks are found
53
+ # +string+ contains the cdata content
54
+ def cdata_block string
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ module Nokogiri
2
+ module XML
3
+ module SAX
4
+ class Parser
5
+ attr_accessor :document
6
+ def initialize(doc = XML::SAX::Document.new)
7
+ @document = doc
8
+ end
9
+
10
+ ###
11
+ # Parse given +thing+ which may be a string containing xml, or an
12
+ # IO object.
13
+ def parse thing
14
+ parse_memory(thing.is_a?(IO) ? thing.read : thing)
15
+ end
16
+
17
+ ###
18
+ # Parse given +io+
19
+ def parse_io io
20
+ parse_memory io.read
21
+ end
22
+
23
+ ###
24
+ # Parse a file with +filename+
25
+ def parse_file filename
26
+ raise Errno::ENOENT unless File.exists?(filename)
27
+ raise Errno::EISDIR if File.directory?(filename)
28
+ native_parse_file filename
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Nokogiri
2
+ module XML
3
+ class SyntaxError < SyntaxError
4
+ def none?
5
+ level == 0
6
+ end
7
+
8
+ def warning?
9
+ level == 1
10
+ end
11
+
12
+ def error?
13
+ level == 2
14
+ end
15
+
16
+ def fatal?
17
+ level == 3
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Nokogiri
2
+ module XML
3
+ class Text < Node
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Nokogiri
2
+ module XML
3
+ class XPath
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module Nokogiri
2
+ module XML
3
+ class XPathContext
4
+
5
+ def register_namespaces(namespaces)
6
+ namespaces.each do |k, v|
7
+ k = k.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
8
+ register_ns(k, v)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'nokogiri/xslt/stylesheet'
2
+
3
+ module Nokogiri
4
+ module XSLT
5
+ class << self
6
+ def parse(string)
7
+ Stylesheet.parse_stylesheet_doc(XML.parse(string))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Nokogiri
2
+ module XSLT
3
+ class Stylesheet
4
+ end
5
+ end
6
+ end
data/nokogiri.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{nokogiri}
3
+ s.version = "1.0.0"
4
+ s.platform = %q{x86-mswin32-60}
5
+
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.authors = ["Aaron Patterson"]
8
+ s.date = %q{2008-10-30}
9
+ s.description = %q{Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser.}
10
+ s.email = ["aaronp@rubyforge.org"]
11
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.ja.txt", "README.txt"]
12
+ s.files = ["History.txt", "Manifest.txt", "README.ja.txt", "README.txt", "Rakefile", "ext/nokogiri/extconf.rb", "ext/nokogiri/html_document.c", "ext/nokogiri/html_document.h", "ext/nokogiri/html_sax_parser.c", "ext/nokogiri/html_sax_parser.h", "ext/nokogiri/native.c", "ext/nokogiri/native.h", "ext/nokogiri/xml_cdata.c", "ext/nokogiri/xml_cdata.h", "ext/nokogiri/xml_document.c", "ext/nokogiri/xml_document.h", "ext/nokogiri/xml_dtd.c", "ext/nokogiri/xml_dtd.h", "ext/nokogiri/xml_node.c", "ext/nokogiri/xml_node.h", "ext/nokogiri/xml_node_set.c", "ext/nokogiri/xml_node_set.h", "ext/nokogiri/xml_reader.c", "ext/nokogiri/xml_reader.h", "ext/nokogiri/xml_sax_parser.c", "ext/nokogiri/xml_sax_parser.h", "ext/nokogiri/xml_syntax_error.c", "ext/nokogiri/xml_syntax_error.h", "ext/nokogiri/xml_text.c", "ext/nokogiri/xml_text.h", "ext/nokogiri/xml_xpath.c", "ext/nokogiri/xml_xpath.h", "ext/nokogiri/xml_xpath_context.c", "ext/nokogiri/xml_xpath_context.h", "ext/nokogiri/xslt_stylesheet.c", "ext/nokogiri/xslt_stylesheet.h", "lib/nokogiri.rb", "lib/nokogiri/css.rb", "lib/nokogiri/css/generated_parser.rb", "lib/nokogiri/css/generated_tokenizer.rb", "lib/nokogiri/css/node.rb", "lib/nokogiri/css/parser.rb", "lib/nokogiri/css/parser.y", "lib/nokogiri/css/tokenizer.rb", "lib/nokogiri/css/tokenizer.rex", "lib/nokogiri/css/xpath_visitor.rb", "lib/nokogiri/decorators.rb", "lib/nokogiri/decorators/hpricot.rb", "lib/nokogiri/decorators/hpricot/node.rb", "lib/nokogiri/decorators/hpricot/node_set.rb", "lib/nokogiri/decorators/hpricot/xpath_visitor.rb", "lib/nokogiri/hpricot.rb", "lib/nokogiri/html.rb", "lib/nokogiri/html/builder.rb", "lib/nokogiri/html/document.rb", "lib/nokogiri/html/sax/parser.rb", "lib/nokogiri/version.rb", "lib/nokogiri/xml.rb", "lib/nokogiri/xml/after_handler.rb", "lib/nokogiri/xml/before_handler.rb", "lib/nokogiri/xml/builder.rb", "lib/nokogiri/xml/cdata.rb", "lib/nokogiri/xml/document.rb", "lib/nokogiri/xml/dtd.rb", "lib/nokogiri/xml/element.rb", "lib/nokogiri/xml/entity_declaration.rb", "lib/nokogiri/xml/node.rb", "lib/nokogiri/xml/node_set.rb", "lib/nokogiri/xml/notation.rb", "lib/nokogiri/xml/reader.rb", "lib/nokogiri/xml/sax.rb", "lib/nokogiri/xml/sax/document.rb", "lib/nokogiri/xml/sax/parser.rb", "lib/nokogiri/xml/syntax_error.rb", "lib/nokogiri/xml/text.rb", "lib/nokogiri/xml/xpath.rb", "lib/nokogiri/xml/xpath_context.rb", "lib/nokogiri/xslt.rb", "lib/nokogiri/xslt/stylesheet.rb", "nokogiri.gemspec", "test/css/test_nthiness.rb", "test/css/test_parser.rb", "test/css/test_tokenizer.rb", "test/css/test_xpath_visitor.rb", "test/files/staff.xml", "test/files/staff.xslt", "test/files/tlm.html", "test/helper.rb", "test/hpricot/files/basic.xhtml", "test/hpricot/files/boingboing.html", "test/hpricot/files/cy0.html", "test/hpricot/files/immob.html", "test/hpricot/files/pace_application.html", "test/hpricot/files/tenderlove.html", "test/hpricot/files/uswebgen.html", "test/hpricot/files/utf8.html", "test/hpricot/files/week9.html", "test/hpricot/files/why.xml", "test/hpricot/load_files.rb", "test/hpricot/test_alter.rb", "test/hpricot/test_builder.rb", "test/hpricot/test_parser.rb", "test/hpricot/test_paths.rb", "test/hpricot/test_preserved.rb", "test/hpricot/test_xml.rb", "test/html/sax/test_parser.rb", "test/html/test_builder.rb", "test/html/test_document.rb", "test/test_convert_xpath.rb", "test/test_nokogiri.rb", "test/test_reader.rb", "test/test_xslt_transforms.rb", "test/xml/sax/test_parser.rb", "test/xml/test_builder.rb", "test/xml/test_cdata.rb", "test/xml/test_document.rb", "test/xml/test_dtd.rb", "test/xml/test_node.rb", "test/xml/test_node_set.rb", "test/xml/test_text.rb", "ext/nokogiri/iconv.dll", "ext/nokogiri/libexslt.dll", "ext/nokogiri/libxml2.dll", "ext/nokogiri/libxslt.dll", "ext/nokogiri/zlib1.dll", "ext/nokogiri/native.so"]
13
+ s.has_rdoc = true
14
+ s.homepage = %q{http://nokogiri.rubyforge.org/}
15
+ s.rdoc_options = ["--main", "README.txt"]
16
+ s.require_paths = ["lib", "ext"]
17
+ s.rubyforge_project = %q{nokogiri}
18
+ s.rubygems_version = %q{1.2.0}
19
+ s.summary = %q{Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser.}
20
+ s.test_files = ["test/css/test_nthiness.rb", "test/css/test_parser.rb", "test/css/test_tokenizer.rb", "test/css/test_xpath_visitor.rb", "test/hpricot/test_alter.rb", "test/hpricot/test_builder.rb", "test/hpricot/test_parser.rb", "test/hpricot/test_paths.rb", "test/hpricot/test_preserved.rb", "test/hpricot/test_xml.rb", "test/html/sax/test_parser.rb", "test/html/test_builder.rb", "test/html/test_document.rb", "test/test_convert_xpath.rb", "test/test_nokogiri.rb", "test/test_reader.rb", "test/test_xslt_transforms.rb", "test/xml/sax/test_parser.rb", "test/xml/test_builder.rb", "test/xml/test_cdata.rb", "test/xml/test_document.rb", "test/xml/test_dtd.rb", "test/xml/test_node.rb", "test/xml/test_node_set.rb", "test/xml/test_text.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if current_version >= 3 then
27
+ s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
28
+ else
29
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
33
+ end
34
+ end
@@ -0,0 +1,159 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module CSS
5
+ class TestNthiness < Nokogiri::TestCase
6
+ def setup
7
+ doc = <<EOF
8
+ <html>
9
+ <table>
10
+ <tr><td>row1 </td></tr>
11
+ <tr><td>row2 </td></tr>
12
+ <tr><td>row3 </td></tr>
13
+ <tr><td>row4 </td></tr>
14
+ <tr><td>row5 </td></tr>
15
+ <tr><td>row6 </td></tr>
16
+ <tr><td>row7 </td></tr>
17
+ <tr><td>row8 </td></tr>
18
+ <tr><td>row9 </td></tr>
19
+ <tr><td>row10 </td></tr>
20
+ <tr><td>row11 </td></tr>
21
+ <tr><td>row12 </td></tr>
22
+ <tr><td>row13 </td></tr>
23
+ <tr><td>row14 </td></tr>
24
+ </table>
25
+ <div>
26
+ <b>bold1 </b>
27
+ <i>italic1 </i>
28
+ <b>bold2 </b>
29
+ <i>italic2 </i>
30
+ <p>para1 </p>
31
+ <b>bold3 </b>
32
+ </div>
33
+ <div>
34
+ <p>para2 </p>
35
+ <p>para3 </p>
36
+ </div>
37
+ <div>
38
+ <p>para4 </p>
39
+ </div>
40
+ <p class='empty'></p>
41
+ <p class='not-empty'><b></b></p>
42
+ </html>
43
+ EOF
44
+ @parser = Nokogiri.Hpricot doc
45
+ end
46
+
47
+
48
+ def test_even
49
+ assert_result_rows [2,4,6,8,10,12,14], @parser.search("table/tr:nth(even)")
50
+ end
51
+
52
+ def test_odd
53
+ assert_result_rows [1,3,5,7,9,11,13], @parser.search("table/tr:nth(odd)")
54
+ end
55
+
56
+ def test_2n
57
+ assert_equal @parser.search("table/tr:nth(even)").inner_text, @parser.search("table/tr:nth(2n)").inner_text
58
+ end
59
+
60
+ def test_2np1
61
+ assert_equal @parser.search("table/tr:nth(odd)").inner_text, @parser.search("table/tr:nth(2n+1)").inner_text
62
+ end
63
+
64
+ def test_4np3
65
+ assert_result_rows [3,7,11], @parser.search("table/tr:nth(4n+3)")
66
+ end
67
+
68
+ def test_3np4
69
+ assert_result_rows [4,7,10,13], @parser.search("table/tr:nth(3n+4)")
70
+ end
71
+
72
+ def test_mnp3
73
+ assert_result_rows [1,2,3], @parser.search("table/tr:nth(-n+3)")
74
+ end
75
+
76
+ def test_np3
77
+ assert_result_rows [3,4,5,6,7,8,9,10,11,12,13,14], @parser.search("table/tr:nth(n+3)")
78
+ end
79
+
80
+ def test_first
81
+ assert_result_rows [1], @parser.search("table/tr:first")
82
+ assert_result_rows [1], @parser.search("table/tr:first()")
83
+ end
84
+
85
+ def test_last
86
+ assert_result_rows [14], @parser.search("table/tr:last")
87
+ assert_result_rows [14], @parser.search("table/tr:last()")
88
+ end
89
+
90
+ def test_first_child
91
+ assert_result_rows [1], @parser.search("div/b:first-child"), "bold"
92
+ assert_result_rows [1], @parser.search("table/tr:first-child")
93
+ end
94
+
95
+ def test_last_child
96
+ assert_result_rows [3], @parser.search("div/b:last-child"), "bold"
97
+ assert_result_rows [14], @parser.search("table/tr:last-child")
98
+ end
99
+
100
+ def test_first_of_type
101
+ assert_result_rows [1], @parser.search("table/tr:first-of-type")
102
+ assert_result_rows [1], @parser.search("div/b:first-of-type"), "bold"
103
+ end
104
+
105
+ def test_last_of_type
106
+ assert_result_rows [14], @parser.search("table/tr:last-of-type")
107
+ assert_result_rows [3], @parser.search("div/b:last-of-type"), "bold"
108
+ end
109
+
110
+ def test_only_of_type
111
+ assert_result_rows [1,4], @parser.search("div/p:only-of-type"), "para"
112
+ end
113
+
114
+ def test_only_child
115
+ assert_result_rows [4], @parser.search("div/p:only-child"), "para"
116
+ end
117
+
118
+ def test_empty
119
+ result = @parser.search("p:empty")
120
+ assert_equal 1, result.size, "unexpected number of rows returned: '#{result.inner_text}'"
121
+ assert_equal 'empty', result.first['class']
122
+ end
123
+
124
+ def test_parent
125
+ result = @parser.search("p:parent")
126
+ assert_equal 5, result.size
127
+ 0.upto(3) do |j|
128
+ assert_equal "para#{j+1} ", result[j].inner_text
129
+ end
130
+ assert_equal "not-empty", result[4]['class']
131
+ end
132
+
133
+ def test_siblings
134
+ doc = <<-EOF
135
+ <html><body><div>
136
+ <p id="1">p1 </p>
137
+ <p id="2">p2 </p>
138
+ <p id="3">p3 </p>
139
+ <p id="4">p4 </p>
140
+ <p id="5">p5 </p>
141
+ EOF
142
+ parser = Nokogiri.Hpricot doc
143
+
144
+ assert_equal 2, parser.search("#3 ~ p").size
145
+ assert_equal "p4 p5 ", parser.search("#3 ~ p").inner_text
146
+ assert_equal 0, parser.search("#5 ~ p").size
147
+
148
+ assert_equal 1, parser.search("#3 + p").size
149
+ assert_equal "p4 ", parser.search("#3 + p").inner_text
150
+ assert_equal 0, parser.search("#5 + p").size
151
+ end
152
+
153
+ def assert_result_rows intarray, result, word="row"
154
+ assert_equal intarray.size, result.size, "unexpected number of rows returned: '#{result.inner_text}'"
155
+ assert_equal intarray.map{|j| "#{word}#{j}"}.join(' '), result.inner_text.strip, result.inner_text
156
+ end
157
+ end
158
+ end
159
+ end