Commit 840e77eb53a5432ff99e8fe4966c61aeba9df14d

Authored by Daniela Feitosa
1 parent 945870d9

Added option to configure if preview in posts will be displayed

app/helpers/blog_helper.rb
... ... @@ -6,7 +6,13 @@ module BlogHelper
6 6 @article = article
7 7 hidden_field_tag('article[published]', 1) +
8 8 hidden_field_tag('article[accept_comments]', 0) +
9   - visibility_options(article,tokenized_children)
  9 + visibility_options(article,tokenized_children) +
  10 + content_tag('h4', _('Visualization of posts')) +
  11 + content_tag(
  12 + 'div',
  13 + check_box(:article, :display_preview) +
  14 + content_tag('label', _('I want to display the preview of posts before the text'), :for => 'article_display_preview')
  15 + )
10 16 end
11 17  
12 18 def cms_label_for_new_children
... ...
app/models/article.rb
... ... @@ -9,7 +9,7 @@ class Article < ActiveRecord::Base
9 9 :highlighted, :notify_comments, :display_hits, :slug,
10 10 :external_feed_builder, :display_versions, :external_link,
11 11 :image_builder, :show_to_followers,
12   - :author
  12 + :author, :display_preview
13 13  
14 14 acts_as_having_image
15 15  
... ... @@ -643,6 +643,12 @@ class Article < ActiveRecord::Base
643 643 false
644 644 end
645 645  
  646 + settings_items :display_preview, :type => :boolean, :default => false
  647 +
  648 + def display_preview?
  649 + false
  650 + end
  651 +
646 652 def image?
647 653 false
648 654 end
... ...
app/models/text_article.rb
... ... @@ -41,4 +41,8 @@ class TextArticle < Article
41 41 end
42 42 end
43 43  
  44 + def display_preview?
  45 + parent && parent.kind_of?(Blog) && parent.display_preview
  46 + end
  47 +
44 48 end
... ...
app/views/content_viewer/_article_title.html.erb
... ... @@ -7,7 +7,7 @@
7 7 <% end %>
8 8 </h1>
9 9 <%= render :partial => "publishing_info" %>
10   - <% unless @page.abstract.blank? %>
  10 + <% if @page.display_preview? %>
11 11 <div class="preview">
12 12 <%= @page.lead %>
13 13 </div>
... ...
test/unit/article_test.rb
... ... @@ -2214,4 +2214,9 @@ class ArticleTest &lt; ActiveSupport::TestCase
2214 2214 assert !a.display_media_panel?
2215 2215 end
2216 2216  
  2217 + should 'have display_preview' do
  2218 + a = Article.new(:display_preview => false)
  2219 + assert !a.display_preview?
  2220 + end
  2221 +
2217 2222 end
... ...
test/unit/text_article_test.rb
... ... @@ -109,4 +109,12 @@ class TextArticleTest &lt; ActiveSupport::TestCase
109 109 assert text.translatable?
110 110 end
111 111  
  112 + should 'display preview when configured on parent that is a blog' do
  113 + person = fast_create(Person)
  114 + post = fast_create(TextArticle, :profile_id => person.id)
  115 + blog = Blog.new(:display_preview => true)
  116 + post.parent = blog
  117 + assert post.display_preview?
  118 + end
  119 +
112 120 end
... ...