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 !
cache title/permalink/published_at fields in comments from the article

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2267 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Sep 24 22:14:55 -0700 2006
commit  3853a03eab6d2435e5e94e6f4370a55bb81a760b
tree    461710d874f64add8c7185e449577736628ad516
parent  824f3fe09f3f1850168ae5d725a10128f5e2ab82
...
72
73
74
75
76
77
78
79
...
72
73
74
 
 
75
76
77
0
@@ -72,8 +72,6 @@ class Article < Content
0
     end
0
   end
0
 
0
- [:year, :month, :day].each { |m| delegate m, :to => :published_at }
0
-
0
   # AX
0
   def full_permalink
0
     published? && ['', published_at.year, published_at.month, published_at.day, permalink] * '/'
...
5
6
7
8
 
9
10
11
...
43
44
45
46
47
 
 
48
49
50
...
5
6
7
 
8
9
10
11
...
43
44
45
 
 
46
47
48
49
50
0
@@ -5,7 +5,7 @@ class Comment < Content
0
   validates_format_of :author_email, :with => Format::EMAIL
0
   before_validation :clean_up_author_email
0
   before_validation :clean_up_author_url
0
- after_validation_on_create :snag_article_filter_and_site
0
+ after_validation_on_create :snag_article_attributes
0
   before_create :check_comment_expiration
0
   before_save :update_counter_cache
0
   before_destroy :decrement_counter_cache
0
@@ -43,8 +43,8 @@ class Comment < Content
0
   end
0
 
0
   protected
0
- def snag_article_filter_and_site
0
- self.attributes = { :site => article.site, :filter => article.site.filter }
0
+ def snag_article_attributes
0
+ self.attributes = { :site => article.site, :filter => article.site.filter, :title => article.title, :published_at => article.published_at, :permalink => article.permalink }
0
     end
0
 
0
     def check_comment_expiration
...
2
3
4
 
5
6
...
2
3
4
5
6
7
0
@@ -2,4 +2,5 @@ class Content < ActiveRecord::Base
0
   filtered_column :body, :excerpt
0
   belongs_to :user, :with_deleted => true
0
   belongs_to :site
0
+ [:year, :month, :day].each { |m| delegate m, :to => :published_at }
0
 end
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 60) do
0
+ActiveRecord::Schema.define(:version => 61) do
0
 
0
   create_table "assets", :force => true do |t|
0
     t.column "content_type", :string
...
97
98
99
 
100
101
 
102
103
104
...
107
108
109
 
110
111
112
...
114
115
116
 
 
 
 
117
118
119
...
97
98
99
100
101
 
102
103
104
105
...
108
109
110
111
112
113
114
...
116
117
118
119
120
121
122
123
124
125
0
@@ -97,8 +97,9 @@ module Mephisto
0
     def self.build_permalink_with(permalink_style, article)
0
       old_published = article.published_at
0
       article.published_at ||= Time.now.utc
0
+ article.article_id ||= article.id
0
       permalink_style.split('/').inject [''] do |s, piece|
0
- s << ((name = variable_format?(piece)) && PERMALINK_OPTIONS.keys.include?(name.to_sym) ? article.send(name).to_s : piece)
0
+ s << ((name = variable_format?(piece)) && PERMALINK_OPTIONS.keys.include?(name.to_sym) ? variable_value_for(article, name) : piece)
0
       end.join('/')
0
     ensure
0
       article.published_at = old_published
0
@@ -107,6 +108,7 @@ module Mephisto
0
     private
0
       @@year_regex = %r{^#{PERMALINK_OPTIONS[:year]}$}
0
       @@month_regex = %r{^#{PERMALINK_OPTIONS[:month]}$}
0
+
0
       def self.year?(n)
0
         n.nil? || n =~ @@year_regex
0
       end
0
@@ -114,5 +116,9 @@ module Mephisto
0
       def self.month?(n)
0
         n.nil? || n =~ @@month_regex
0
       end
0
+
0
+ def self.variable_value_for(article, variable)
0
+ variable == 'id' ? article.article_id.to_s : article.send(variable).to_s
0
+ end
0
   end
0
 end
0
\ No newline at end of file
...
40
41
42
 
 
43
44
45
46
47
 
 
 
48
49
50
...
114
115
116
 
 
117
118
119
120
121
 
 
 
122
123
124
...
126
127
128
 
 
129
130
131
132
133
 
 
 
134
135
136
...
40
41
42
43
44
45
46
 
 
 
47
48
49
50
51
52
...
116
117
118
119
120
121
122
 
 
 
123
124
125
126
127
128
...
130
131
132
133
134
135
136
 
 
 
137
138
139
140
141
142
0
@@ -40,11 +40,13 @@ welcome_comment:
0
   id: 3
0
   site_id: 1
0
   article_id: 1
0
+ title: Welcome to Mephisto
0
+ permalink: welcome-to-mephisto
0
   body: "rico's evil <script>hi</script> and <a onclick=\"foo\" href=\"#\">linkage</a>"
0
   body_html: "<p>rico&#8217;s evil <script>hi</script> and <a onclick=\"foo\" href=\"#\">linkage</a></p>"
0
- created_at: <%= 3.days.ago.to_s(:db) %>
0
- updated_at: <%= 3.days.ago.to_s(:db) %>
0
- published_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ created_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ updated_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ published_at: <%= 3.days.ago.to_s(:db) %>
0
   type: Comment
0
   author: rico
0
   author_ip: 1dfasd
0
@@ -114,11 +116,13 @@ cupcake_welcome_comment:
0
   id: 9
0
   site_id: 2
0
   article_id: 8
0
+ title: Welcome to Cupcake
0
+ permalink: welcome-to-cupcake
0
   body: This blogging tool tastes like fudge.
0
   body_html: This blogging tool tastes like fudge.
0
- created_at: <%= 3.days.ago.to_s(:db) %>
0
- updated_at: <%= 3.days.ago.to_s(:db) %>
0
- published_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ created_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ updated_at: <%= (3.days + 55.minutes).ago.to_s(:db) %>
0
+ published_at: <%= 3.days.ago.to_s(:db) %>
0
   type: Comment
0
   author: rico
0
   approved: true
0
@@ -126,11 +130,13 @@ unwelcome_comment:
0
   id: 10
0
   site_id: 1
0
   article_id: 1
0
+ title: Welcome to Mephisto
0
+ permalink: welcome-to-mephisto
0
   body: This blogging tool sucks.
0
   body_html: This blogging tool sucks.
0
- created_at: <%= 2.days.ago.to_s(:db) %>
0
- updated_at: <%= 2.days.ago.to_s(:db) %>
0
- published_at: <%= (2.days + 55.minutes).ago.to_s(:db) %>
0
+ created_at: <%= (2.days + 55.minutes).ago.to_s(:db) %>
0
+ updated_at: <%= (2.days + 55.minutes).ago.to_s(:db) %>
0
+ published_at: <%= 3.days.ago.to_s(:db) %>
0
   type: Comment
0
   author: rico
0
   author_ip: '127.0.0.1'
...
8
9
10
11
 
12
13
14
 
 
 
 
15
16
17
 
18
19
20
...
8
9
10
 
11
12
13
 
14
15
16
17
18
19
 
20
21
22
23
0
@@ -8,13 +8,16 @@ class CommentTest < Test::Unit::TestCase
0
     assert_equal [contents(:welcome_comment)], contents(:welcome).comments
0
   end
0
 
0
- def test_should_add_comment_and_retrieve_site_id_from_article
0
+ def test_should_add_comment_and_retrieve_attributes_from_article
0
     assert_difference Comment, :count do
0
       comment = contents(:welcome).comments.create :body => 'test comment', :author => 'bob', :author_ip => '127.0.0.1', :filter => 'textile_filter'
0
- assert_equal contents(:welcome).site_id, comment.site_id
0
+ assert_equal contents(:welcome).site_id, comment.site_id
0
+ assert_equal contents(:welcome).title, comment.title
0
+ assert_equal contents(:welcome).published_at, comment.published_at
0
+ assert_equal contents(:welcome).permalink, comment.permalink
0
     end
0
   end
0
-
0
+
0
   def test_should_pass_filter_down_from_article
0
     old_times = contents(:welcome).comments.collect &:updated_at
0
     comment = contents(:welcome).comments.create :body => 'test comment', :author => 'bob', :author_ip => '127.0.0.1', :filter => 'textile_filter'
...
56
57
58
 
 
 
 
59
60
61
...
67
68
69
 
 
 
 
 
 
70
71
...
56
57
58
59
60
61
62
63
64
65
...
71
72
73
74
75
76
77
78
79
80
81
0
@@ -56,6 +56,10 @@ context "Site Permalink Generation" do
0
     assert_equal "/#{@article.year}/#{@article.month}/#{@article.day}/#{@article.permalink}", @site.permalink_for(@article)
0
   end
0
 
0
+ specify "should generate correct permalink format with comment" do
0
+ assert_equal "/#{@article.year}/#{@article.month}/#{@article.day}/#{@article.permalink}", @site.permalink_for(contents(:welcome_comment))
0
+ end
0
+
0
   specify "should generate correct permalink format for draft" do
0
     @article.published_at = nil
0
     now = Time.now.utc
0
@@ -67,4 +71,10 @@ context "Site Permalink Generation" do
0
     assert_valid @site
0
     assert_equal "/posts/#{@article.year}/#{@article.id}", @site.permalink_for(@article)
0
   end
0
+
0
+ specify "should generate custom id permalink with comment" do
0
+ @site.permalink_style = 'posts/:year/:id'
0
+ assert_valid @site
0
+ assert_equal "/posts/#{@article.year}/#{@article.id}", @site.permalink_for(contents(:welcome_comment))
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.