From 769eb2c53f8dc122dd2ffbe2266bbe76aa2d1f69 Mon Sep 17 00:00:00 2001 From: David Carlos Date: Wed, 11 Feb 2015 11:10:49 -0200 Subject: [PATCH] Add new visualization option for blog posts. --- app/controllers/public/content_viewer_controller.rb | 1 + app/helpers/blog_helper.rb | 15 +++++++++++---- app/models/blog.rb | 7 +++++-- app/views/cms/_blog.html.erb | 3 ++- app/views/content_viewer/_display_compact_format.html.erb | 21 +++++++++++++++++++++ app/views/content_viewer/blog_page.html.erb | 2 +- public/stylesheets/application.css | 26 ++++++++++++++++++++++++++ test/functional/content_viewer_controller_test.rb | 27 +++++++++++++++++++++++++++ test/unit/blog_test.rb | 15 ++++++++++++++- 9 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 app/views/content_viewer/_display_compact_format.html.erb diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index fe9443a..0260d8a 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -11,6 +11,7 @@ class ContentViewerController < ApplicationController path = get_path(params[:page], params[:format]) @version = params[:version].to_i + @npage = params[:npage] || '1' if path.blank? @page = profile.home_page diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index 5c87253..aa08107 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -2,6 +2,7 @@ module BlogHelper include ArticleHelper + def custom_options_for_article(article,tokenized_children) @article = article hidden_field_tag('article[published]', 1) + @@ -22,7 +23,9 @@ module BlogHelper :param_name => 'npage', :previous_label => _('« Newer posts'), :next_label => _('Older posts »'), - :params => {:action=>"view_page", :page=>articles.first.parent.path.split('/'), :controller=>"content_viewer"} + :params => {:action=>"view_page", + :page=>articles.first.parent.path.split('/'), + :controller=>"content_viewer"} }) if articles.present? && conf[:paginate] content = [] artic_len = articles.length @@ -44,7 +47,7 @@ module BlogHelper end def display_post(article, format = 'full') - no_comments = (format == 'full') ? false : true + no_comments = (format == 'full' || format == 'compact' ) ? false : true title = article_title(article, :no_comments => no_comments) method = "display_#{format.split('+')[0]}_format" html = send(method, FilePresenter.for(article)).html_safe @@ -55,8 +58,12 @@ module BlogHelper else '
' end - end.to_s + - title + html + end.to_s + title + html + end + + def display_compact_format(article) + render :file => 'content_viewer/_display_compact_format', + :locals => { :article => article, :format => "compact" } end def display_full_format(article) diff --git a/app/models/blog.rb b/app/models/blog.rb index edee58e..7a17124 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -76,9 +76,12 @@ class Blog < Folder end settings_items :visualization_format, :type => :string, :default => 'full' - validates_inclusion_of :visualization_format, :in => [ 'full', 'short', 'short+pic' ], :if => :visualization_format + validates_inclusion_of :visualization_format, + :in => [ 'full', 'short', 'short+pic', 'compact'], + :if => :visualization_format - settings_items :display_posts_in_current_language, :type => :boolean, :default => false + settings_items :display_posts_in_current_language, + :type => :boolean, :default => false alias :display_posts_in_current_language? :display_posts_in_current_language diff --git a/app/views/cms/_blog.html.erb b/app/views/cms/_blog.html.erb index 3a8c5be..5efe648 100644 --- a/app/views/cms/_blog.html.erb +++ b/app/views/cms/_blog.html.erb @@ -67,7 +67,8 @@ <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'], - [ _('First paragraph, with post picture'), 'short+pic'] + [ _('First paragraph, with post picture'), 'short+pic'], + [ _("Title, Image, Lead"), 'compact'] ])) %> <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> diff --git a/app/views/content_viewer/_display_compact_format.html.erb b/app/views/content_viewer/_display_compact_format.html.erb new file mode 100644 index 0000000..ad8d0e0 --- /dev/null +++ b/app/views/content_viewer/_display_compact_format.html.erb @@ -0,0 +1,21 @@ +<% if article.image %> + <% className = "article-compact-abstract-with-image" %> + <% if article.image.thumbnails_processed? %> + <% image_file = article.image.thumbnails[4].public_filename %> + <% else %> + <% image_file = "/images/icons-app/image-loading-thumb.png" %> + <% end %> +<% else %> + <% className = "article-compact-abstract" %> +<% end %> + +
+ <% if article.image %> +
+ <%= image_tag(image_file) %> +
+ <% end %> +
> + <%= article.abstract.truncate(400) %> +
+
diff --git a/app/views/content_viewer/blog_page.html.erb b/app/views/content_viewer/blog_page.html.erb index b4a9621..47f4252 100644 --- a/app/views/content_viewer/blog_page.html.erb +++ b/app/views/content_viewer/blog_page.html.erb @@ -8,7 +8,7 @@
-
+
<% paginate = true %> <%= posts = @posts diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 9c0117b..89d9a67 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1559,6 +1559,32 @@ div.article-body p img { #content .blog-post .read-more a { margin: 0 10px; } + +#content #article .blog-posts .blog-post .article-compact-abstract{ + position: relative; + float:left; + margin-left: 10px; + width: 100%; + word-wrap: break-word; +} + +#content #article .blog-posts .blog-post .article-compact-image{ + position:relative; + float:left; + width: 27%; + display: table-cell; + vertical-align: middle; + text-align: center; + margin-top: 15px; +} + +#content #article .blog-posts .blog-post .article-compact-abstract-with-image{ + position: relative; + float:left; + margin-left: 10px; + width: 70%; + word-wrap: break-word; +} /* NOT PUBLISHED BLOG POSTS */ .blog-post.not-published { diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 0d59889..c2031de 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1547,4 +1547,31 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :href => "/anotherurl" }} end + should 'show lead,image and title in compact blog visualization' do + community = Community.create(:name => 'test-community') + community.add_member(@profile) + community.save! + + blog = community.articles.find_by_name("Blog") + blog.visualization_format = 'compact' + blog.save! + + article = TinyMceArticle.create(:name => 'Article to be shared with images', + :body => 'This article should be shared with all social networks', + :profile => @profile, + :published => false, + :abstract => "teste teste teste", + :show_to_followers => true, + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} ) + article.parent = blog + article.save! + + login_as(@profile.identifier) + + + get :view_page, :profile => community.identifier, "page" => 'blog' + + assert_tag :tag => 'div', :attributes => { :class => 'article-compact-image' } + assert_tag :tag => 'div', :attributes => { :class => 'article-compact-abstract-with-image' } + end end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index da78199..39fdc85 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -161,7 +161,16 @@ class BlogTest < ActiveSupport::TestCase assert_equal 'short', p.blog.visualization_format end - should 'allow only full and short as visualization_format' do + should 'update visualization_format setting to compact' do + p = create_user('testuser').person + p.articles << build(Blog, :profile => p, :name => 'Blog test') + blog = p.blog + blog.visualization_format = 'compact' + assert blog.save! + assert_equal 'compact', p.blog.visualization_format + end + + should 'allow only full, short or compact as visualization_format' do blog = build(Blog, :name => 'blog') blog.visualization_format = 'wrong_format' blog.valid? @@ -174,6 +183,10 @@ class BlogTest < ActiveSupport::TestCase blog.visualization_format = 'full' blog.valid? assert !blog.errors[:visualization_format.to_s].present? + + blog.visualization_format = 'compact' + blog.valid? + assert !blog.errors[:visualization_format.to_s].present? end should 'have posts' do -- libgit2 0.21.2