[noosfero/noosfero][master] 4 commits: Add new visualization option for blog posts.

Rodrigo Souto gitlab at gitlab.com
Fri Jun 12 13:34:27 BRT 2015


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
769eb2c5 by David Carlos at 2015-06-12T13:03:20Z
Add new visualization option for blog posts.

Signed-off-by: Arthur Del Esposte <arthurmde at gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392 at gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>

- - - - -
b8629708 by Gabriela Navarro at 2015-06-12T13:03:20Z
Add date format option for articles from the environment

Signed-off-by: Arthur Del Esposte <arthurmde at gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392 at gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079 at gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>

- - - - -
853418be by Gabriela Navarro at 2015-06-12T13:03:20Z
db/schema.rb: update

- - - - -
dbea8847 by Gabriela Navarro at 2015-06-12T13:33:36Z
Refactor deprecated code for date to use rails method

Signed-off-by: Antonio Terceiro <terceiro at colivre.coop.br>
Signed-off-by: Arthur Del Esposte <arthurmde at gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>

- - - - -


40 changed files:

- app/controllers/public/content_viewer_controller.rb
- app/helpers/application_helper.rb
- app/helpers/blog_helper.rb
- app/helpers/comment_helper.rb
- app/helpers/content_viewer_helper.rb
- app/helpers/dates_helper.rb
- app/helpers/events_helper.rb
- app/helpers/forum_helper.rb
- app/models/blog.rb
- app/models/environment.rb
- app/views/admin_panel/_site_info.html.erb
- app/views/cms/_blog.html.erb
- + app/views/content_viewer/_display_compact_format.html.erb
- app/views/content_viewer/blog_page.html.erb
- app/views/person_notifier/mailer/_comment.html.erb
- app/views/person_notifier/mailer/_create_article.html.erb
- app/views/person_notifier/mailer/_default_activity.html.erb
- app/views/person_notifier/mailer/_task.html.erb
- app/views/person_notifier/mailer/_upload_image.html.erb
- app/views/profile/_comment.html.erb
- app/views/profile/_create_article.html.erb
- app/views/profile/_default_activity.html.erb
- app/views/profile/_leave_scrap.html.erb
- app/views/profile/_profile_scrap.html.erb
- app/views/profile/_profile_scraps.html.erb
- app/views/profile/_upload_image.html.erb
- app/views/tasks/_abuse_complaint_accept_details.html.erb
- + db/migrate/20150529180110_add_date_format_to_environment.rb
- db/schema.rb
- plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb
- public/stylesheets/application.css
- test/functional/admin_panel_controller_test.rb
- test/functional/content_viewer_controller_test.rb
- test/test_helper.rb
- test/unit/blog_test.rb
- test/unit/content_viewer_helper_test.rb
- test/unit/dates_helper_test.rb
- test/unit/environment_test.rb
- test/unit/events_helper_test.rb
- test/unit/forum_helper_test.rb


Changes:

=====================================
app/controllers/public/content_viewer_controller.rb
=====================================
--- 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


=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1215,35 +1215,6 @@ module ApplicationHelper
     list.sort.inject(Hash.new(0)){|h,i| h[i] += 1; h }.collect{ |x, n| [n, connector, x].join(" ") }.sort
   end
 
-  #FIXME Use time_ago_in_words instead of this method if you're using Rails 2.2+
-  def time_ago_as_sentence(from_time, include_seconds = false)
-    to_time = Time.now
-    from_time = Time.parse(from_time.to_s)
-    from_time = from_time.to_time if from_time.respond_to?(:to_time)
-    to_time = to_time.to_time if to_time.respond_to?(:to_time)
-    distance_in_minutes = (((to_time - from_time).abs)/60).round
-    distance_in_seconds = ((to_time - from_time).abs).round
-    case distance_in_minutes
-      when 0..1
-        return (distance_in_minutes == 0) ? _('less than a minute') : _('1 minute') unless include_seconds
-        case distance_in_seconds
-          when 0..4   then _('less than 5 seconds')
-          when 5..9   then _('less than 10 seconds')
-          when 10..19 then _('less than 20 seconds')
-          when 20..39 then _('half a minute')
-          when 40..59 then _('less than a minute')
-          else             _('1 minute')
-        end
-
-      when 2..44           then _('%{distance} minutes ago') % { :distance => distance_in_minutes }
-      when 45..89          then _('about 1 hour ago')
-      when 90..1439        then _('about %{distance} hours ago') % { :distance => (distance_in_minutes.to_f / 60.0).round }
-      when 1440..2879      then _('1 day ago')
-      when 2880..10079     then _('%{distance} days ago') % { :distance => (distance_in_minutes / 1440).round }
-      else                      show_time(from_time)
-    end
-  end
-
   def comment_balloon(options = {}, &block)
     wrapper = content_tag(:div, capture(&block), :class => 'comment-balloon-content')
     (1..8).to_a.reverse.each { |i| wrapper = content_tag(:div, wrapper, :class => "comment-wrapper-#{i}") }


=====================================
app/helpers/blog_helper.rb
=====================================
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -22,7 +22,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 +46,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 +57,12 @@ module BlogHelper
       else
         '<div class="post-pic" style="background-image:url('+img+')"></div>'
       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)


=====================================
app/helpers/comment_helper.rb
=====================================
--- a/app/helpers/comment_helper.rb
+++ b/app/helpers/comment_helper.rb
@@ -1,4 +1,5 @@
 module CommentHelper
+  include DatesHelper
 
   def article_title(article, args = {})
     title = article.title


=====================================
app/helpers/content_viewer_helper.rb
=====================================
--- a/app/helpers/content_viewer_helper.rb
+++ b/app/helpers/content_viewer_helper.rb
@@ -2,6 +2,7 @@ module ContentViewerHelper
 
   include BlogHelper
   include ForumHelper
+  include DatesHelper
 
   def display_number_of_comments(n)
     base_str = "<span class='comment-count hide'>#{n}</span>"
@@ -24,8 +25,9 @@ module ContentViewerHelper
       unless args[:no_comments] || !article.accept_comments
         comments = (" - %s") % link_to_comments(article)
       end
+      date_format = show_with_right_format_date article
       title << content_tag('span',
-        content_tag('span', show_date(article.published_at), :class => 'date') +
+        date_format +
         content_tag('span', _(", by %s") % (article.author ? link_to(article.author_name, article.author_url) : article.author_name), :class => 'author') +
         content_tag('span', comments, :class => 'comments'),
         :class => 'created-at'
@@ -34,6 +36,24 @@ module ContentViewerHelper
     title
   end
 
+  def show_with_right_format_date article
+    date_format = article.environment.date_format
+    use_numbers = false
+    year = true
+    left_time = false
+    if date_format ==  'numbers_with_year'
+      use_numbers = true
+    elsif date_format == 'numbers'
+      use_numbers = true
+      year = false
+    elsif date_format == 'month_name'
+      year = false
+    elsif date_format == 'past_time'
+      left_time = true
+    end
+    content_tag('span', show_date(article.published_at, use_numbers , year, left_time), :class => 'date')
+  end
+
   def link_to_comments(article, args = {})
     return '' unless article.accept_comments?
     reference_to_article number_of_comments(article), article, 'comments_list'


=====================================
app/helpers/dates_helper.rb
=====================================
--- a/app/helpers/dates_helper.rb
+++ b/app/helpers/dates_helper.rb
@@ -2,6 +2,7 @@ require 'noosfero/i18n'
 
 module DatesHelper
 
+  include ActionView::Helpers::DateHelper
   def months
     I18n.t('date.month_names')
   end
@@ -15,10 +16,12 @@ module DatesHelper
   end
 
   # formats a date for displaying.
-  def show_date(date, use_numbers = false, year=true)
+  def show_date(date, use_numbers = false, year = true, left_time = false)
     if date && use_numbers
       date_format = year ? _('%{month}/%{day}/%{year}') : _('%{month}/%{day}')
       date_format % { :day => date.day, :month => date.month, :year => date.year }
+    elsif date && left_time
+      date_format = time_ago_in_words(date)
     elsif date
       date_format = year ? _('%{month_name} %{day}, %{year}') : _('%{month_name} %{day}')
       date_format % { :day => date.day, :month_name => month_name(date.month), :year => date.year }


=====================================
app/helpers/events_helper.rb
=====================================
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -1,5 +1,6 @@
 module EventsHelper
 
+  include DatesHelper
   def list_events(date, events)
     title = _('Events for %s') % show_date_month(date)
     content_tag('h2', title) +


=====================================
app/helpers/forum_helper.rb
=====================================
--- a/app/helpers/forum_helper.rb
+++ b/app/helpers/forum_helper.rb
@@ -1,4 +1,5 @@
 module ForumHelper
+  include ActionView::Helpers::DateHelper
 
   def cms_label_for_new_children
     _('New discussion topic')
@@ -42,9 +43,9 @@ module ForumHelper
   def last_topic_update(article)
     info = article.info_from_last_update
     if info[:author_url]
-      time_ago_as_sentence(info[:date]) + ' ' + _('by') + ' ' + link_to(info[:author_name], info[:author_url])
+      time_ago_in_words(info[:date]) + ' ' + _('by') + ' ' + link_to(info[:author_name], info[:author_url])
     else
-      time_ago_as_sentence(info[:date]) + ' ' + _('by') + ' ' + info[:author_name]
+      time_ago_in_words(info[:date]) + ' ' + _('by') + ' ' + info[:author_name]
     end
   end
 


=====================================
app/models/blog.rb
=====================================
--- 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
 


=====================================
app/models/environment.rb
=====================================
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -3,7 +3,17 @@
 # domains.
 class Environment < ActiveRecord::Base
 
-  attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body, :members_whitelist_enabled, :members_whitelist, :highlighted_news_amount, :portal_news_amount
+  attr_accessible :name, :is_default, :signup_welcome_text_subject,
+                  :signup_welcome_text_body, :terms_of_use,
+                  :message_for_disabled_enterprise, :news_amount_by_folder,
+                  :default_language, :languages, :description,
+                  :organization_approval_method, :enabled_plugins,
+                  :enabled_features, :redirection_after_login,
+                  :redirection_after_signup, :contact_email, :theme,
+                  :reports_lower_bound, :noreply_email,
+                  :signup_welcome_screen_body, :members_whitelist_enabled,
+                  :members_whitelist, :highlighted_news_amount,
+                  :portal_news_amount, :date_format
 
   has_many :users
 
@@ -14,6 +24,12 @@ class Environment < ActiveRecord::Base
 
   IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/
 
+  validates_inclusion_of :date_format,
+                         :in => [ 'numbers_with_year', 'numbers',
+                                  'month_name_with_year', 'month_name',
+                                  'past_time'],
+                         :if => :date_format
+
   def self.verify_filename(filename)
     filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS
     filename


=====================================
app/views/admin_panel/_site_info.html.erb
=====================================
--- a/app/views/admin_panel/_site_info.html.erb
+++ b/app/views/admin_panel/_site_info.html.erb
@@ -3,6 +3,21 @@
 <%= labelled_form_field(_('No reply email'), text_field(:environment, :noreply_email)) %>
 <% themes_options = Theme.system_themes.map {|theme| [theme.name, theme.id] }.sort %>
 <%= labelled_form_field(_('Theme'), select(:environment, :theme, options_for_select(themes_options, environment.theme))) %>
+
+<%= labelled_form_field(
+  _("Article's date format"),
+  select(:environment, :date_format,
+    options_for_select([
+      [ _('mm/dd/yyyy'), 'numbers_with_year'],
+      [ _('mm/dd'), 'numbers'],
+      [ _('Month dd, yyyy'), 'month_name_with_year'],
+      [ _('Month dd'), 'month_name'],
+      [ _('X minutes/hours/days/months/years ago'), 'past_time']
+      ], environment.date_format
+    )
+  )
+) %>
+
 <%= required f.text_field(:reports_lower_bound, :size => 3) %>
 <%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %>
 <%= label_tag :languages, _('Available languages') %>


=====================================
app/views/cms/_blog.html.erb
=====================================
--- 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)) %>


=====================================
app/views/content_viewer/_display_compact_format.html.erb
=====================================
--- /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 %>
+
+<div>
+  <% if article.image %>
+    <div class = "article-compact-image">
+      <%= image_tag(image_file) %>
+    </div>
+  <% end %>
+  <div class = <%= className %> >
+      <%= article.abstract.truncate(400) %>
+  </div>
+</div>


=====================================
app/views/content_viewer/blog_page.html.erb
=====================================
--- a/app/views/content_viewer/blog_page.html.erb
+++ b/app/views/content_viewer/blog_page.html.erb
@@ -8,7 +8,7 @@
   </div>
 </div>
 <hr class="pre-posts"/>
-<div class="blog-posts">
+<div class="blog-posts page-<%= @npage %>">
   <% paginate = true %>
   <%=
    posts = @posts


=====================================
app/views/person_notifier/mailer/_comment.html.erb
=====================================
--- a/app/views/person_notifier/mailer/_comment.html.erb
+++ b/app/views/person_notifier/mailer/_comment.html.erb
@@ -19,7 +19,7 @@
         <span style="font-size: 12px;"><%= comment.title %></span><br/>
       <% end %>
       <span style="font-size: 10px;"><%= txt2html comment.body %></span><br/>
-      <span style="font-size: 8px; color: #929292"><%= time_ago_as_sentence(comment.created_at) %></span>
+      <span style="font-size: 8px; color: #929292"><%= time_ago_in_words(comment.created_at) %></span>
   <br style="clear: both;" />
 
   <% unless comment.replies.blank? %>


=====================================
app/views/person_notifier/mailer/_create_article.html.erb
=====================================
--- a/app/views/person_notifier/mailer/_create_article.html.erb
+++ b/app/views/person_notifier/mailer/_create_article.html.erb
@@ -6,7 +6,7 @@
     <p>
     <span style="font-size: 14px;"><%= link_to activity.user.short_name(20), activity.user.url %></span>
     <span style="font-size: 14px;"><%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %></span>
-    <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span>
+    <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_in_words(activity.created_at) %></span>
     </p>
     <p>
     <span style="font-size: 14px;"><%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %></span>


=====================================
app/views/person_notifier/mailer/_default_activity.html.erb
=====================================
--- a/app/views/person_notifier/mailer/_default_activity.html.erb
+++ b/app/views/person_notifier/mailer/_default_activity.html.erb
@@ -5,7 +5,7 @@
   <td>
     <p>
       <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span>
-      <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(activity.created_at) %></span>
+      <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(activity.created_at) %></span>
     </p>
   </td>
 </tr>


=====================================
app/views/person_notifier/mailer/_task.html.erb
=====================================
--- a/app/views/person_notifier/mailer/_task.html.erb
+++ b/app/views/person_notifier/mailer/_task.html.erb
@@ -12,7 +12,7 @@
           <span style="font-size: 14px">
             <%= task_information(task) %>
           </span>
-          <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(task.created_at) %></span>
+          <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(task.created_at) %></span>
         </div>
       </td>
     </tr>


=====================================
app/views/person_notifier/mailer/_upload_image.html.erb
=====================================
--- a/app/views/person_notifier/mailer/_upload_image.html.erb
+++ b/app/views/person_notifier/mailer/_upload_image.html.erb
@@ -5,7 +5,7 @@
     <td>
       <p>
         <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span>
-        <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span>
+        <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_in_words(activity.created_at) %></span>
       </p>
   </td>
 </tr>


=====================================
app/views/profile/_comment.html.erb
=====================================
--- a/app/views/profile/_comment.html.erb
+++ b/app/views/profile/_comment.html.erb
@@ -40,7 +40,7 @@
       <%= txt2html comment.body %>
     </div>
     <div class="profile-activity-time">
-      <%= time_ago_as_sentence(comment.created_at) %>
+      <%= time_ago_in_words(comment.created_at) %>
     </div>
   </div>
 


=====================================
app/views/profile/_create_article.html.erb
=====================================
--- a/app/views/profile/_create_article.html.erb
+++ b/app/views/profile/_create_article.html.erb
@@ -12,7 +12,7 @@
     <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xC2\xA0|\s)+/, ' ').gsub(/^\s+/, '') unless activity.params['lead'].blank? %> <small><%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %></small>
   </div>
   <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %>
-  <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
+  <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p>
   <div class='profile-wall-actions'>
     <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %>
     <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :only_hide => true, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>


=====================================
app/views/profile/_default_activity.html.erb
=====================================
--- a/app/views/profile/_default_activity.html.erb
+++ b/app/views/profile/_default_activity.html.erb
@@ -3,7 +3,7 @@
 </div>
 <div class='profile-activity-description'>
   <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
-  <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
+  <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p>
   <div class='profile-wall-actions'>
     <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %>
     <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>


=====================================
app/views/profile/_leave_scrap.html.erb
=====================================
--- a/app/views/profile/_leave_scrap.html.erb
+++ b/app/views/profile/_leave_scrap.html.erb
@@ -3,7 +3,7 @@
 </div>
 <div class='profile-activity-description'>
   <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
-  <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
+  <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p>
   <div class='profile-wall-actions'>
     <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
   </div>


=====================================
app/views/profile/_profile_scrap.html.erb
=====================================
--- a/app/views/profile/_profile_scrap.html.erb
+++ b/app/views/profile/_profile_scrap.html.erb
@@ -5,7 +5,7 @@
   <div class='profile-activity-description'>
     <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p>
     <p class='profile-activity-text'><%= txt2html scrap.content %></p>
-    <p class='profile-activity-time'><%= time_ago_as_sentence(scrap.created_at) %></p>
+    <p class='profile-activity-time'><%= time_ago_in_words(scrap.created_at) %></p>
     <div class='profile-wall-actions'>
     <% if logged_in? && current_person.follows?(scrap.sender) %>
       <span class='profile-activity-send-reply'>
@@ -22,5 +22,5 @@
     <% end %>
   </ul>
   <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %>
-  <hr />  
+  <hr />
 </li>


=====================================
app/views/profile/_profile_scraps.html.erb
=====================================
--- a/app/views/profile/_profile_scraps.html.erb
+++ b/app/views/profile/_profile_scraps.html.erb
@@ -5,7 +5,7 @@
   <div class='profile-activity-description'>
     <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p>
     <p class='profile-activity-text'><%= txt2html scrap.content %></p>
-    <p class='profile-activity-time'><%= time_ago_as_sentence(scrap.created_at) %></p>
+    <p class='profile-activity-time'><%= time_ago_in_words(scrap.created_at) %></p>
     <div class='profile-wall-actions'>
     <% if logged_in? && current_person.follows?(scrap.sender) %>
       <span class='profile-activity-send-reply'>


=====================================
app/views/profile/_upload_image.html.erb
=====================================
--- a/app/views/profile/_upload_image.html.erb
+++ b/app/views/profile/_upload_image.html.erb
@@ -4,7 +4,7 @@
   </div>
   <div class='profile-activity-description'>
     <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
-    <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
+    <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p>
     <div class='profile-wall-actions'>
       <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
     </div>


=====================================
app/views/tasks/_abuse_complaint_accept_details.html.erb
=====================================
--- a/app/views/tasks/_abuse_complaint_accept_details.html.erb
+++ b/app/views/tasks/_abuse_complaint_accept_details.html.erb
@@ -2,7 +2,7 @@
 <% task.abuse_reports.each do |abuse_report| %>
   <div>
     <strong style="word-wrap: break-word; display: block; padding-right: 40px">"<%= abuse_report.reason %>"</strong> <br />
-    <i><%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_as_sentence(abuse_report.created_at) }%></i> <br />
+    <i><%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_in_words(abuse_report.created_at) }%></i> <br />
     <% if !abuse_report.content.blank? %>
       <button class="display-abuse-report-details" data-report="<%=abuse_report.id%>"><%=_('View details')%></button>
       <div style='display: none' id=<%= 'abuse-report-details-'+abuse_report.id.to_s %> class="abuse-report-details">


=====================================
db/migrate/20150529180110_add_date_format_to_environment.rb
=====================================
--- /dev/null
+++ b/db/migrate/20150529180110_add_date_format_to_environment.rb
@@ -0,0 +1,9 @@
+class AddDateFormatToEnvironment < ActiveRecord::Migration
+  def up
+    add_column :environments, :date_format, :string, :default => 'month_name_with_year'
+  end
+
+  def down
+    remove_column :environments, :date_format
+  end
+end


=====================================
db/schema.rb
=====================================
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -320,17 +320,18 @@ ActiveRecord::Schema.define(:version => 20150602142030) do
     t.text     "design_data"
     t.text     "custom_header"
     t.text     "custom_footer"
-    t.string   "theme",                        :default => "default",           :null => false
+    t.string   "theme",                        :default => "default",              :null => false
     t.text     "terms_of_use_acceptance_text"
     t.datetime "created_at"
     t.datetime "updated_at"
-    t.integer  "reports_lower_bound",          :default => 0,                   :null => false
+    t.integer  "reports_lower_bound",          :default => 0,                      :null => false
     t.string   "redirection_after_login",      :default => "keep_on_same_page"
     t.text     "signup_welcome_text"
     t.string   "languages"
     t.string   "default_language"
     t.string   "noreply_email"
     t.string   "redirection_after_signup",     :default => "keep_on_same_page"
+    t.string   "date_format",                  :default => "month_name_with_year"
   end
 
   create_table "external_feeds", :force => true do |t|


=====================================
plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb
=====================================
--- a/plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb
+++ b/plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb
@@ -13,7 +13,7 @@
     <ul>
     <% @comment.comment_classification_plugin_comment_status_users.each do |relation| %>
       <li>
-        <%= _("<i>%{user}</i> added the status <i>%{status_name}</i> at <i>%{created_at}</i>.") % { :user => relation.profile.name, :status_name => relation.status.name, :created_at => time_ago_as_sentence(relation.created_at)} %>
+        <%= _("<i>%{user}</i> added the status <i>%{status_name}</i> at <i>%{created_at}</i>.") % { :user => relation.profile.name, :status_name => relation.status.name, :created_at => time_ago_in_words(relation.created_at)} %>
         <% unless relation.reason.blank? %>
           <p><%= _("<i>Reason:</i> %s") % relation.reason %></p>
         <% end %>


=====================================
public/stylesheets/application.css
=====================================
--- 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 {


=====================================
test/functional/admin_panel_controller_test.rb
=====================================
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -130,6 +130,19 @@ class AdminPanelControllerTest < ActionController::TestCase
     assert_equal "This <strong>is</strong> my new environment", Environment.default.message_for_disabled_enterprise
   end
 
+  should 'save site article date format option' do
+    post :site_info, :environment => { :date_format => "numbers_with_year" }
+    assert_redirected_to :action => 'index'
+
+    assert_equal "numbers_with_year", Environment.default.date_format
+  end
+
+  should 'dont save site article date format option when a invalid option is passed' do
+    post :site_info, :environment => { :date_format => "invalid_format" }
+
+    assert_not_equal "invalid_format", Environment.default.date_format
+  end
+
   should 'set portal community' do
     e = Environment.default
     @controller.stubs(:environment).returns(e)


=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- 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


=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -262,10 +262,6 @@ module NoosferoTestHelper
     arg
   end
 
-  def show_date(date)
-    date.to_s
-  end
-
   def strip_tags(html)
     html.gsub(/<[^>]+>/, '')
   end


=====================================
test/unit/blog_test.rb
=====================================
--- 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


=====================================
test/unit/content_viewer_helper_test.rb
=====================================
--- a/test/unit/content_viewer_helper_test.rb
+++ b/test/unit/content_viewer_helper_test.rb
@@ -18,7 +18,7 @@ class ContentViewerHelperTest < ActionView::TestCase
     result = article_title(post)
     assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at)
   end
-  
+
   should 'display published-at for forum posts' do
     forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id)
     post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => forum)
@@ -112,6 +112,42 @@ class ContentViewerHelperTest < ActionView::TestCase
     assert_match 'bt-bookmark.gif', addthis_image_tag
   end
 
+  should 'show date with mm/dd/yyyy' do
+    Environment.any_instance.stubs(:date_format).returns('numbers_with_year')
+    article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
+    article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
+    article.save!
+    result = show_with_right_format_date article
+    assert_match /2\/1\/2007/, result
+  end
+
+  should 'show date with mm/dd' do
+    Environment.any_instance.stubs(:date_format).returns('numbers')
+    article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
+    article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
+    article.save!
+    result = show_with_right_format_date article
+    assert_match /2\/1/, result
+  end
+
+  should 'show date with month name' do
+    Environment.any_instance.stubs(:date_format).returns('month_name')
+    article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
+    article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
+    article.save!
+    result = show_with_right_format_date article
+    assert_match /February 1/, result
+  end
+
+  should 'show date with month name and year' do
+    Environment.any_instance.stubs(:date_format).returns('month_name_with_year')
+    article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
+    article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
+    article.save!
+    result = show_with_right_format_date article
+    assert_match /February 1, 2007/, result
+  end
+
   protected
   include NoosferoTestHelper
   include ActionView::Helpers::TextHelper


=====================================
test/unit/dates_helper_test.rb
=====================================
--- a/test/unit/dates_helper_test.rb
+++ b/test/unit/dates_helper_test.rb
@@ -146,4 +146,9 @@ class DatesHelperTest < ActiveSupport::TestCase
     assert_equal Date.new(Date.today.year, Date.today.month, 1), build_date('', '')
   end
 
+  should 'show how long it has passed since a specific date' do
+    date = Time.zone.now
+    assert_equal show_date(date, false, false, true), time_ago_in_words(date)
+  end
+
 end


=====================================
test/unit/environment_test.rb
=====================================
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -1703,4 +1703,32 @@ class EnvironmentTest < ActiveSupport::TestCase
     assert !e.has_license?
   end
 
+  should 'validates_inclusion_of date format' do
+    environment = fast_create(Environment)
+
+    environment.date_format = "invalid_format"
+    environment.valid?
+    assert environment.errors[:date_format.to_s].present?
+
+    environment.date_format = "numbers_with_year"
+    environment.valid?
+    assert !environment.errors[:date_format.to_s].present?
+
+    environment.date_format = "numbers"
+    environment.valid?
+    assert !environment.errors[:date_format.to_s].present?
+
+    environment.date_format = "month_name_with_year"
+    environment.valid?
+    assert !environment.errors[:date_format.to_s].present?
+
+    environment.date_format = "month_name"
+    environment.valid?
+    assert !environment.errors[:date_format.to_s].present?
+
+    environment.date_format = "past_time"
+    environment.valid?
+    assert !environment.errors[:date_format.to_s].present?
+  end
+
 end


=====================================
test/unit/events_helper_test.rb
=====================================
--- a/test/unit/events_helper_test.rb
+++ b/test/unit/events_helper_test.rb
@@ -8,27 +8,13 @@ class EventsHelperTest < ActiveSupport::TestCase
     user = create_user('userwithevents').person
     stubs(:user).returns(user)
 
-    expects(:show_date_month).returns('')
-    expects(:_).with('Events for %s').returns('').once
-    expects(:_).with(' to ').returns('').twice
-    expects(:_).with('Place: ').returns('').twice
-    expects(:_).with('No events for this month').returns('').never
-
-    event1 = mock;
-    event1.expects(:display_to?).with(anything).returns(true).once;
-    event1.expects(:start_date).returns(Date.today).once
-    event1.expects(:end_date).returns(Date.today + 1.day).twice
-    event1.expects(:name).returns('Event 1').once
-    event1.expects(:url).returns({}).once
-    event1.expects(:address).returns('The Shire').times(3)
-
-    event2 = mock;
-    event2.expects(:display_to?).with(anything).returns(true).once
-    event2.expects(:start_date).returns(Date.today).once
-    event2.expects(:end_date).returns(Date.today + 1.day).twice
-    event2.expects(:name).returns('Event 2').once
-    event2.expects(:url).returns({}).once
-    event2.expects(:address).returns('Valfenda').times(3)
+    event1 = Event.new(name: "Event 1", start_date: Date.today, end_date: (Date.today + 1.day), address: 'The Shire')
+    event1.profile = user
+    event1.save
+
+    event2 = Event.new(name: 'Event 2', start_date: Date.today, end_date: (Date.today + 1.day), address: 'Valfenda')
+    event2.profile = user
+    event2.save
 
     result = list_events(Date.today, [event1, event2])
 


=====================================
test/unit/forum_helper_test.rb
=====================================
--- a/test/unit/forum_helper_test.rb
+++ b/test/unit/forum_helper_test.rb
@@ -7,6 +7,7 @@ class ForumHelperTest < ActiveSupport::TestCase
   include ContentViewerHelper
   include ActionView::Helpers::AssetTagHelper
   include ApplicationHelper
+  include ActionView::Helpers::DateHelper
 
   def setup
     @environment = Environment.default
@@ -41,7 +42,7 @@ class ForumHelperTest < ActiveSupport::TestCase
     some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author)
     assert some_post.comments.empty?
     out = last_topic_update(some_post)
-    assert_match some_post.updated_at.to_s, out
+    assert_match time_ago_in_words(some_post.updated_at), out
     assert_match /forum test author/, out
   end
 
@@ -53,10 +54,11 @@ class ForumHelperTest < ActiveSupport::TestCase
     c = Comment.last
     assert_equal 2, some_post.comments.count
     out = last_topic_update(some_post)
-    assert_match c.created_at.to_s, out
+    result = time_ago_in_words(c.created_at)
+    assert_match result, out
     assert_match 'a2', out
 
-    assert_match(/#{Regexp.escape(c.created_at.to_s)} by <a href='[^']+'>a2<\/a>/, last_topic_update(some_post))
+    assert_match(/#{result} by <a href='[^']+'>a2<\/a>/, last_topic_update(some_post))
   end
 
   should "return last comment author's name from unauthenticated user" do
@@ -64,18 +66,15 @@ class ForumHelperTest < ActiveSupport::TestCase
     some_post.comments << build(Comment, :name => 'John', :email => 'lenon at example.com', :title => 'test', :body => 'test')
     c = Comment.last
     out = last_topic_update(some_post)
-    assert_match "#{c.created_at.to_s} by John", out
+    result = time_ago_in_words(c.created_at)
+    assert_match "#{result} by John", out
     assert_match 'John', out
 
-    assert_match(/#{Regexp.escape(c.created_at.to_s)} by John/m, last_topic_update(some_post))
+    assert_match(/#{result} by John/m, last_topic_update(some_post))
   end
 
   protected
 
   include NoosferoTestHelper
 
-  def time_ago_as_sentence(t = Time.now)
-    t.to_s
-  end
-
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/a349d8fa8307c5f07d04caf8775d1b34e3b94fbf...dbea884758ec0f30bf505426815867cce32767c0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150612/afb00586/attachment-0001.html>


More information about the Noosfero-dev mailing list