niceogiri 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Niceogiri
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -32,8 +32,8 @@ module Niceogiri
32
32
  #
33
33
  # @param [#to_sym] attr_name the name of the attribute
34
34
  # @param [#to_s] value the value to set the attribute to
35
- def write_attr(attr_name, value)
36
- self[attr_name.to_sym] = value
35
+ def write_attr(attr_name, value, to_call = nil)
36
+ self[attr_name.to_sym] = value && to_call ? value.__send__(to_call) : value
37
37
  end
38
38
 
39
39
  # Helper method to read the content of a node
@@ -133,9 +133,15 @@ module Niceogiri
133
133
  # @param [XML::Node] node the node to inherit
134
134
  # @return [self]
135
135
  def inherit(node)
136
- nokogiri_namespace = node.namespace
136
+ self.namespace = node.namespace.href if node.namespace
137
137
  inherit_attrs node.attributes
138
- node.children.each { |c| self << c.dup }
138
+ node.children.each do |c|
139
+ self << (n = c.dup)
140
+ if c.respond_to?(:namespace) && c.namespace
141
+ ns = n.add_namespace c.namespace.prefix, c.namespace.href
142
+ n.namespace = ns
143
+ end
144
+ end
139
145
  self
140
146
  end
141
147
 
data/niceogiri.gemspec CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.rdoc_options = %w{--charset=UTF-8}
20
20
  s.extra_rdoc_files = %w{LICENSE README.md}
21
21
 
22
- s.add_dependency "nokogiri", ["~> 1.4"]
22
+ s.add_dependency "nokogiri", ["~> 1.5"]
23
23
 
24
- s.add_development_dependency "rspec", [">= 2.7.0"]
25
- s.add_development_dependency "bundler", [">= 1.0.0"]
26
- s.add_development_dependency "yard", [">= 0.6.1"]
24
+ s.add_development_dependency "rspec", ["~> 2.7"]
25
+ s.add_development_dependency "bundler", ["~> 1.0"]
26
+ s.add_development_dependency "yard", ["~> 0.6"]
27
27
  s.add_development_dependency "rake"
28
28
  s.add_development_dependency "guard-rspec"
29
29
  end
@@ -46,6 +46,14 @@ module Niceogiri
46
46
  subject[:bar].should == 'baz'
47
47
  end
48
48
 
49
+ it 'provides an attribute writer with conversion' do
50
+ subject[:bar].should be_nil
51
+ subject.write_attr :bar, '1.0', :to_i
52
+ subject[:bar].should == '1'
53
+ subject.write_attr :bar, nil, :to_i
54
+ subject[:bar].should == nil
55
+ end
56
+
49
57
  it 'provides a content reader' do
50
58
  foo = Node.new 'foo'
51
59
  foo << (bar = Node.new('bar', foo.document))
@@ -139,12 +147,21 @@ module Niceogiri
139
147
  n2.to_s.should == n.to_s
140
148
  end
141
149
 
142
- it 'holds on to namespaces when inheriting content' do
150
+ it 'holds on to namespace prefixes when inheriting content' do
143
151
  n = Nokogiri::XML.parse('<message><bar:foo xmlns:bar="http://bar.com"></message>').root
144
152
  n2 = Node.new('message').inherit n
145
153
  n2.to_s.should == n.to_s
146
154
  end
147
155
 
156
+ it 'holds on to namespaces when inheriting content' do
157
+ n = Nokogiri::XML.parse('<message xmlns="foobar"><body xmlns="barfoo"/></message>').root
158
+ n2 = Node.new('message').inherit n
159
+ n2.to_s.should == n.to_s
160
+ n2.namespace.href.should be == 'foobar'
161
+ body = n2.children.first
162
+ body.namespace.href.should be == 'barfoo'
163
+ end
164
+
148
165
  it 'holds on to namespaces without a prefix when inheriting content' do
149
166
  n = Nokogiri::XML.parse('<message><bar:foo xmlns="http://bar.com"></message>').root
150
167
  n2 = Node.new('message').inherit n
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: niceogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-07 00:00:00.000000000 Z
13
+ date: 2012-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: '1.4'
22
+ version: '1.5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,55 +27,55 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: '1.4'
30
+ version: '1.5'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rspec
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
- - - ! '>='
36
+ - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: 2.7.0
38
+ version: '2.7'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ! '>='
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 2.7.0
46
+ version: '2.7'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.0
54
+ version: '1.0'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - ! '>='
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 1.0.0
62
+ version: '1.0'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: yard
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
- - - ! '>='
68
+ - - ~>
69
69
  - !ruby/object:Gem::Version
70
- version: 0.6.1
70
+ version: '0.6'
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
- - - ! '>='
76
+ - - ~>
77
77
  - !ruby/object:Gem::Version
78
- version: 0.6.1
78
+ version: '0.6'
79
79
  - !ruby/object:Gem::Dependency
80
80
  name: rake
81
81
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: 2448257972408275473
151
+ hash: 1354346198489803166
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
@@ -157,10 +157,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 2448257972408275473
160
+ hash: 1354346198489803166
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 1.8.21
163
+ rubygems_version: 1.8.24
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: Some additional niceties atop Nokogiri