diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index f6ba368..a976ff4 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -2,6 +2,7 @@ module ContentViewerHelper include BlogHelper include ForumHelper + include ActionView::Helpers::TagHelper def number_of_comments(article) n = article.comments.without_spam.count @@ -36,7 +37,7 @@ module ContentViewerHelper def link_to_comments(article, args = {}) return '' unless article.accept_comments? - link_to(number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) + link_to_article number_of_comments(article), article, 'comments_list' end def article_translations(article) diff --git a/app/models/article.rb b/app/models/article.rb index 57d3781..9feef3e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -236,8 +236,13 @@ class Article < ActiveRecord::Base # The implementation in this class just provides the +body+ attribute as the # HTML. Other article types can override this method to provide customized # views of themselves. + # (To override short format representation, override the lead method) def to_html(options = {}) - body || '' + if options[:format] == 'short' + display_short_format(self) + else + body || '' + end end include ApplicationHelper diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index aa936f1..735f17e 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -97,6 +97,21 @@ class ArticleTest < ActiveSupport::TestCase assert_equal '', a.to_html end + should 'provide short html version' do + a = fast_create(Article, :body => 'full body', :abstract => 'lead') + a.stubs(:url).returns({:x=>'none'}) + a.stubs(:link_to).returns('') + def a.content_tag (tag, content, c=nil) + "<#{tag}>#{content}" + end + assert_match /
lead.*/, a.to_html(:format=>'short') + end + + should 'provide full html version' do + a = fast_create(Article, :body => 'full body', :abstract => 'lead') + assert_equal 'full body', a.to_html(:format=>'full body') + end + should 'provide first paragraph of HTML version' do profile = create_user('testinguser').person a = fast_create(Article, :name => 'my article', :profile_id => profile.id) -- libgit2 0.21.2