Skip to content

Commit

Permalink
add linking to article from comment
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2268 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Sep 25, 2006
1 parent 3853a03 commit 48a8d52
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,5 +1,10 @@
* SVN *

* Cache article-specific fields in comments table, allow simple linking to article:

{{ comment | link_to_article }}
{{ comment.url }}

* Add Liquid Filter helpers for showing comment/article feeds for a section

{{ section | comments_feed }}
Expand Down
7 changes: 6 additions & 1 deletion app/drops/comment_drop.rb
@@ -1,11 +1,12 @@
class CommentDrop < BaseDrop
include Mephisto::Liquid::UrlMethods
include WhiteListHelper

def comment() @source end

def initialize(source)
@source = source
@comment_liquid = %w(id author author_email author_ip created_at).inject({}) { |l, a| l.update(a => comment.send(a)) }
@comment_liquid = %w(id author author_email author_ip created_at title published_at).inject({}) { |l, a| l.update(a => comment.send(a)) }
@comment_liquid.update 'is_approved' => comment.approved?, 'body' => white_list(comment.body_html)
end

Expand All @@ -18,6 +19,10 @@ def author_url
comment.author_url =~ /^https?:\/\// ? comment.author_url : "http://" + comment.author_url
end

def url
@url ||= absolute_url(@source.site.permalink_for(@source))
end

def author_link
comment.author_url.blank? ? "<span>#{CGI::escapeHTML(comment.author)}</span>" : %Q{<a href="#{CGI::escapeHTML author_url}">#{CGI::escapeHTML comment.author}</a>}
end
Expand Down
5 changes: 5 additions & 0 deletions test/unit/article_drop_test.rb
Expand Up @@ -68,4 +68,9 @@ def test_only_body_with_empty_excerpt
assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
end

def test_article_url
t = Time.now.utc - 3.days
assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto", @article.url
end
end
7 changes: 6 additions & 1 deletion test/unit/comment_drop_test.rb
Expand Up @@ -4,7 +4,7 @@ class CommentDropTest < Test::Unit::TestCase
fixtures :contents, :sites

def setup
@comment = CommentDrop.new(contents(:welcome_comment))
@comment = contents(:welcome_comment).to_liquid
end

def test_should_convert_comment_to_drop
Expand Down Expand Up @@ -45,4 +45,9 @@ def test_should_show_filtered_text
liquid = comment.to_liquid
assert_equal '<p><strong>test</strong> comment</p>', liquid.before_method(:body)
end

def test_comment_url
t = Time.now.utc - 3.days
assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto", @comment.url
end
end

0 comments on commit 48a8d52

Please sign in to comment.