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:
Yorick Peterse 2014-09-13 11:47:06 +02:00
parent dd47dd43a0
commit b8a82b2094
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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',