hpricot 0.8.1-x86-mswin32 → 0.8.2-x86-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -132,6 +132,8 @@ static VALUE reProcInsParse;
132
132
  }
133
133
 
134
134
  action save_attr {
135
+ if (!S->xml)
136
+ akey = rb_funcall(akey, s_downcase, 0);
135
137
  ATTR(akey, aval);
136
138
  }
137
139
 
Binary file
@@ -38,15 +38,20 @@ module Hpricot
38
38
  end
39
39
  end
40
40
 
41
- class Elem
42
- def initialize tag, attrs = nil, children = nil, etag = nil
43
- self.name, self.raw_attributes, self.children, self.etag =
44
- tag, attrs, children, etag
41
+ class Attributes
42
+ attr_accessor :element
43
+ def initialize e
44
+ @element = e
45
45
  end
46
- def empty?; children.nil? or children.empty? end
47
- def attributes
48
- if raw_attributes
49
- raw_attributes.inject({}) do |hsh, (k, v)|
46
+ def [] k
47
+ Hpricot.uxs((@element.raw_attributes || {})[k])
48
+ end
49
+ def []= k, v
50
+ (@element.raw_attributes ||= {})[k] = v.fast_xs
51
+ end
52
+ def to_hash
53
+ if @element.raw_attributes
54
+ @element.raw_attributes.inject({}) do |hsh, (k, v)|
50
55
  hsh[k] = Hpricot.uxs(v)
51
56
  hsh
52
57
  end
@@ -54,6 +59,23 @@ module Hpricot
54
59
  {}
55
60
  end
56
61
  end
62
+ def to_s
63
+ to_hash.to_s
64
+ end
65
+ def inspect
66
+ to_hash.inspect
67
+ end
68
+ end
69
+
70
+ class Elem
71
+ def initialize tag, attrs = nil, children = nil, etag = nil
72
+ self.name, self.raw_attributes, self.children, self.etag =
73
+ tag, attrs, children, etag
74
+ end
75
+ def empty?; children.nil? or children.empty? end
76
+ def attributes
77
+ Attributes.new self
78
+ end
57
79
  def to_plain_text
58
80
  if self.name == 'br'
59
81
  "\n"
@@ -102,10 +124,7 @@ module Hpricot
102
124
  class BogusETag
103
125
  def initialize name; self.name = name end
104
126
  def output(out, opts = {})
105
- out <<
106
- if_output(opts) do
107
- "</#{name}>"
108
- end
127
+ out << if_output(opts) { "" }
109
128
  end
110
129
  end
111
130
 
@@ -194,6 +194,7 @@ module Hpricot
194
194
  alias_method :innerHTML=, :inner_html=
195
195
 
196
196
  def reparent(nodes)
197
+ return unless nodes
197
198
  altered!
198
199
  [*nodes].each { |e| e.parent = self }
199
200
  end
Binary file
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #!/usr/bin/env ruby
2
3
 
3
4
  require 'test/unit'
@@ -35,14 +36,22 @@ class TestAlter < Test::Unit::TestCase
35
36
  end
36
37
 
37
38
  def test_change_attributes
38
- all_ps = (@basic/"p").attr("title", "Some Title")
39
+ all_ps = (@basic/"p").attr("title", "Some Title & Etc…")
39
40
  all_as = (@basic/"a").attr("href", "http://my_new_href.com")
40
41
  all_lb = (@basic/"link").attr("href") { |e| e.name }
41
- assert_changed(@basic, "p", all_ps) {|p| p.attributes["title"] == "Some Title"}
42
+ assert_changed(@basic, "p", all_ps) {|p| p.raw_attributes["title"] == "Some Title &amp; Etc&#8230;"}
42
43
  assert_changed(@basic, "a", all_as) {|a| a.attributes["href"] == "http://my_new_href.com"}
43
44
  assert_changed(@basic, "link", all_lb) {|a| a.attributes["href"] == "link" }
44
45
  end
45
46
 
47
+ def test_change_attributes2
48
+ all_as = (@basic%"a").attributes["href"] = "http://my_new_href.com"
49
+ all_ps = (@basic%"p").attributes["title"] = "Some Title & Etc…"
50
+ assert_equal (@basic%"a").raw_attributes["href"], "http://my_new_href.com"
51
+ assert_equal (@basic%"p").raw_attributes["title"], "Some Title &amp; Etc&#8230;"
52
+ assert_equal (@basic%"p").attributes["title"], "Some Title & Etc…"
53
+ end
54
+
46
55
  def test_remove_attr
47
56
  all_rl = (@basic/"link").remove_attr("href")
48
57
  assert_changed(@basic, "link", all_rl) { |link| link['href'].nil? }
@@ -70,6 +79,16 @@ class TestAlter < Test::Unit::TestCase
70
79
  assert_equal frag.to_s, "<b><i>A bit of HTML</i></b><beanPole>gravity</beanPole>"
71
80
  end
72
81
 
82
+ def test_reparent_empty_nodes
83
+ doc = Hpricot("<div/>")
84
+ doc.root.inner_html = "foo"
85
+ assert_equal doc.root.inner_html, "foo"
86
+ doc.root.inner_html = ""
87
+ assert_equal doc.root.inner_html, ""
88
+ doc.root.swap { b "test" }
89
+ assert_equal doc.root.inner_html, "test"
90
+ end
91
+
73
92
  def assert_changed original, selector, set, &block
74
93
  assert set.all?(&block)
75
94
  assert Hpricot(original.to_html).search(selector).all?(&block)
@@ -227,6 +227,14 @@ class TestParser < Test::Unit::TestCase
227
227
  assert_kind_of Hpricot::Elements, @boingboing.search('//div/p').search('a img')
228
228
  end
229
229
 
230
+ def test_attr_casing
231
+ doc = Hpricot("<a HREF='a'>A simple <b>test</b> string.</a>")
232
+ assert_equal (doc % :a)[:href], "a"
233
+ assert_equal (doc % :a)[:HREF], nil
234
+ assert_equal (doc % :a)['href'], "a"
235
+ assert_equal (doc % :a)['HREF'], nil
236
+ end
237
+
230
238
  def test_class_search
231
239
  # test case sent by Chih-Chao Lam
232
240
  doc = Hpricot("<div class=xyz'>abc</div>")
@@ -5,6 +5,15 @@ require 'test/unit'
5
5
  require 'hpricot'
6
6
  require 'load_files'
7
7
 
8
+ unless "".respond_to?(:lines)
9
+ require 'enumerator'
10
+ class String
11
+ def lines
12
+ Enumerable::Enumerator.new(self, :each_line)
13
+ end
14
+ end
15
+ end
16
+
8
17
  class TestPreserved < Test::Unit::TestCase
9
18
  def assert_roundtrip str
10
19
  doc = Hpricot(str)
@@ -53,6 +62,15 @@ class TestPreserved < Test::Unit::TestCase
53
62
  assert_roundtrip TestFiles::CY0
54
63
  end
55
64
 
65
+ def test_fixup_link
66
+ doc = %{<?xml version="1.0" encoding="UTF-8"?><rss><channel><link>ht</link></channel></rss>}
67
+ assert_roundtrip doc
68
+ assert_equal Hpricot(doc).to_s,
69
+ %{<?xml version="1.0" encoding="UTF-8"?><rss><channel><link />ht</channel></rss>}
70
+ assert_equal Hpricot.XML(doc).to_s,
71
+ %{<?xml version="1.0" encoding="UTF-8"?><rss><channel><link>ht</link></channel></rss>}
72
+ end
73
+
56
74
  def test_escaping_of_attrs
57
75
  # ampersands in URLs
58
76
  str = %{<a href="http://google.com/search?q=hpricot&amp;l=en">Google</a>}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hpricot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: x86-mswin32
6
6
  authors:
7
7
  - why the lucky stiff
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-03 00:00:00 -07:00
12
+ date: 2009-11-05 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,56 +28,57 @@ files:
28
28
  - COPYING
29
29
  - README
30
30
  - Rakefile
31
- - test/test_paths.rb
32
- - test/test_preserved.rb
33
- - test/test_parser.rb
34
- - test/files
31
+ - test/files/basic.xhtml
32
+ - test/files/boingboing.html
35
33
  - test/files/cy0.html
34
+ - test/files/immob.html
36
35
  - test/files/pace_application.html
37
- - test/files/basic.xhtml
36
+ - test/files/tenderlove.html
37
+ - test/files/uswebgen.html
38
38
  - test/files/utf8.html
39
- - test/files/boingboing.html
40
39
  - test/files/week9.html
41
- - test/files/tenderlove.html
42
- - test/files/immob.html
43
40
  - test/files/why.xml
44
- - test/files/uswebgen.html
45
41
  - test/load_files.rb
46
42
  - test/nokogiri-bench.rb
43
+ - test/test_alter.rb
47
44
  - test/test_builder.rb
45
+ - test/test_parser.rb
46
+ - test/test_paths.rb
47
+ - test/test_preserved.rb
48
48
  - test/test_xml.rb
49
- - test/test_alter.rb
50
- - lib/hpricot
51
- - lib/hpricot/tags.rb
49
+ - lib/hpricot/blankslate.rb
52
50
  - lib/hpricot/builder.rb
53
- - lib/hpricot/traverse.rb
54
51
  - lib/hpricot/elements.rb
55
- - lib/hpricot/modules.rb
52
+ - lib/hpricot/htmlinfo.rb
56
53
  - lib/hpricot/inspect.rb
54
+ - lib/hpricot/modules.rb
55
+ - lib/hpricot/parse.rb
57
56
  - lib/hpricot/tag.rb
58
- - lib/hpricot/blankslate.rb
57
+ - lib/hpricot/tags.rb
58
+ - lib/hpricot/traverse.rb
59
59
  - lib/hpricot/xchar.rb
60
- - lib/hpricot/htmlinfo.rb
61
- - lib/hpricot/parse.rb
62
60
  - lib/hpricot.rb
63
61
  - extras/mingw-rbconfig.rb
64
62
  - ext/hpricot_scan/hpricot_scan.h
65
- - ext/hpricot_scan/HpricotScanService.java
66
63
  - ext/fast_xs/FastXsService.java
67
- - ext/hpricot_scan/hpricot_scan.c
68
- - ext/hpricot_scan/hpricot_css.c
64
+ - ext/hpricot_scan/HpricotCss.java
65
+ - ext/hpricot_scan/HpricotScanService.java
69
66
  - ext/fast_xs/fast_xs.c
70
- - ext/hpricot_scan/test.rb
71
- - ext/hpricot_scan/extconf.rb
67
+ - ext/hpricot_scan/hpricot_css.c
68
+ - ext/hpricot_scan/hpricot_scan.c
72
69
  - ext/fast_xs/extconf.rb
73
- - ext/hpricot_scan/hpricot_scan.rl
74
- - ext/hpricot_scan/hpricot_scan.java.rl
75
- - ext/hpricot_scan/hpricot_css.rl
70
+ - ext/hpricot_scan/extconf.rb
76
71
  - ext/hpricot_scan/hpricot_common.rl
72
+ - ext/hpricot_scan/hpricot_css.java.rl
73
+ - ext/hpricot_scan/hpricot_css.rl
74
+ - ext/hpricot_scan/hpricot_scan.java.rl
75
+ - ext/hpricot_scan/hpricot_scan.rl
77
76
  - lib/hpricot_scan.so
78
77
  - lib/fast_xs.so
79
78
  has_rdoc: true
80
79
  homepage: http://code.whytheluckystiff.net/hpricot/
80
+ licenses: []
81
+
81
82
  post_install_message:
82
83
  rdoc_options:
83
84
  - --quiet
@@ -103,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  requirements: []
104
105
 
105
106
  rubyforge_project: hobix
106
- rubygems_version: 1.3.1
107
+ rubygems_version: 1.3.5
107
108
  signing_key:
108
- specification_version: 2
109
+ specification_version: 3
109
110
  summary: a swift, liberal HTML parser with a fantastic library
110
111
  test_files: []
111
112
 
@@ -1,4 +0,0 @@
1
- require './hpricot_scan.so'
2
-
3
- doc = "<doc><person><test>YESSS</test></person><train>SET</train></doc>"
4
- p Hpricot.scan(doc)