Commit c9517286e7bee94dd2230c6f08ffd3c7285f38dd

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 26a8cdfc

Added option to configure if preview in posts will be displayed

(cherry picked from commit 840e77eb53a5432ff99e8fe4966c61aeba9df14d)
app/helpers/blog_helper.rb
@@ -6,7 +6,13 @@ module BlogHelper @@ -6,7 +6,13 @@ module BlogHelper
6 @article = article 6 @article = article
7 hidden_field_tag('article[published]', 1) + 7 hidden_field_tag('article[published]', 1) +
8 hidden_field_tag('article[accept_comments]', 0) + 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 end 16 end
11 17
12 def cms_label_for_new_children 18 def cms_label_for_new_children
app/models/article.rb
@@ -8,7 +8,8 @@ class Article < ActiveRecord::Base @@ -8,7 +8,8 @@ class Article < ActiveRecord::Base
8 :accept_comments, :feed, :published, :source, :source_name, 8 :accept_comments, :feed, :published, :source, :source_name,
9 :highlighted, :notify_comments, :display_hits, :slug, 9 :highlighted, :notify_comments, :display_hits, :slug,
10 :external_feed_builder, :display_versions, :external_link, 10 :external_feed_builder, :display_versions, :external_link,
11 - :image_builder, :show_to_followers 11 + :image_builder, :show_to_followers,
  12 + :display_preview
12 13
13 acts_as_having_image 14 acts_as_having_image
14 15
@@ -634,6 +635,12 @@ class Article < ActiveRecord::Base @@ -634,6 +635,12 @@ class Article < ActiveRecord::Base
634 can_display_hits? && display_hits 635 can_display_hits? && display_hits
635 end 636 end
636 637
  638 + settings_items :display_preview, :type => :boolean, :default => false
  639 +
  640 + def display_preview?
  641 + false
  642 + end
  643 +
637 def image? 644 def image?
638 false 645 false
639 end 646 end
app/models/text_article.rb
@@ -41,4 +41,8 @@ class TextArticle < Article @@ -41,4 +41,8 @@ class TextArticle < Article
41 end 41 end
42 end 42 end
43 43
  44 + def display_preview?
  45 + parent && parent.kind_of?(Blog) && parent.display_preview
  46 + end
  47 +
44 end 48 end
app/views/content_viewer/_article_title.html.erb
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 <% end %> 7 <% end %>
8 </h1> 8 </h1>
9 <%= render :partial => "publishing_info" %> 9 <%= render :partial => "publishing_info" %>
10 - <% unless @page.abstract.blank? %> 10 + <% if @page.display_preview? %>
11 <div class="preview"> 11 <div class="preview">
12 <%= @page.lead %> 12 <%= @page.lead %>
13 </div> 13 </div>
test/unit/article_test.rb
@@ -2180,4 +2180,8 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -2180,4 +2180,8 @@ class ArticleTest &lt; ActiveSupport::TestCase
2180 article.destroy 2180 article.destroy
2181 end 2181 end
2182 2182
  2183 + should 'have display_preview' do
  2184 + a = Article.new(:display_preview => false)
  2185 + assert !a.display_preview?
  2186 + end
2183 end 2187 end
test/unit/text_article_test.rb
@@ -120,4 +120,12 @@ class TextArticleTest &lt; ActiveSupport::TestCase @@ -120,4 +120,12 @@ class TextArticleTest &lt; ActiveSupport::TestCase
120 assert text.translatable? 120 assert text.translatable?
121 end 121 end
122 122
  123 + should 'display preview when configured on parent that is a blog' do
  124 + person = fast_create(Person)
  125 + post = fast_create(TextArticle, :profile_id => person.id)
  126 + blog = Blog.new(:display_preview => true)
  127 + post.parent = blog
  128 + assert post.display_preview?
  129 + end
  130 +
123 end 131 end