I've got a web service which outputs XML. I'm generating it very
conveniently by creating a file in the view named index.xml.builder.
That all works great, almost.

I can write that file very simply and cleanly like this:

xml.instruct!
xml.search do
  xml.total @results[:total]
end

That's really maintainable, but the output contains lots of extra
spaces and newlines that muck it up. I can get rid of all the spaces
by adding this line to the top of each xml.builder file:

xml = Builder::XmlMarkup.new

But that takes out ALL the spaces and newlines, so the entire output
is on one line. What I want is something in the middle. Through
experimentation, I've explicitly added newlines and spaces where I
want them, but suddenly the file is no longer as easily maintainable:

xml = Builder::XmlMarkup.new
xml.instruct!
xml.text!("\n")
xml.search do
  xml.text!("\n  ")
  xml.total @results[:total]
end

Does anyone know of a cleaner approach where I get the maintainability
of the top example with the output of the bottom example?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to