tenderlove-nokogiri 0.0.0.20081001111445

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +105 -0
  3. data/README.txt +51 -0
  4. data/Rakefile +70 -0
  5. data/ext/nokogiri/extconf.rb +24 -0
  6. data/ext/nokogiri/html_document.c +85 -0
  7. data/ext/nokogiri/html_document.h +10 -0
  8. data/ext/nokogiri/html_sax_parser.c +32 -0
  9. data/ext/nokogiri/html_sax_parser.h +11 -0
  10. data/ext/nokogiri/native.c +35 -0
  11. data/ext/nokogiri/native.h +32 -0
  12. data/ext/nokogiri/xml_cdata.c +36 -0
  13. data/ext/nokogiri/xml_cdata.h +9 -0
  14. data/ext/nokogiri/xml_document.c +159 -0
  15. data/ext/nokogiri/xml_document.h +10 -0
  16. data/ext/nokogiri/xml_node.c +573 -0
  17. data/ext/nokogiri/xml_node.h +13 -0
  18. data/ext/nokogiri/xml_node_set.c +90 -0
  19. data/ext/nokogiri/xml_node_set.h +9 -0
  20. data/ext/nokogiri/xml_reader.c +420 -0
  21. data/ext/nokogiri/xml_reader.h +10 -0
  22. data/ext/nokogiri/xml_sax_parser.c +161 -0
  23. data/ext/nokogiri/xml_sax_parser.h +10 -0
  24. data/ext/nokogiri/xml_text.c +25 -0
  25. data/ext/nokogiri/xml_text.h +9 -0
  26. data/ext/nokogiri/xml_xpath.c +39 -0
  27. data/ext/nokogiri/xml_xpath.h +11 -0
  28. data/ext/nokogiri/xml_xpath_context.c +69 -0
  29. data/ext/nokogiri/xml_xpath_context.h +9 -0
  30. data/ext/nokogiri/xslt_stylesheet.c +83 -0
  31. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  32. data/lib/nokogiri.rb +45 -0
  33. data/lib/nokogiri/css.rb +6 -0
  34. data/lib/nokogiri/css/node.rb +95 -0
  35. data/lib/nokogiri/css/parser.rb +24 -0
  36. data/lib/nokogiri/css/parser.y +198 -0
  37. data/lib/nokogiri/css/tokenizer.rb +9 -0
  38. data/lib/nokogiri/css/tokenizer.rex +63 -0
  39. data/lib/nokogiri/css/xpath_visitor.rb +153 -0
  40. data/lib/nokogiri/decorators.rb +1 -0
  41. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  42. data/lib/nokogiri/decorators/hpricot/node.rb +47 -0
  43. data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
  44. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +13 -0
  45. data/lib/nokogiri/hpricot.rb +46 -0
  46. data/lib/nokogiri/html.rb +64 -0
  47. data/lib/nokogiri/html/builder.rb +9 -0
  48. data/lib/nokogiri/html/document.rb +9 -0
  49. data/lib/nokogiri/html/sax/parser.rb +21 -0
  50. data/lib/nokogiri/version.rb +3 -0
  51. data/lib/nokogiri/xml.rb +29 -0
  52. data/lib/nokogiri/xml/after_handler.rb +18 -0
  53. data/lib/nokogiri/xml/before_handler.rb +32 -0
  54. data/lib/nokogiri/xml/builder.rb +79 -0
  55. data/lib/nokogiri/xml/document.rb +22 -0
  56. data/lib/nokogiri/xml/node.rb +162 -0
  57. data/lib/nokogiri/xml/node_set.rb +136 -0
  58. data/lib/nokogiri/xml/reader.rb +14 -0
  59. data/lib/nokogiri/xml/sax.rb +9 -0
  60. data/lib/nokogiri/xml/sax/document.rb +59 -0
  61. data/lib/nokogiri/xml/sax/parser.rb +33 -0
  62. data/lib/nokogiri/xml/text.rb +6 -0
  63. data/lib/nokogiri/xml/xpath.rb +6 -0
  64. data/lib/nokogiri/xslt.rb +11 -0
  65. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  66. data/nokogiri.gemspec +33 -0
  67. data/test/css/test_nthiness.rb +141 -0
  68. data/test/css/test_parser.rb +214 -0
  69. data/test/css/test_tokenizer.rb +162 -0
  70. data/test/files/staff.xml +57 -0
  71. data/test/files/staff.xslt +32 -0
  72. data/test/files/tlm.html +850 -0
  73. data/test/helper.rb +70 -0
  74. data/test/hpricot/files/basic.xhtml +17 -0
  75. data/test/hpricot/files/boingboing.html +2266 -0
  76. data/test/hpricot/files/cy0.html +3653 -0
  77. data/test/hpricot/files/immob.html +400 -0
  78. data/test/hpricot/files/pace_application.html +1320 -0
  79. data/test/hpricot/files/tenderlove.html +16 -0
  80. data/test/hpricot/files/uswebgen.html +220 -0
  81. data/test/hpricot/files/utf8.html +1054 -0
  82. data/test/hpricot/files/week9.html +1723 -0
  83. data/test/hpricot/files/why.xml +19 -0
  84. data/test/hpricot/load_files.rb +7 -0
  85. data/test/hpricot/test_alter.rb +67 -0
  86. data/test/hpricot/test_builder.rb +27 -0
  87. data/test/hpricot/test_parser.rb +412 -0
  88. data/test/hpricot/test_paths.rb +15 -0
  89. data/test/hpricot/test_preserved.rb +72 -0
  90. data/test/hpricot/test_xml.rb +26 -0
  91. data/test/html/sax/test_parser.rb +27 -0
  92. data/test/html/test_builder.rb +78 -0
  93. data/test/html/test_document.rb +22 -0
  94. data/test/test_convert_xpath.rb +173 -0
  95. data/test/test_nokogiri.rb +36 -0
  96. data/test/test_reader.rb +222 -0
  97. data/test/test_xslt_transforms.rb +29 -0
  98. data/test/xml/sax/test_parser.rb +93 -0
  99. data/test/xml/test_builder.rb +16 -0
  100. data/test/xml/test_document.rb +141 -0
  101. data/test/xml/test_node.rb +148 -0
  102. data/test/xml/test_node_set.rb +54 -0
  103. data/test/xml/test_text.rb +13 -0
  104. metadata +191 -0
@@ -0,0 +1,148 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestNode < Nokogiri::TestCase
6
+ def test_find_by_css_with_tilde_eql
7
+ xml = Nokogiri::XML.parse(<<-eoxml)
8
+ <root>
9
+ <a>Hello world</a>
10
+ <a class='foo bar'>Bar</a>
11
+ <a class='bar foo'>Bar</a>
12
+ <a class='bar'>Bar</a>
13
+ <a class='baz bar foo'>Bar</a>
14
+ <a class='bazbarfoo'>Awesome</a>
15
+ <a class='bazbar'>Awesome</a>
16
+ </root>
17
+ eoxml
18
+ set = xml.find_by_css('a[@class~="bar"]')
19
+ assert_equal 4, set.length
20
+ assert_equal ['Bar'], set.map { |node| node.content }.uniq
21
+ end
22
+
23
+ def test_dup
24
+ html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
25
+ found = html.search('//div/a').first
26
+ dup = found.dup
27
+ assert dup
28
+ assert_equal found.content, dup.content
29
+ end
30
+
31
+ def test_search_can_handle_xpath_and_css
32
+ html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
33
+ found = html.search('//div/a', 'div > p')
34
+ length = html.find_by_xpath('//div/a').length +
35
+ html.find_by_css('div > p').length
36
+ assert_equal length, found.length
37
+ end
38
+
39
+ def test_find_by_xpath
40
+ html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
41
+ found = html.find_by_xpath('//div/a')
42
+ assert_equal 3, found.length
43
+ end
44
+
45
+ def test_find_by_css
46
+ html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
47
+ found = html.find_by_css('div > a')
48
+ assert_equal 3, found.length
49
+ end
50
+
51
+ def test_next_sibling
52
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
53
+ assert node = xml.root
54
+ assert sibling = node.child.next_sibling
55
+ assert_equal('employee', sibling.name)
56
+ end
57
+
58
+ def test_previous_sibling
59
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
60
+ assert node = xml.root
61
+ assert sibling = node.child.next_sibling
62
+ assert_equal('employee', sibling.name)
63
+ assert_equal(sibling.previous_sibling, node.child)
64
+ end
65
+
66
+ def test_name=
67
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
68
+ assert node = xml.root
69
+ node.name = 'awesome'
70
+ assert_equal('awesome', node.name)
71
+ end
72
+
73
+ def test_child
74
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
75
+ assert node = xml.root
76
+ assert child = node.child
77
+ assert_equal('text', child.name)
78
+ end
79
+
80
+ def test_key?
81
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
82
+ assert node = xml.search('//address').first
83
+ assert(!node.key?('asdfasdf'))
84
+ end
85
+
86
+ def test_set_property
87
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
88
+ assert node = xml.search('//address').first
89
+ node['foo'] = 'bar'
90
+ assert_equal('bar', node['foo'])
91
+ end
92
+
93
+ def test_attributes
94
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
95
+ assert node = xml.search('//address').first
96
+ assert_nil(node['asdfasdfasdf'])
97
+ assert_equal('Yes', node['domestic'])
98
+
99
+ assert node = xml.search('//address')[2]
100
+ attr = node.attributes
101
+ assert_equal 2, attr.size
102
+ assert_equal 'Yes', attr['domestic']
103
+ assert_equal 'No', attr['street']
104
+ end
105
+
106
+ def test_path
107
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
108
+ assert set = xml.search('//employee')
109
+ assert node = set.first
110
+ assert_equal('/staff/employee[1]', node.path)
111
+ end
112
+
113
+ def test_new_node
114
+ node = Nokogiri::XML::Node.new('form')
115
+ assert_equal('form', node.name)
116
+ assert_nil(node.document)
117
+ end
118
+
119
+ def test_content
120
+ node = Nokogiri::XML::Node.new('form')
121
+ assert_equal('', node.content)
122
+
123
+ node.content = 'hello world!'
124
+ assert_equal('hello world!', node.content)
125
+ end
126
+
127
+ def test_replace
128
+ xml = Nokogiri::XML.parse(File.read(XML_FILE))
129
+ set = xml.search('//employee')
130
+ assert 5, set.length
131
+ assert 0, xml.search('//form').length
132
+
133
+ first = set[0]
134
+ second = set[1]
135
+
136
+ node = Nokogiri::XML::Node.new('form')
137
+ first.replace(node)
138
+
139
+ assert set = xml.search('//employee')
140
+ assert_equal 4, set.length
141
+ assert 1, xml.search('//form').length
142
+
143
+ assert_equal set[0].to_xml, second.to_xml
144
+ end
145
+
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestNodeSet < Nokogiri::TestCase
6
+ def setup
7
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
8
+ end
9
+
10
+ def test_new_nodeset
11
+ node_set = Nokogiri::XML::NodeSet.new
12
+ assert_equal(0, node_set.length)
13
+ node = Nokogiri::XML::Node.new('form')
14
+ node_set << node
15
+ assert_equal(1, node_set.length)
16
+ assert_equal(node, node_set.last)
17
+ end
18
+
19
+ def test_search_on_nodeset
20
+ assert node_set = @xml.search('//employee')
21
+ assert sub_set = node_set.search('.//name')
22
+ assert_equal(node_set.length, sub_set.length)
23
+ end
24
+
25
+ def test_negative_index_works
26
+ assert node_set = @xml.search('//employee')
27
+ assert_equal node_set.last, node_set[-1]
28
+ end
29
+
30
+ def test_large_negative_index_returns_nil
31
+ assert node_set = @xml.search('//employee')
32
+ assert_nil(node_set[-1 * (node_set.length + 1)])
33
+ end
34
+
35
+ def test_node_set_fetches_private_data
36
+ assert node_set = @xml.search('//employee')
37
+
38
+ set = node_set
39
+ assert_equal(set[0], set[0])
40
+ end
41
+
42
+ def test_node_set_returns_0
43
+ assert node_set = @xml.search('//asdkfjhasdlkfjhaldskfh')
44
+ assert_equal(0, node_set.length)
45
+ end
46
+
47
+ def test_wrap
48
+ employees = (@xml/"//employee").wrap("<wrapper/>")
49
+ assert_equal 'wrapper', employees[0].parent.name
50
+ assert_equal 'employee', @xml.search("//wrapper").first.children[0].name
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestText < Nokogiri::TestCase
6
+ def test_new
7
+ node = Text.new('hello world')
8
+ assert node
9
+ assert_equal('hello world', node.content)
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tenderlove-nokogiri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.20081001111445
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Patterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.0
23
+ version:
24
+ description: FIX (describe your package)
25
+ email:
26
+ - aaronp@rubyforge.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - ext/nokogiri/extconf.rb
41
+ - ext/nokogiri/html_document.c
42
+ - ext/nokogiri/html_document.h
43
+ - ext/nokogiri/html_sax_parser.c
44
+ - ext/nokogiri/html_sax_parser.h
45
+ - ext/nokogiri/native.c
46
+ - ext/nokogiri/native.h
47
+ - ext/nokogiri/xml_cdata.c
48
+ - ext/nokogiri/xml_cdata.h
49
+ - ext/nokogiri/xml_document.c
50
+ - ext/nokogiri/xml_document.h
51
+ - ext/nokogiri/xml_node.c
52
+ - ext/nokogiri/xml_node.h
53
+ - ext/nokogiri/xml_node_set.c
54
+ - ext/nokogiri/xml_node_set.h
55
+ - ext/nokogiri/xml_reader.c
56
+ - ext/nokogiri/xml_reader.h
57
+ - ext/nokogiri/xml_sax_parser.c
58
+ - ext/nokogiri/xml_sax_parser.h
59
+ - ext/nokogiri/xml_text.c
60
+ - ext/nokogiri/xml_text.h
61
+ - ext/nokogiri/xml_xpath.c
62
+ - ext/nokogiri/xml_xpath.h
63
+ - ext/nokogiri/xml_xpath_context.c
64
+ - ext/nokogiri/xml_xpath_context.h
65
+ - ext/nokogiri/xslt_stylesheet.c
66
+ - ext/nokogiri/xslt_stylesheet.h
67
+ - lib/nokogiri.rb
68
+ - lib/nokogiri/css.rb
69
+ - lib/nokogiri/css/generated_parser.rb
70
+ - lib/nokogiri/css/generated_tokenizer.rb
71
+ - lib/nokogiri/css/node.rb
72
+ - lib/nokogiri/css/parser.rb
73
+ - lib/nokogiri/css/parser.y
74
+ - lib/nokogiri/css/tokenizer.rb
75
+ - lib/nokogiri/css/tokenizer.rex
76
+ - lib/nokogiri/css/xpath_visitor.rb
77
+ - lib/nokogiri/decorators.rb
78
+ - lib/nokogiri/decorators/hpricot.rb
79
+ - lib/nokogiri/decorators/hpricot/node.rb
80
+ - lib/nokogiri/decorators/hpricot/node_set.rb
81
+ - lib/nokogiri/decorators/hpricot/xpath_visitor.rb
82
+ - lib/nokogiri/hpricot.rb
83
+ - lib/nokogiri/html.rb
84
+ - lib/nokogiri/html/builder.rb
85
+ - lib/nokogiri/html/document.rb
86
+ - lib/nokogiri/html/sax/parser.rb
87
+ - lib/nokogiri/version.rb
88
+ - lib/nokogiri/xml.rb
89
+ - lib/nokogiri/xml/after_handler.rb
90
+ - lib/nokogiri/xml/before_handler.rb
91
+ - lib/nokogiri/xml/builder.rb
92
+ - lib/nokogiri/xml/document.rb
93
+ - lib/nokogiri/xml/node.rb
94
+ - lib/nokogiri/xml/node_set.rb
95
+ - lib/nokogiri/xml/reader.rb
96
+ - lib/nokogiri/xml/sax.rb
97
+ - lib/nokogiri/xml/sax/document.rb
98
+ - lib/nokogiri/xml/sax/parser.rb
99
+ - lib/nokogiri/xml/text.rb
100
+ - lib/nokogiri/xml/xpath.rb
101
+ - lib/nokogiri/xslt.rb
102
+ - lib/nokogiri/xslt/stylesheet.rb
103
+ - nokogiri.gemspec
104
+ - test/css/test_nthiness.rb
105
+ - test/css/test_parser.rb
106
+ - test/css/test_tokenizer.rb
107
+ - test/files/staff.xml
108
+ - test/files/staff.xslt
109
+ - test/files/tlm.html
110
+ - test/helper.rb
111
+ - test/hpricot/files/basic.xhtml
112
+ - test/hpricot/files/boingboing.html
113
+ - test/hpricot/files/cy0.html
114
+ - test/hpricot/files/immob.html
115
+ - test/hpricot/files/pace_application.html
116
+ - test/hpricot/files/tenderlove.html
117
+ - test/hpricot/files/uswebgen.html
118
+ - test/hpricot/files/utf8.html
119
+ - test/hpricot/files/week9.html
120
+ - test/hpricot/files/why.xml
121
+ - test/hpricot/load_files.rb
122
+ - test/hpricot/test_alter.rb
123
+ - test/hpricot/test_builder.rb
124
+ - test/hpricot/test_parser.rb
125
+ - test/hpricot/test_paths.rb
126
+ - test/hpricot/test_preserved.rb
127
+ - test/hpricot/test_xml.rb
128
+ - test/html/sax/test_parser.rb
129
+ - test/html/test_builder.rb
130
+ - test/html/test_document.rb
131
+ - test/test_convert_xpath.rb
132
+ - test/test_nokogiri.rb
133
+ - test/test_reader.rb
134
+ - test/test_xslt_transforms.rb
135
+ - test/xml/sax/test_parser.rb
136
+ - test/xml/test_builder.rb
137
+ - test/xml/test_document.rb
138
+ - test/xml/test_node.rb
139
+ - test/xml/test_node_set.rb
140
+ - test/xml/test_text.rb
141
+ has_rdoc: true
142
+ homepage: http://github.com/tenderlove/nokogiri/tree/master
143
+ post_install_message:
144
+ rdoc_options:
145
+ - --main
146
+ - README.txt
147
+ require_paths:
148
+ - lib
149
+ - ext
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: "0"
155
+ version:
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: "0"
161
+ version:
162
+ requirements: []
163
+
164
+ rubyforge_project: nokogiri
165
+ rubygems_version: 1.2.0
166
+ signing_key:
167
+ specification_version: 2
168
+ summary: FIX (describe your package)
169
+ test_files:
170
+ - test/css/test_nthiness.rb
171
+ - test/css/test_parser.rb
172
+ - test/css/test_tokenizer.rb
173
+ - test/hpricot/test_alter.rb
174
+ - test/hpricot/test_builder.rb
175
+ - test/hpricot/test_parser.rb
176
+ - test/hpricot/test_paths.rb
177
+ - test/hpricot/test_preserved.rb
178
+ - test/hpricot/test_xml.rb
179
+ - test/html/sax/test_parser.rb
180
+ - test/html/test_builder.rb
181
+ - test/html/test_document.rb
182
+ - test/test_convert_xpath.rb
183
+ - test/test_nokogiri.rb
184
+ - test/test_reader.rb
185
+ - test/test_xslt_transforms.rb
186
+ - test/xml/sax/test_parser.rb
187
+ - test/xml/test_builder.rb
188
+ - test/xml/test_document.rb
189
+ - test/xml/test_node.rb
190
+ - test/xml/test_node_set.rb
191
+ - test/xml/test_text.rb