-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Rails support #94
Comments
This is the first interest I've had in XML and ActiveSupport. Most people use JSON. If you are interested and would like to work with me on it I would not mind looking more deeply at it. |
Yeah all the cool Rails kids are using JSON (myself included). I have some API partners who are .net shops and they consume XML from my API though. I suspect that is the case for some others as well, particularity apps that are more geared towards enterprise usage. Unfortunately the Rails community doesn't put that much love into it (example: rails-api/active_model_serializers#448) Here is the nokogiri adapter btw: https://github.com/rails/rails/blob/8dd4aca4850c678f96d0a72098b3a080b51dea44/activesupport/lib/active_support/xml_mini/nokogiri.rb I just started testing out oj in our Rails app today and see a 10% performance increase (thanks!) with some simple benchmarking. Trying it out in staging now. If I can get a performance increase by switching the XML parser as well that would be great as most of the requests to the app is through the API. |
I also had a look at multi_xml which supports ox, perhaps a better solution is for them to add active_support support? Then other gems would benefit too. |
I'll look at it more carefully this week. |
Has there been any progress with this? I have some pretty big xml feeds that my Rails app generates that take forever and I'd love to be able to speed them up. |
It did not seem like something I wanted to tackle at the time. Lets discuss a bit though. You mentioned the nokogiri adapter. Would something like that be what you need but instead for Ox? |
I think I actually misunderstood what this issue was about (I'm not the original poster). What I'd like to do is use Ox with something (or instead of something) like the builder gem to build XML for my Rails app to serve XML. I'm trying to put something together myself, but if you had any ideas I'd appreciate it (assuming this is the correct issue for this discussion). |
Probably should be a separate discussion. Since its not really an issue but a request for how to make something new lets handle it with email to start with and when we have a better idea what it is we can create an issue. |
Hi @ohler55, first of all, I want to say great thanks for all your work! |
If it was something I could do in Ox I would but that change would have to be made to rails itself. I can make an attempt by submitting a PR but with almost 800 outstanding PRs I suspect it will take a very long time for such a PR to be accepted. Maybe I'm being pessimistic though. @mario-amazing would you be interested in testing? |
Sounds interesting, I'll really glad to help you with this PR. |
Yes, that would be the plan. To start out, can you tell me what the conversion is from Ruby objects to XML is? I'll use that as part of a test suite. |
You can check expected XML formatting from rails acrive_support xml_mini tests. There are many examples) |
That helps some. I'll look for other examples as well. |
Do you want something like that? Xml -> <recipe type="dessert">
<recipename cuisine="american" servings="1">Ice Cream Sundae</recipename>
<ingredlist>
<listitem>
<quantity units="cups">0.5</quantity>
<itemdescription>vanilla ice cream</itemdescription>
</listitem>
<listitem>
<quantity units="tablespoons">3</quantity>
<itemdescription>chocolate syrup or chocolate fudge</itemdescription>
</listitem>
<listitem>
<quantity units="tablespoons">1</quantity>
<itemdescription>nuts</itemdescription>
</listitem>
<listitem>
<quantity units="each">1</quantity>
<itemdescription>cherry</itemdescription>
</listitem>
</ingredlist>
<utensils>
<listitem>
<quantity units="each">1</quantity>
<utensilname>bowl</utensilname>
</listitem>
<listitem>
<quantity units="each">1</quantity>
<utensilname>spoons</utensilname>
</listitem>
<listitem>
<quantity units="each">1</quantity>
<utensilname>ice cream scoop</utensilname>
</listitem>
</utensils>
<directions>
<step>Using ice cream scoop, place vanilla ice cream into bowl.</step>
<step>Drizzle chocolate syrup or chocolate fudge over the ice cream.</step>
<step>Sprinkle nuts over the mound of chocolate and ice cream.</step>
<step>Place cherry on top of mound with stem pointing upward.</step>
<step>Serve.</step>
</directions>
<variations>
<option>Replace nuts with raisins.</option>
<option>Use chocolate ice cream instead of vanilla ice cream.</option>
</variations>
<preptime>5 minutes</preptime>
</recipe> Rails expected Hash -> {"recipe"=>
{"type"=>"dessert",
"recipename"=>{"cuisine"=>"american", "servings"=>"1", "__content__"=>"Ice Cream Sundae"},
"ingredlist"=>
{"listitem"=>
[{"quantity"=>{"units"=>"cups", "__content__"=>"0.5"}, "itemdescription"=>{"__content__"=>"vanilla ice cream"}},
{"quantity"=>{"units"=>"tablespoons", "__content__"=>"3"}, "itemdescription"=>{"__content__"=>"chocolate syrup or chocolate fudge"}},
{"quantity"=>{"units"=>"tablespoons", "__content__"=>"1"}, "itemdescription"=>{"__content__"=>"nuts"}},
{"quantity"=>{"units"=>"each", "__content__"=>"1"}, "itemdescription"=>{"__content__"=>"cherry"}}]},
"utensils"=>
{"listitem"=>
[{"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"bowl"}},
{"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"spoons"}},
{"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"ice cream scoop"}}]},
"directions"=>
{"step"=>
[{"__content__"=>"Using ice cream scoop, place vanilla ice cream into bowl."},
{"__content__"=>"Drizzle chocolate syrup or chocolate fudge over the ice cream."},
{"__content__"=>"Sprinkle nuts over the mound of chocolate and ice cream."},
{"__content__"=>"Place cherry on top of mound with stem pointing upward."},
{"__content__"=>"Serve."}]},
"variations"=>
{"option"=>[{"__content__"=>"Replace nuts with raisins."}, {"__content__"=>"Use chocolate ice cream instead of vanilla ice cream."}]},
"preptime"=>{"__content__"=>"5 minutes"}}} |
Perfect, thanks. I think it would make sense to add the conversion from XML to Hash to Ox directly and then create a simpler hook into rails. |
Any plans on adding support to be used with ActiveSupport?
The text was updated successfully, but these errors were encountered: