Forum: Ruby on Rails Html formatting w/ Atom feeds

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.
Clem R. (Guest)
on 2007-01-25 21:53
Hello,
   I'm having a great time building some rss/atom feeds and I've been
quite successful until I hit the html formatting line of the Atom feed.

Here's an example:

xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"

  xml.feed "xml:lang" => "en-US", "xmlns" =>
'http://www.w3.org/2005/Atom ' do
    xml.title("flavor: #{@flavor} *title1: " + @feed.title)
    xml.id(
"tag:#{request.host},#{Time.now.utc.year}:#{@feed.title}/#{@feed.title.downcase}"
)
    xml.link('url: ' + @ feed.guid) if @feed.guid
    xml.author  { xml.name "Author Name" }

     @entities.each do |entity|
       xml.entry do
         xml.title('title: ' + entity.title )
         xml.link("rel" => "alternate", "href" => url_for(url_for
:only_path => false, :controller => @this_controller, :action =>
@this_action, :id => entity.id))
         xml.id(url_for(:only_path => false, :controller =>
@this_controller, :action => @this_action, :id => entity.id))
         xml.updated("#{Time.now.utc.year}")

         xml.content "type" => "html" do
           xml.name entity.body   #-->>tried this - doesn't work
           xml.text! render(:partial => "shared/feed/entity", :entity =>
entity)-->>Tried this - doesn't work

         end
       end
     end
  end


If I could just get the
xml.content "type" => "html" do
end

section to work I would be home free.

Help!
Rick O. (Guest)
on 2007-01-25 23:38
(Received via mailing list)
> xml.content "type" => "html" do
> end
>
> section to work I would be home free.

1) You should be using xhtml for the content type.  HTML assumes html
escaped text.  XHTML wants well formed HTML starting with a div tag:

http://tools.ietf.org/html/rfc4287#section-4.1.3

2) You can use the #<< method to add raw xml to the xml object.
Here's how I do it in Mephisto:

http://svn.techno-weenie.net/projects/mephisto/tru...

(sanitize_feed_content is in here)
http://svn.techno-weenie.net/projects/mephisto/tru...

--
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Rick O. (Guest)
on 2007-01-25 23:40
(Received via mailing list)
> 1) You should be using xhtml for the content type.  HTML assumes html
> escaped text.  XHTML wants well formed HTML starting with a div tag:
>
> http://tools.ietf.org/html/rfc4287#section-4.1.3

Okay, just to be clear... I assumed from your code you want strongly
typed HTML, which is why I suggested the XHTML content type.  In
Mephisto, I don't run the content through tidy or anything and can't
guarantee xhtml compliance, so I just use HTML for now.  Use what you
like.  I just wanted to highlight the difference between the two.

--
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
clem_c_rock (Guest)
on 2007-01-26 09:02
Rick - thanks for all your help.

I'm not quite sure I fully understand this.    The closest I'm coming to
getting this displayed correctly is w/ this:

xml.content "type" => "xhtml" do
   xml.content( "<div
xmlns=\"http://www.w3.org/1999/xhtml\">#{entity.body}</div...)
end

This displays the info but does not render the html properly.

what am I missing?

Also, When I try this atom method in windows IE, it completely fails and
spits the output w/out any rendering at all.

lordy.


Rick O. wrote:
>> 1) You should be using xhtml for the content type.  HTML assumes html
>> escaped text.  XHTML wants well formed HTML starting with a div tag:
>>
>> http://tools.ietf.org/html/rfc4287#section-4.1.3
>
> Okay, just to be clear... I assumed from your code you want strongly
> typed HTML, which is why I suggested the XHTML content type.  In
> Mephisto, I don't run the content through tidy or anything and can't
> guarantee xhtml compliance, so I just use HTML for now.  Use what you
> like.  I just wanted to highlight the difference between the two.
>
> --
> Rick O.
> http://weblog.techno-weenie.net
> http://mephistoblog.com
clem_c_rock (Guest)
on 2007-01-26 09:04
Also when I try rendering this feed as rss in windows IE it doesn't even
respond.

Double Lordy.
Clem R. (Guest)
on 2007-01-26 20:33
Also - does anyone know if there are good functional tests to test the
validation of the rss and atom feed structures?

Thanks,

desperate
Rick O. (Guest)
on 2007-01-26 23:52
(Received via mailing list)
On 1/26/07, Clem R. <removed_email_address@domain.invalid> wrote:
>
> Also - does anyone know if there are good functional tests to test the
> validation of the rss and atom feed structures?

Look at how typo does it.  I believe it calls the feed validator, or
checks for and uses the local feed validator lib if it exists.


--
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Rick O. (Guest)
on 2007-01-26 23:53
(Received via mailing list)
On 1/26/07, clem_c_rock <removed_email_address@domain.invalid> wrote:
>
> This displays the info but does not render the html properly.
>
> what am I missing?
>
> Also, When I try this atom method in windows IE, it completely fails and
> spits the output w/out any rendering at all.
>
> lordy.

Impossible to solve, this is, without an example of the result xml.
Well, on first glance, you didnt use << at all. sooo.....

--
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Clem R. (Guest)
on 2007-01-27 20:49
Rick - I did try this:

xml.content "type" => "xhtml" do
   xml << %{"<div>" + entity.body + "</div>" }
end

and it does render the html code properly but, for only one entry.   In
other words, if I have 2 records in a database, only the first one is
getting displayed.

Weird.   I'm close but missing something basic.

Thanks so much for your help.
Clem R. (Guest)
on 2007-01-30 21:23
I also tried to render the xml.content section w/ a partial like this:

xml.content "type" => "html" do
   xml.text! render(partial => "shared/feed/entity", :entity => entity,
:xm => xml)
end

and the partial code would contain:

xm.entry 'xml:base' => home_url do
    xm.title('title: ' + entity.title )
    xm.link("rel" => "alternate", "href" => url_for(url_for :only_path
=> false, :controller => @this_controller, :action => @this_action, :id
=> entity.id))
    xm.id(url_for(:only_path => false, :controller => @this_controller,
:action => @this_action, :id => entity.id))
    xm.updated("#{Time.now.utc.year}")
    xm.author  { xm.name "Author Name" }
    xm << %{<content type="xhtml">****#{entity.body}</content>}
end


This still only prints out the first line.





Clem R. wrote:
> Rick - I did try this:
>
> xml.content "type" => "xhtml" do
>    xml << %{"<div>" + entity.body + "</div>" }
> end
>
> and it does render the html code properly but, for only one entry.   In
> other words, if I have 2 records in a database, only the first one is
> getting displayed.
>
> Weird.   I'm close but missing something basic.
>
> Thanks so much for your help.
This topic is locked and can not be replied to.