Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes not preserved for arrays #31

Closed
cout opened this issue Jun 20, 2013 · 3 comments
Closed

attributes not preserved for arrays #31

cout opened this issue Jun 20, 2013 · 3 comments
Labels
Milestone

Comments

@cout
Copy link

cout commented Jun 20, 2013

This code:

xml = Gyoku.xml({
  'foo' => { '@foo' => 'foo' },
  'bar' => [ { '@bar' => 'bar', 'baz' => { } } ],
})

produces this xml:

<foo foo="foo">
</foo>
<bar>
    <baz>
    </baz>
</bar>

but should produce:

<foo foo="foo">
</foo>
<bar bar="bar">
    <baz>
    </baz>
</bar>

(the attributes are missing when the hash value is an array of hashes).

I looked at array.rb for how to fix this, but it's not obvious to me.

Strathmeyer mentioned this in #18 (comment), but I thought it was better to enter a separate issue for this rather than hijack an existing one.

@rubiii
Copy link
Contributor

rubiii commented Jun 29, 2013

glancing over this, it looks like this could be resolved by #30.
@razum2um what do you think?

razum2um added a commit to razum2um/gyoku that referenced this issue Jun 29, 2013
razum2um added a commit to razum2um/gyoku that referenced this issue Jun 29, 2013
@razum2um
Copy link
Contributor

@cout please see #30
i also included your example into specs - passing now

note 2 things

  1. you needn't use array in this case
hash = {
  :order! => ['foo', 'bar'],
  'foo' => { :@foo => 'foo' },
  'bar' => { :@bar => 'bar', 'baz' => { } },
}
to_xml(hash).should == '<foo foo="foo"></foo><bar bar="bar"><baz></baz></bar>'
  1. order! is needed only in 1.8 to get guaranted order of nodes

@rubiii i think its completly mergable

@rubiii
Copy link
Contributor

rubiii commented Jun 30, 2013

thanks @razum2um!

@rubiii rubiii closed this as completed Jun 30, 2013
@rubiii rubiii mentioned this issue Jul 20, 2013
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants