Forum: Ruby on Rails text output in rxml (builder)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ingo W. (Guest)
on 2007-04-27 23:48
Hi, I need to output the following in an rxml template:


<coordinates>
  -122.3662784465226,37.81884427772081,30
  -122.3652480684771,37.81926777010555,30
  -122.365640222455,37.81986126286519,30
  -122.36666937925,37.81942987753481,30
  -122.3662784465226,37.81884427772081,30
</coordinates>

what I am struggling with are the text lines:

xml.coordinates do
  #what goes here?
end

I experimented with xml.text! but I could not find a way to preserve the
indentation and get the linebreaks

Thanks for any help!
Ingo
Phlip (Guest)
on 2007-04-28 07:27
(Received via mailing list)
Ingo W. wrote:

> xml.coordinates do
>  #what goes here?
    xml << '-122...'   #   right?
> end

<< goes in with no translation.

> I experimented with xml.text! but I could not find a way to preserve the
> indentation and get the linebreaks

What about xml.text! "-122...\n" ?

--
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
Ingo W. (Guest)
on 2007-05-01 05:52
> What about xml.text! "-122...\n" ?

This worked, but I had to manually add spaces to get the indentation
(not that that would be terribly important, but...)

Thanks!
Ingo
Ben M. (Guest)
on 2007-05-01 07:12
(Received via mailing list)
Ingo W. wrote:
>> What about xml.text! "-122...\n" ?
>
> This worked, but I had to manually add spaces to get the indentation
> (not that that would be terribly important, but...)

Maybe if you use the """ (multiline string) or << (here doc) operator it
will keep the indentation?

b
Onno F. (Guest)
on 2008-11-07 10:55
> What about xml.text! "-122...\n" ?

I'm having an extra problem now, I'm doing this:
xml.Data 'ss:Type' => 'String' do
  xml.text! format_excel_html(block_content)
end

Now it works, but the output is like this:
<Data>
bla bla bla
</Data>

The problem I have is the whitespace the builder creates around my
content. Does anyone know a trick to get rid of this whitespace?

Thanks, Onno
This topic is locked and can not be replied to.