Commit 50e0a4c34e68f306498e261fbac341330a858286
1 parent
21ff0c09
Exists in
master
and in
28 other branches
ActionItem23: first step of implementing RSS feeds
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1116 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
127 additions
and
0 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -19,6 +19,12 @@ class ContentViewerController < PublicController |
19 | 19 | end |
20 | 20 | end |
21 | 21 | |
22 | + if @page.mime_type != 'text/html' | |
23 | + headers['Content-Type'] = @page.mime_type | |
24 | + render :text => @page.data, :layout => false | |
25 | + return | |
26 | + end | |
27 | + | |
22 | 28 | if request.post? && params[:comment] |
23 | 29 | @comment = Comment.new(params[:comment]) |
24 | 30 | @comment.author = user if logged_in? | ... | ... |
app/models/article.rb
... | ... | @@ -39,6 +39,12 @@ class Article < ActiveRecord::Base |
39 | 39 | body |
40 | 40 | end |
41 | 41 | |
42 | + # returns the data of the article. Must be overriden in each subclass to | |
43 | + # provide the correct content for the article. | |
44 | + def data | |
45 | + body | |
46 | + end | |
47 | + | |
42 | 48 | # provides the icon name to be used for this article. In this class this |
43 | 49 | # method just returns 'text-html', but subclasses may (and should) override |
44 | 50 | # to return their specific icons. | ... | ... |
... | ... | @@ -0,0 +1,43 @@ |
1 | +class RssFeed < Article | |
2 | + | |
3 | + # store setting in body | |
4 | + serialize Hash, :body | |
5 | + | |
6 | + # TODO | |
7 | + def to_html | |
8 | + end | |
9 | + | |
10 | + # RSS feeds have type =text/xml=. | |
11 | + def mime_type | |
12 | + 'text/xml' | |
13 | + end | |
14 | + | |
15 | + # FIXME - feed real data into the RSS feed | |
16 | + def data | |
17 | + result = "" | |
18 | + xml = Builder::XmlMarkup.new(:target => result) | |
19 | + | |
20 | + xml.instruct! :xml, :version=>"1.0" | |
21 | + xml.rss(:version=>"2.0") do | |
22 | + xml.channel do | |
23 | + xml.title(_("%s's RSS feed") % (self.profile.name)) | |
24 | + xml.link("http://www.yourDomain.com") | |
25 | + xml.description('Description here') | |
26 | + xml.language("pt_BR") | |
27 | + for article in profile.recent_documents(10) | |
28 | + xml.item do | |
29 | + xml.title(article.name) | |
30 | + xml.description(article.abstract) | |
31 | + # rfc822 | |
32 | + xml.pubDate(article.created_on.rfc2822) | |
33 | + xml.link("http://www.yourDomain.com/linkToYourPost") | |
34 | + xml.guid("http://www.yourDomain.com/linkToYourPost") | |
35 | + end | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + result | |
41 | + end | |
42 | + | |
43 | +end | ... | ... |
db/migrate/007_create_articles.rb
... | ... | @@ -23,6 +23,9 @@ class CreateArticles < ActiveRecord::Migration |
23 | 23 | # acts as versioned |
24 | 24 | t.column :version, :integer |
25 | 25 | t.column :lock_version, :integer |
26 | + | |
27 | + # single-table inheritance | |
28 | + t.column :type, :string | |
26 | 29 | end |
27 | 30 | |
28 | 31 | Article.create_versioned_table | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -85,5 +85,24 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
85 | 85 | end |
86 | 86 | end |
87 | 87 | |
88 | + should 'produce a download-like when article is not text/html' do | |
89 | + | |
90 | + # for example, RSS feeds | |
91 | + profile = create_user('someone').person | |
92 | + page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') | |
93 | + page.save! | |
94 | + | |
95 | + feed = RssFeed.new(:name => 'feed') | |
96 | + feed.profile = profile | |
97 | + feed.save! | |
98 | + | |
99 | + get :view_page, :profile => 'someone', :page => [ 'feed' ] | |
100 | + | |
101 | + assert_response :success | |
102 | + assert_match /^text\/xml/, @response.headers['Content-Type'] | |
103 | + | |
104 | + assert_equal feed.data, @response.body | |
105 | + end | |
106 | + | |
88 | 107 | |
89 | 108 | end | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class RssFeedTest < Test::Unit::TestCase | |
4 | + | |
5 | + should 'indicate the correct mime/type' do | |
6 | + assert_equal 'text/xml', RssFeed.new.mime_type | |
7 | + end | |
8 | + | |
9 | + should 'store settings in a hash serialized into body field' do | |
10 | + flunk 'pending' | |
11 | + end | |
12 | + | |
13 | + should 'list recent articles of profile when top-level' do | |
14 | + profile = create_user('testuser').person | |
15 | + a1 = profile.articles.build(:name => 'article 1'); a1.save! | |
16 | + a2 = profile.articles.build(:name => 'article 2'); a2.save! | |
17 | + a3 = profile.articles.build(:name => 'article 3'); a3.save! | |
18 | + | |
19 | + feed = RssFeed.new(:name => 'feed') | |
20 | + feed.profile = profile | |
21 | + feed.save! | |
22 | + | |
23 | + rss = feed.data | |
24 | + assert_match /<title>article 1<\/title>/, rss | |
25 | + assert_match /<title>article 2<\/title>/, rss | |
26 | + assert_match /<title>article 3<\/title>/, rss | |
27 | + end | |
28 | + | |
29 | + should 'list recent article from parent article' do | |
30 | + profile = create_user('testuser').person | |
31 | + feed = RssFeed.new | |
32 | + feed.expects(:profile).returns(profile).at_least_once | |
33 | + array = [] | |
34 | + profile.expects(:recent_documents).returns(array) | |
35 | + feed.data | |
36 | + end | |
37 | + | |
38 | + should 'be able to choose to put abstract or entire body on feed' do | |
39 | + flunk 'pending' | |
40 | + end | |
41 | + | |
42 | + should 'be able to choose if search in all articles or in subarticles of parent' do | |
43 | + flunk 'pending' | |
44 | + end | |
45 | + | |
46 | + should 'be able to indicate maximum number of items' do | |
47 | + flunk 'pending' | |
48 | + end | |
49 | + | |
50 | +end | ... | ... |