File tree 6 files changed +104
-0
lines changed
6 files changed +104
-0
lines changed Original file line number Diff line number Diff line change
1
+ class FeedsController < ApplicationController
2
+ def show
3
+
4
+ posts = Rails . cache . fetch ( 'posts' , expires_in : 12 . hours ) do
5
+ Crowdblog ::Post . all_for_feed
6
+ end
7
+
8
+ events = Rails . cache . fetch ( 'events' , expires_in : 12 . hours ) do
9
+ Event . limit ( 15 )
10
+ end
11
+
12
+ @items = ( posts + events ) . sort_by ( &:updated_at ) . reverse
13
+
14
+ respond_to do | format |
15
+ format . xml { render layout : false }
16
+ format . rss { render layout : false }
17
+ end
18
+ end
19
+ end
Original file line number Diff line number Diff line change
1
+ xml . instruct! :xml , :version => "1.0"
2
+ xml . rss :version => "2.0" do
3
+ xml . channel do
4
+ xml . title "rails.mx"
5
+
6
+ @items . each do | item |
7
+ if item . class == Crowdblog ::Post
8
+
9
+ xml . item do
10
+ xml . title item . title
11
+ xml . description item . html_body
12
+ xml . pubDate item . published_at . to_s ( :rfc822 )
13
+ xml . link post_url ( *item . url_params )
14
+ end
15
+
16
+ else
17
+
18
+ xml . item do
19
+ xml . title item . name
20
+ xml . description item . description
21
+ xml . link event_url ( item . slug )
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
Original file line number Diff line number Diff line change
1
+ atom_feed do |feed |
2
+ feed . title 'rails.mx'
3
+ feed . updated @items . first . updated_at if @items . first
4
+ @items . each do |item |
5
+ if item . class == Crowdblog ::Post
6
+ feed . entry ( item , url : post_url ( *item . url_params ) ) do |entry |
7
+ entry . title item . title
8
+ entry . content item . html_body , type : 'html'
9
+ entry . author do |author |
10
+ author . name item . author . username
11
+ author . email item . author_email
12
+ end
13
+ end
14
+ else
15
+ feed . entry ( item , url : event_url ( item . slug ) ) do |entry |
16
+ entry . title item . name
17
+ entry . content item . description , type : 'html'
18
+ entry . author do |author |
19
+ author . name item . organizer
20
+ author . email item . contact
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
Original file line number Diff line number Diff line change 8
8
< meta name ="description " content ="Una comunidad de desarrolladores mexicanos e hispanohablantes.
9
9
Un punto de encuentro para compartir experiencias y mejores prácticas sobre el mundo de rails. ">
10
10
< meta name ="robots " content ="all " >
11
+ <%= auto_discovery_link_tag ( :atom , '/blog.xml' ) %>
12
+ <%= auto_discovery_link_tag ( :rss , '/blog.rss' ) %>
11
13
<%= favicon_link_tag "favicon-#{ ENV [ 'THEME' ] . downcase } .ico" %>
12
14
<%= stylesheet_link_tag "railsmx" %>
13
15
<%= javascript_include_tag "railsmx" %>
Original file line number Diff line number Diff line change 12
12
get "/contacto" => "contact_form#new" , as : :contact_form_new
13
13
post "/contacto" => "contact_form#create" , as : :contact_form
14
14
15
+
16
+ get "/blog.(:format)" => 'feeds#show'
17
+
15
18
get "/:id" => "home#show" , as : :static
16
19
17
20
if Rails . env . test?
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+
3
+ describe FeedsController do
4
+
5
+ describe "using xml as format" do
6
+ it "should get show" do
7
+ get :show , format : 'xml'
8
+ assert_response :success
9
+ end
10
+
11
+ it "should render xml" do
12
+ get :show , format : 'xml'
13
+ assert_template :show
14
+ end
15
+ end
16
+
17
+ describe "using rss as format" do
18
+ it "should get show" do
19
+ get :show , format : 'rss'
20
+ assert_response :success
21
+ end
22
+
23
+ it "should render rss" do
24
+ get :show , format : 'rss'
25
+ assert_template :show
26
+ end
27
+ end
28
+ end
You can’t perform that action at this time.
0 commit comments