public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
Add comments and changes feeds for articles

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2272 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Sep 25 00:40:16 -0700 2006
commit  734e1a56d61f1e42ba7f5303afaeced3484c9e26
tree    c0b90e28180869b696bbcfaa02fa03dc3aa35292
parent  5cfedaa4493dc87c031cb9ef46b46f8e2a1b348f
...
1
2
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1,5 +1,10 @@
0
 * SVN *
0
 
0
+* Add comments and changes feeds for articles.
0
+
0
+ {{ article | comments_feed }}
0
+ {{ article | changes_feed: "Latest Changes for this Article" }}
0
+
0
 * Cache article-specific fields in comments table, allow simple linking to article:
0
 
0
   {{ comment | link_to_article }}
...
54
55
56
 
 
 
 
 
 
 
 
57
58
59
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -54,6 +54,14 @@ class ArticleDrop < BaseDrop
0
     @url ||= absolute_url(@site.permalink_for(@source))
0
   end
0
 
0
+ def comments_feed_url
0
+ @comments_feed_url ||= url + '/comments.xml'
0
+ end
0
+
0
+ def changes_feed_url
0
+ @changes_feed_url ||= url + '/changes.xml'
0
+ end
0
+
0
   protected
0
     def body_for_mode(mode)
0
       contents = [before_method(:excerpt), before_method(:body)]
...
86
87
88
89
 
90
91
92
93
94
95
 
96
97
98
99
 
 
 
 
 
 
 
 
100
101
102
103
 
104
105
106
...
86
87
88
 
89
90
91
92
93
94
 
95
96
97
 
 
98
99
100
101
102
103
104
105
106
107
108
 
109
110
111
112
0
@@ -86,21 +86,27 @@ module UrlFilters
0
   end
0
 
0
   def atom_feed(url, title = nil)
0
- options = {:rel => 'alternate', :type => 'application/atom+xml', :href => absolute_url("/feed/#{url}")}
0
+ options = {:rel => 'alternate', :type => 'application/atom+xml', :href => absolute_url(url)}
0
     options[:title] = title unless title.blank?
0
     tag(:link, options)
0
   end
0
 
0
   def all_comments_feed(title = nil)
0
- atom_feed 'all_comments.xml', title.blank? ? 'All Comments' : title
0
+ atom_feed '/feed/all_comments.xml', title.blank? ? 'All Comments' : title
0
   end
0
 
0
- def comments_feed(section, title = nil)
0
- atom_feed section.source.to_comments_url.join('/'), (title.blank? ? "Comments for #{section['name']}" : title)
0
+ def comments_feed(section_or_article, title = nil)
0
+ section_or_article.is_a?(SectionDrop) ?
0
+ atom_feed('/feed/' + section_or_article.source.to_comments_url.join('/'), (title.blank? ? "Comments for #{section_or_article['name']}" : title)) :
0
+ atom_feed(section_or_article.url + '/comments.xml', (title.blank? ? "Comments for #{section_or_article['title']}" : title))
0
+ end
0
+
0
+ def changes_feed(article, title = nil)
0
+ atom_feed article.url + '/changes.xml', (title.blank? ? "Changes for #{article['title']}" : title)
0
   end
0
 
0
   def articles_feed(section, title = nil)
0
- atom_feed section.source.to_feed_url.join('/'), (title.blank? ? "Articles for #{section['name']}" : title)
0
+ atom_feed '/feed/' + section.source.to_feed_url.join('/'), (title.blank? ? "Articles for #{section['name']}" : title)
0
   end
0
 
0
   private
...
73
74
75
 
 
 
 
 
 
 
 
 
 
76
...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
0
@@ -73,4 +73,14 @@ class ArticleDropTest < Test::Unit::TestCase
0
     t = Time.now.utc - 3.days
0
     assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto", @article.url
0
   end
0
+
0
+ def test_comments_feed_url
0
+ t = Time.now.utc - 3.days
0
+ assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto/comments.xml", @article.comments_feed_url
0
+ end
0
+
0
+ def test_changes_feed_url
0
+ t = Time.now.utc - 3.days
0
+ assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto/changes.xml", @article.changes_feed_url
0
+ end
0
 end
...
59
60
61
62
 
63
64
65
...
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110
...
59
60
61
 
62
63
64
65
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
0
@@ -59,7 +59,7 @@ context "Url Filters" do
0
   end
0
   
0
   specify "should generate atom auto discovery tag" do
0
- content = atom_feed('foo')
0
+ content = atom_feed('/feed/foo')
0
     assert_match /^<link /, content
0
     assert_match /rel="alternate"/, content
0
     assert_match /type="application\/atom\+xml"/, content
0
@@ -106,4 +106,36 @@ context "Url Filters" do
0
     assert_match /href="\/feed\/about\/atom.xml"/, content
0
     assert_match /title="About Articles"/, content
0
   end
0
+end
0
+
0
+context "Article Url Filters" do
0
+ fixtures :sites, :sections, :contents
0
+ include CoreFilters, UrlFilters
0
+
0
+ def setup
0
+ @article = contents(:welcome).to_liquid(:site => sites(:first))
0
+ @permalink = @article.url
0
+ end
0
+
0
+ specify "should show article comments feed" do
0
+ content = comments_feed(@article)
0
+ assert_match /href="#{@permalink}\/comments\.xml"/, content
0
+ assert_match /title="Comments for Welcome to Mephisto"/, content
0
+ end
0
+
0
+ specify "should show article comments feed with custom title" do
0
+ content = comments_feed(@article, "Welcome Comments")
0
+ assert_match /title="Welcome Comments"/, content
0
+ end
0
+
0
+ specify "should show article changes feed" do
0
+ content = changes_feed(@article)
0
+ assert_match /href="#{@permalink}\/changes\.xml"/, content
0
+ assert_match /title="Changes for Welcome to Mephisto"/, content
0
+ end
0
+
0
+ specify "should show article changes feed with custom title" do
0
+ content = changes_feed(@article, "Welcome Changes")
0
+ assert_match /title="Welcome Changes"/, content
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.