Separate XML attributes by spaces.
This was originally reported by @jrochkind and partially patched by @billdueber. My patches are built upon the latter, but without the need of using Array#map, Array#join, etc. They also contain a few style changes. This fixes #32 and #33.
This commit is contained in:
parent
dd47dd43a0
commit
b8a82b2094
|
@ -211,11 +211,9 @@ module Oga
|
|||
attrs = ''
|
||||
|
||||
attributes.each do |attr|
|
||||
attrs << attr.to_xml
|
||||
attrs << " #{attr.to_xml}"
|
||||
end
|
||||
|
||||
attrs = " #{attrs}" unless attrs.empty?
|
||||
|
||||
return "<#{ns}#{name}#{attrs}>#{body}</#{ns}#{name}>"
|
||||
end
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ describe Oga::XML::Element do
|
|||
instance.to_xml.should == '<foo:p></foo:p>'
|
||||
end
|
||||
|
||||
example 'include the attributes if present' do
|
||||
example 'include a single attribute if present' do
|
||||
instance = described_class.new(
|
||||
:name => 'p',
|
||||
:attributes => [
|
||||
|
@ -272,6 +272,18 @@ describe Oga::XML::Element do
|
|||
instance.to_xml.should == '<p key="value"></p>'
|
||||
end
|
||||
|
||||
example 'include multiple attributes if present' do
|
||||
instance = described_class.new(
|
||||
:name => 'p',
|
||||
:attributes => [
|
||||
Oga::XML::Attribute.new(:name => 'key1', :value => 'value1'),
|
||||
Oga::XML::Attribute.new(:name => 'key2', :value => 'value2'),
|
||||
]
|
||||
)
|
||||
|
||||
instance.to_xml.should == '<p key1="value1" key2="value2"></p>'
|
||||
end
|
||||
|
||||
example 'include the child nodes if present' do
|
||||
instance = described_class.new(
|
||||
:name => 'p',
|
||||
|
|
Loading…
Reference in New Issue