-
Notifications
You must be signed in to change notification settings - Fork 19
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
First scratch of rexml implementation #46
Conversation
5026169
to
28d40cf
Compare
28d40cf
to
1c42a1b
Compare
@soulcutter I've update a bit the code. Please check it) |
module Saxerator | ||
module Builder | ||
class XmlDocument < REXML::Document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a need for a to_xml
alias? Less might be more here - meaning we just return a bare REXML::Document and let end-users transform it however they prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soulcutter Before this we had a Nokogiri document and he has a :to_xml method.
I thought that it'll be good to backward compatibility.
If it's bad Idea I can remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for removing it and simply returning the REXML::Document object. Technically this library isn't 1.0, so this is a tolerable breaking change.
@soulcutter Also question about output. REXML convert |
1c42a1b
to
b63ceb0
Compare
@soulcutter I've removed out_put type restrictions for different parsers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks alright other than the wrapper for REXML::Document
@@ -100,7 +100,7 @@ end | |||
| Setting | Default | Values | Description | |||
|:------------------|:--------|-----------------|------------ | |||
| `adapter` | `:nokogiri` | `:nokogiri`, `:ox` | The XML parser used by Saxerator | | |||
| `output_type` | `:hash` | `:hash`, `:xml` | The type of object generated by Saxerator's parsing. `:hash` should be self-explanatory, `:xml` generates a `Nokogiri::XML::Document` | |||
| `output_type` | `:hash` | `:hash`, `:xml` | The type of object generated by Saxerator's parsing. `:hash` should be self-explanatory, `:xml` generates a `REXML::Document` (but have additional method :to_xml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing our REXML::Document wrapper means we can remove the documentation of to_xml
here
</contributor> | ||
</entry> | ||
eos | ||
expected_xml = '<?xml version=\'1.0\'?><entry><id>1</id><published>2012-01-01T16:17:00-06:00</published><updated>2012-01-01T16:17:00-06:00</updated><link href="https://example.com/blog/how-to-eat-an-airplane"/><title>How to eat an airplane</title><content type="html"><p>Airplanes are very large — this can present difficulty in digestion.</p></content><media:thumbnail url="http://www.gravatar.com/avatar/a9eb6ba22e482b71b266daadf9c9a080?s=80"/><author><name>Soul<utter</name></author><contributor type="primary"><name>Jane Doe</name></contributor><contributor><name>Leviticus Alabaster</name></contributor></entry>' | ||
expect(entry.to_xml).to eq(expected_xml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_xml
will need to be to_s
here once the REXML::Document wrapper is removed.
let(:output_type) { :xml } | ||
specify { expect(parser.all).to be_a Nokogiri::XML::Document } | ||
specify { expect(parser.all).to be_a Saxerator::Builder::XmlDocument } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be a REXML::Document
when the wrapper is removed
I'm fine with keeping with REXML's behavior for that output. |
4c9ecc0
to
2bec86d
Compare
@soulcutter I've updated with your additions, But for some reason test fails on ruby 2.0 with error:
|
@soulcutter Also look like test doesn't works properly because the not test when we changing adapter actually. It's stubbed. |
976c44a
to
2bec86d
Compare
2bec86d
to
c865cf9
Compare
The latest nokogiri requires ruby 2.1.0+ |
It should fail in that scenario. You have to have the adapter on the load path if you want to use it. That could be worth clarifying in the documentation. Adapters are external dependencies, not bundled with this library. |
Related to task: Update XmlBuilder to use REXML class
—
onxml_builder_spec.rb
was printed as—
(long dash)@soulcutter Please take a look here.
That is the first scratch but tests works good. Also I've turned on xml
output_type
for Ox too.