Commit 769eb2c53f8dc122dd2ffbe2266bbe76aa2d1f69
Committed by
Rodrigo Souto
1 parent
a349d8fa
Exists in
master
and in
22 other branches
Add new visualization option for blog posts.
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
9 changed files
with
108 additions
and
9 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -11,6 +11,7 @@ class ContentViewerController < ApplicationController | @@ -11,6 +11,7 @@ class ContentViewerController < ApplicationController | ||
11 | path = get_path(params[:page], params[:format]) | 11 | path = get_path(params[:page], params[:format]) |
12 | 12 | ||
13 | @version = params[:version].to_i | 13 | @version = params[:version].to_i |
14 | + @npage = params[:npage] || '1' | ||
14 | 15 | ||
15 | if path.blank? | 16 | if path.blank? |
16 | @page = profile.home_page | 17 | @page = profile.home_page |
app/helpers/blog_helper.rb
@@ -2,6 +2,7 @@ module BlogHelper | @@ -2,6 +2,7 @@ module BlogHelper | ||
2 | 2 | ||
3 | include ArticleHelper | 3 | include ArticleHelper |
4 | 4 | ||
5 | + | ||
5 | def custom_options_for_article(article,tokenized_children) | 6 | def custom_options_for_article(article,tokenized_children) |
6 | @article = article | 7 | @article = article |
7 | hidden_field_tag('article[published]', 1) + | 8 | hidden_field_tag('article[published]', 1) + |
@@ -22,7 +23,9 @@ module BlogHelper | @@ -22,7 +23,9 @@ module BlogHelper | ||
22 | :param_name => 'npage', | 23 | :param_name => 'npage', |
23 | :previous_label => _('« Newer posts'), | 24 | :previous_label => _('« Newer posts'), |
24 | :next_label => _('Older posts »'), | 25 | :next_label => _('Older posts »'), |
25 | - :params => {:action=>"view_page", :page=>articles.first.parent.path.split('/'), :controller=>"content_viewer"} | 26 | + :params => {:action=>"view_page", |
27 | + :page=>articles.first.parent.path.split('/'), | ||
28 | + :controller=>"content_viewer"} | ||
26 | }) if articles.present? && conf[:paginate] | 29 | }) if articles.present? && conf[:paginate] |
27 | content = [] | 30 | content = [] |
28 | artic_len = articles.length | 31 | artic_len = articles.length |
@@ -44,7 +47,7 @@ module BlogHelper | @@ -44,7 +47,7 @@ module BlogHelper | ||
44 | end | 47 | end |
45 | 48 | ||
46 | def display_post(article, format = 'full') | 49 | def display_post(article, format = 'full') |
47 | - no_comments = (format == 'full') ? false : true | 50 | + no_comments = (format == 'full' || format == 'compact' ) ? false : true |
48 | title = article_title(article, :no_comments => no_comments) | 51 | title = article_title(article, :no_comments => no_comments) |
49 | method = "display_#{format.split('+')[0]}_format" | 52 | method = "display_#{format.split('+')[0]}_format" |
50 | html = send(method, FilePresenter.for(article)).html_safe | 53 | html = send(method, FilePresenter.for(article)).html_safe |
@@ -55,8 +58,12 @@ module BlogHelper | @@ -55,8 +58,12 @@ module BlogHelper | ||
55 | else | 58 | else |
56 | '<div class="post-pic" style="background-image:url('+img+')"></div>' | 59 | '<div class="post-pic" style="background-image:url('+img+')"></div>' |
57 | end | 60 | end |
58 | - end.to_s + | ||
59 | - title + html | 61 | + end.to_s + title + html |
62 | + end | ||
63 | + | ||
64 | + def display_compact_format(article) | ||
65 | + render :file => 'content_viewer/_display_compact_format', | ||
66 | + :locals => { :article => article, :format => "compact" } | ||
60 | end | 67 | end |
61 | 68 | ||
62 | def display_full_format(article) | 69 | def display_full_format(article) |
app/models/blog.rb
@@ -76,9 +76,12 @@ class Blog < Folder | @@ -76,9 +76,12 @@ class Blog < Folder | ||
76 | end | 76 | end |
77 | 77 | ||
78 | settings_items :visualization_format, :type => :string, :default => 'full' | 78 | settings_items :visualization_format, :type => :string, :default => 'full' |
79 | - validates_inclusion_of :visualization_format, :in => [ 'full', 'short', 'short+pic' ], :if => :visualization_format | 79 | + validates_inclusion_of :visualization_format, |
80 | + :in => [ 'full', 'short', 'short+pic', 'compact'], | ||
81 | + :if => :visualization_format | ||
80 | 82 | ||
81 | - settings_items :display_posts_in_current_language, :type => :boolean, :default => false | 83 | + settings_items :display_posts_in_current_language, |
84 | + :type => :boolean, :default => false | ||
82 | 85 | ||
83 | alias :display_posts_in_current_language? :display_posts_in_current_language | 86 | alias :display_posts_in_current_language? :display_posts_in_current_language |
84 | 87 |
app/views/cms/_blog.html.erb
@@ -67,7 +67,8 @@ | @@ -67,7 +67,8 @@ | ||
67 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ | 67 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ |
68 | [ _('Full post'), 'full'], | 68 | [ _('Full post'), 'full'], |
69 | [ _('First paragraph'), 'short'], | 69 | [ _('First paragraph'), 'short'], |
70 | - [ _('First paragraph, with post picture'), 'short+pic'] | 70 | + [ _('First paragraph, with post picture'), 'short+pic'], |
71 | + [ _("Title, Image, Lead"), 'compact'] | ||
71 | ])) %> | 72 | ])) %> |
72 | 73 | ||
73 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> | 74 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> |
app/views/content_viewer/_display_compact_format.html.erb
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +<% if article.image %> | ||
2 | + <% className = "article-compact-abstract-with-image" %> | ||
3 | + <% if article.image.thumbnails_processed? %> | ||
4 | + <% image_file = article.image.thumbnails[4].public_filename %> | ||
5 | + <% else %> | ||
6 | + <% image_file = "/images/icons-app/image-loading-thumb.png" %> | ||
7 | + <% end %> | ||
8 | +<% else %> | ||
9 | + <% className = "article-compact-abstract" %> | ||
10 | +<% end %> | ||
11 | + | ||
12 | +<div> | ||
13 | + <% if article.image %> | ||
14 | + <div class = "article-compact-image"> | ||
15 | + <%= image_tag(image_file) %> | ||
16 | + </div> | ||
17 | + <% end %> | ||
18 | + <div class = <%= className %> > | ||
19 | + <%= article.abstract.truncate(400) %> | ||
20 | + </div> | ||
21 | +</div> |
app/views/content_viewer/blog_page.html.erb
public/stylesheets/application.css
@@ -1559,6 +1559,32 @@ div.article-body p img { | @@ -1559,6 +1559,32 @@ div.article-body p img { | ||
1559 | #content .blog-post .read-more a { | 1559 | #content .blog-post .read-more a { |
1560 | margin: 0 10px; | 1560 | margin: 0 10px; |
1561 | } | 1561 | } |
1562 | + | ||
1563 | +#content #article .blog-posts .blog-post .article-compact-abstract{ | ||
1564 | + position: relative; | ||
1565 | + float:left; | ||
1566 | + margin-left: 10px; | ||
1567 | + width: 100%; | ||
1568 | + word-wrap: break-word; | ||
1569 | +} | ||
1570 | + | ||
1571 | +#content #article .blog-posts .blog-post .article-compact-image{ | ||
1572 | + position:relative; | ||
1573 | + float:left; | ||
1574 | + width: 27%; | ||
1575 | + display: table-cell; | ||
1576 | + vertical-align: middle; | ||
1577 | + text-align: center; | ||
1578 | + margin-top: 15px; | ||
1579 | +} | ||
1580 | + | ||
1581 | +#content #article .blog-posts .blog-post .article-compact-abstract-with-image{ | ||
1582 | + position: relative; | ||
1583 | + float:left; | ||
1584 | + margin-left: 10px; | ||
1585 | + width: 70%; | ||
1586 | + word-wrap: break-word; | ||
1587 | +} | ||
1562 | /* NOT PUBLISHED BLOG POSTS */ | 1588 | /* NOT PUBLISHED BLOG POSTS */ |
1563 | 1589 | ||
1564 | .blog-post.not-published { | 1590 | .blog-post.not-published { |
test/functional/content_viewer_controller_test.rb
@@ -1547,4 +1547,31 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -1547,4 +1547,31 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
1547 | assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :href => "/anotherurl" }} | 1547 | assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :href => "/anotherurl" }} |
1548 | end | 1548 | end |
1549 | 1549 | ||
1550 | + should 'show lead,image and title in compact blog visualization' do | ||
1551 | + community = Community.create(:name => 'test-community') | ||
1552 | + community.add_member(@profile) | ||
1553 | + community.save! | ||
1554 | + | ||
1555 | + blog = community.articles.find_by_name("Blog") | ||
1556 | + blog.visualization_format = 'compact' | ||
1557 | + blog.save! | ||
1558 | + | ||
1559 | + article = TinyMceArticle.create(:name => 'Article to be shared with images', | ||
1560 | + :body => 'This article should be shared with all social networks', | ||
1561 | + :profile => @profile, | ||
1562 | + :published => false, | ||
1563 | + :abstract => "teste teste teste", | ||
1564 | + :show_to_followers => true, | ||
1565 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} ) | ||
1566 | + article.parent = blog | ||
1567 | + article.save! | ||
1568 | + | ||
1569 | + login_as(@profile.identifier) | ||
1570 | + | ||
1571 | + | ||
1572 | + get :view_page, :profile => community.identifier, "page" => 'blog' | ||
1573 | + | ||
1574 | + assert_tag :tag => 'div', :attributes => { :class => 'article-compact-image' } | ||
1575 | + assert_tag :tag => 'div', :attributes => { :class => 'article-compact-abstract-with-image' } | ||
1576 | + end | ||
1550 | end | 1577 | end |
test/unit/blog_test.rb
@@ -161,7 +161,16 @@ class BlogTest < ActiveSupport::TestCase | @@ -161,7 +161,16 @@ class BlogTest < ActiveSupport::TestCase | ||
161 | assert_equal 'short', p.blog.visualization_format | 161 | assert_equal 'short', p.blog.visualization_format |
162 | end | 162 | end |
163 | 163 | ||
164 | - should 'allow only full and short as visualization_format' do | 164 | + should 'update visualization_format setting to compact' do |
165 | + p = create_user('testuser').person | ||
166 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') | ||
167 | + blog = p.blog | ||
168 | + blog.visualization_format = 'compact' | ||
169 | + assert blog.save! | ||
170 | + assert_equal 'compact', p.blog.visualization_format | ||
171 | + end | ||
172 | + | ||
173 | + should 'allow only full, short or compact as visualization_format' do | ||
165 | blog = build(Blog, :name => 'blog') | 174 | blog = build(Blog, :name => 'blog') |
166 | blog.visualization_format = 'wrong_format' | 175 | blog.visualization_format = 'wrong_format' |
167 | blog.valid? | 176 | blog.valid? |
@@ -174,6 +183,10 @@ class BlogTest < ActiveSupport::TestCase | @@ -174,6 +183,10 @@ class BlogTest < ActiveSupport::TestCase | ||
174 | blog.visualization_format = 'full' | 183 | blog.visualization_format = 'full' |
175 | blog.valid? | 184 | blog.valid? |
176 | assert !blog.errors[:visualization_format.to_s].present? | 185 | assert !blog.errors[:visualization_format.to_s].present? |
186 | + | ||
187 | + blog.visualization_format = 'compact' | ||
188 | + blog.valid? | ||
189 | + assert !blog.errors[:visualization_format.to_s].present? | ||
177 | end | 190 | end |
178 | 191 | ||
179 | should 'have posts' do | 192 | should 'have posts' do |