Commit aaccd5c489b4d25ef8e5bad05b0e05afa5bc2b9d
1 parent
76ea3016
Exists in
master
and in
29 other branches
makes Article::to_html finally configurable
Showing
3 changed files
with
23 additions
and
2 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
@@ -2,6 +2,7 @@ module ContentViewerHelper | @@ -2,6 +2,7 @@ module ContentViewerHelper | ||
2 | 2 | ||
3 | include BlogHelper | 3 | include BlogHelper |
4 | include ForumHelper | 4 | include ForumHelper |
5 | + include ActionView::Helpers::TagHelper | ||
5 | 6 | ||
6 | def number_of_comments(article) | 7 | def number_of_comments(article) |
7 | n = article.comments.without_spam.count | 8 | n = article.comments.without_spam.count |
@@ -36,7 +37,7 @@ module ContentViewerHelper | @@ -36,7 +37,7 @@ module ContentViewerHelper | ||
36 | 37 | ||
37 | def link_to_comments(article, args = {}) | 38 | def link_to_comments(article, args = {}) |
38 | return '' unless article.accept_comments? | 39 | return '' unless article.accept_comments? |
39 | - link_to(number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) | 40 | + link_to_article number_of_comments(article), article, 'comments_list' |
40 | end | 41 | end |
41 | 42 | ||
42 | def article_translations(article) | 43 | def article_translations(article) |
app/models/article.rb
@@ -236,8 +236,13 @@ class Article < ActiveRecord::Base | @@ -236,8 +236,13 @@ class Article < ActiveRecord::Base | ||
236 | # The implementation in this class just provides the +body+ attribute as the | 236 | # The implementation in this class just provides the +body+ attribute as the |
237 | # HTML. Other article types can override this method to provide customized | 237 | # HTML. Other article types can override this method to provide customized |
238 | # views of themselves. | 238 | # views of themselves. |
239 | + # (To override short format representation, override the lead method) | ||
239 | def to_html(options = {}) | 240 | def to_html(options = {}) |
240 | - body || '' | 241 | + if options[:format] == 'short' |
242 | + display_short_format(self) | ||
243 | + else | ||
244 | + body || '' | ||
245 | + end | ||
241 | end | 246 | end |
242 | 247 | ||
243 | include ApplicationHelper | 248 | include ApplicationHelper |
test/unit/article_test.rb
@@ -97,6 +97,21 @@ class ArticleTest < ActiveSupport::TestCase | @@ -97,6 +97,21 @@ class ArticleTest < ActiveSupport::TestCase | ||
97 | assert_equal '', a.to_html | 97 | assert_equal '', a.to_html |
98 | end | 98 | end |
99 | 99 | ||
100 | + should 'provide short html version' do | ||
101 | + a = fast_create(Article, :body => 'full body', :abstract => 'lead') | ||
102 | + a.stubs(:url).returns({:x=>'none'}) | ||
103 | + a.stubs(:link_to).returns('<link>') | ||
104 | + def a.content_tag (tag, content, c=nil) | ||
105 | + "<#{tag}>#{content}</#{tag}>" | ||
106 | + end | ||
107 | + assert_match /<div>lead.*/, a.to_html(:format=>'short') | ||
108 | + end | ||
109 | + | ||
110 | + should 'provide full html version' do | ||
111 | + a = fast_create(Article, :body => 'full body', :abstract => 'lead') | ||
112 | + assert_equal 'full body', a.to_html(:format=>'full body') | ||
113 | + end | ||
114 | + | ||
100 | should 'provide first paragraph of HTML version' do | 115 | should 'provide first paragraph of HTML version' do |
101 | profile = create_user('testinguser').person | 116 | profile = create_user('testinguser').person |
102 | a = fast_create(Article, :name => 'my article', :profile_id => profile.id) | 117 | a = fast_create(Article, :name => 'my article', :profile_id => profile.id) |