Skip to content

Commit

Permalink
feed en atom
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavila committed Dec 1, 2009
1 parent 20298f7 commit 0f73f1a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/homes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ class HomesController < ApplicationController
def show
@posts = Post.active(:limit => 11)
@last_post = @posts.shift

respond_to do |format|
format.html
format.atom do
@posts = [@last_post] + @posts[0..8]
end
end
end
end
44 changes: 44 additions & 0 deletions app/views/homes/show.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
atom_feed(:schema_date => '2009') do |feed|
feed.title("Rubén on Rails' Blog")
feed.updated(@posts.first.published_at)

for post in @posts
feed.entry(post, { :url => seo_post_url(post.published_at.year, post.published_at.month, post.published_at.day, post.friendly_id) }) do |entry|
entry.title(post.title)
entry.content(post.body_html, :type => 'html')
#entry.link "rel" => "alternate", "href" => seo_post_url(post.published_at.year, post.published_at.month, post.published_at.day, post.friendly_id)
#entry.url "type" => "text/html", "rel" => "alternate", "href" => seo_post_url(post.published_at.year, post.published_at.month, post.published_at.day, post.friendly_id)
entry.author do |author|
author.name("Rubén Dávila")
end
end
end
end


#xml.instruct!
#
#xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
#
#xml.title "Feed Name"
#xml.link "rel" => "self", "href" => url_for(:only_path => false, :controller => 'home', :action => 'show', :format => :atom)
#xml.link "rel" => "alternate", "href" => url_for(:only_path => false, :controller => 'home')
#xml.id url_for(:only_path => false, :controller => 'posts')
#xml.updated @posts.first.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ" if @posts.any?
#xml.author { xml.name "Author Name" }
#
# @posts.each do |post|
# xml.entry do
# xml.title post.title
# xml.link "rel" => "alternate", "href" => seo_post_url(post.published_at.year, post.published_at.month, post.published_at.day, post.friendly_id)
#
# xml.id seo_post_url(post.published_at.year, post.published_at.month, post.published_at.day, post.friendly_id)
#
# xml.updated post.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ"
# xml.author { xml.name 'ddddd' }
# xml.content post.body_html
# end
# end
#
#end
#
1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
%html{ "xml:lang" => "es", :lang => "es", :xmlns => "http://www.w3.org/1999/xhtml" }

%head
= auto_discovery_link_tag :atom, root_url(:format=>'atom'), :title=>'Rubén on Rails'
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'print.css', :media => 'print'
= syntax_css('espresso_libre')
Expand Down

0 comments on commit 0f73f1a

Please sign in to comment.