From dbea884758ec0f30bf505426815867cce32767c0 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Fri, 12 Jun 2015 12:24:12 +0000 Subject: [PATCH] Refactor deprecated code for date to use rails method --- app/helpers/application_helper.rb | 29 ----------------------------- app/helpers/blog_helper.rb | 1 - app/helpers/comment_helper.rb | 1 + app/helpers/events_helper.rb | 1 + app/helpers/forum_helper.rb | 5 +++-- app/views/person_notifier/mailer/_comment.html.erb | 2 +- app/views/person_notifier/mailer/_create_article.html.erb | 2 +- app/views/person_notifier/mailer/_default_activity.html.erb | 2 +- app/views/person_notifier/mailer/_task.html.erb | 2 +- app/views/person_notifier/mailer/_upload_image.html.erb | 2 +- app/views/profile/_comment.html.erb | 2 +- app/views/profile/_create_article.html.erb | 2 +- app/views/profile/_default_activity.html.erb | 2 +- app/views/profile/_leave_scrap.html.erb | 2 +- app/views/profile/_profile_scrap.html.erb | 4 ++-- app/views/profile/_profile_scraps.html.erb | 2 +- app/views/profile/_upload_image.html.erb | 2 +- app/views/tasks/_abuse_complaint_accept_details.html.erb | 2 +- plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb | 2 +- test/functional/admin_panel_controller_test.rb | 3 +-- test/unit/events_helper_test.rb | 28 +++++++--------------------- test/unit/forum_helper_test.rb | 17 ++++++++--------- 22 files changed, 36 insertions(+), 79 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c31efdf..2a181fd 100644 --- 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}") } diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index aa08107..a185502 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -2,7 +2,6 @@ module BlogHelper include ArticleHelper - def custom_options_for_article(article,tokenized_children) @article = article hidden_field_tag('article[published]', 1) + diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index 9b93e8c..c8e780a 100644 --- 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 diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 3b66568..c71ef3f 100644 --- 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) + diff --git a/app/helpers/forum_helper.rb b/app/helpers/forum_helper.rb index 7d8bd24..a82d2dc 100644 --- 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 diff --git a/app/views/person_notifier/mailer/_comment.html.erb b/app/views/person_notifier/mailer/_comment.html.erb index 89f3512..435006b 100644 --- a/app/views/person_notifier/mailer/_comment.html.erb +++ b/app/views/person_notifier/mailer/_comment.html.erb @@ -19,7 +19,7 @@ <%= comment.title %>
<% end %> <%= txt2html comment.body %>
- <%= time_ago_as_sentence(comment.created_at) %> + <%= time_ago_in_words(comment.created_at) %>
<% unless comment.replies.blank? %> diff --git a/app/views/person_notifier/mailer/_create_article.html.erb b/app/views/person_notifier/mailer/_create_article.html.erb index 1cf53e9..d514e4b 100644 --- a/app/views/person_notifier/mailer/_create_article.html.erb +++ b/app/views/person_notifier/mailer/_create_article.html.erb @@ -6,7 +6,7 @@

<%= link_to activity.user.short_name(20), activity.user.url %> <%= _("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) %> - <%= time_ago_as_sentence(activity.created_at) %> + <%= time_ago_in_words(activity.created_at) %>

<%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %> diff --git a/app/views/person_notifier/mailer/_default_activity.html.erb b/app/views/person_notifier/mailer/_default_activity.html.erb index 135e10b..c1bd5c1 100644 --- a/app/views/person_notifier/mailer/_default_activity.html.erb +++ b/app/views/person_notifier/mailer/_default_activity.html.erb @@ -5,7 +5,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %> - <%= time_ago_as_sentence(activity.created_at) %> + <%= time_ago_in_words(activity.created_at) %>

diff --git a/app/views/person_notifier/mailer/_task.html.erb b/app/views/person_notifier/mailer/_task.html.erb index ddafbe3..487341e 100644 --- a/app/views/person_notifier/mailer/_task.html.erb +++ b/app/views/person_notifier/mailer/_task.html.erb @@ -12,7 +12,7 @@ <%= task_information(task) %> - <%= time_ago_as_sentence(task.created_at) %> + <%= time_ago_in_words(task.created_at) %> diff --git a/app/views/person_notifier/mailer/_upload_image.html.erb b/app/views/person_notifier/mailer/_upload_image.html.erb index c17cd6e..16cb6ce 100644 --- a/app/views/person_notifier/mailer/_upload_image.html.erb +++ b/app/views/person_notifier/mailer/_upload_image.html.erb @@ -5,7 +5,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %> - <%= time_ago_as_sentence(activity.created_at) %> + <%= time_ago_in_words(activity.created_at) %>

diff --git a/app/views/profile/_comment.html.erb b/app/views/profile/_comment.html.erb index e034399..ea88c7b 100644 --- a/app/views/profile/_comment.html.erb +++ b/app/views/profile/_comment.html.erb @@ -40,7 +40,7 @@ <%= txt2html comment.body %>
- <%= time_ago_as_sentence(comment.created_at) %> + <%= time_ago_in_words(comment.created_at) %>
diff --git a/app/views/profile/_create_article.html.erb b/app/views/profile/_create_article.html.erb index 8385a5d..a4cdc1f 100644 --- 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? %> <%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %> <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %> -

<%= time_ago_as_sentence(activity.created_at) %>

+

<%= time_ago_in_words(activity.created_at) %>

<%= 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 %> diff --git a/app/views/profile/_default_activity.html.erb b/app/views/profile/_default_activity.html.erb index 6a9d342..51ee36c 100644 --- a/app/views/profile/_default_activity.html.erb +++ b/app/views/profile/_default_activity.html.erb @@ -3,7 +3,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence(activity.created_at) %>

+

<%= time_ago_in_words(activity.created_at) %>

<%= 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 %> diff --git a/app/views/profile/_leave_scrap.html.erb b/app/views/profile/_leave_scrap.html.erb index 8ef4313..121dd77 100644 --- a/app/views/profile/_leave_scrap.html.erb +++ b/app/views/profile/_leave_scrap.html.erb @@ -3,7 +3,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence(activity.created_at) %>

+

<%= time_ago_in_words(activity.created_at) %>

<%= 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 %>
diff --git a/app/views/profile/_profile_scrap.html.erb b/app/views/profile/_profile_scrap.html.erb index a7d6113..69140ee 100644 --- a/app/views/profile/_profile_scrap.html.erb +++ b/app/views/profile/_profile_scrap.html.erb @@ -5,7 +5,7 @@

<%= link_to scrap.sender.name, scrap.sender.url %>

<%= txt2html scrap.content %>

-

<%= time_ago_as_sentence(scrap.created_at) %>

+

<%= time_ago_in_words(scrap.created_at) %>

<% if logged_in? && current_person.follows?(scrap.sender) %> @@ -22,5 +22,5 @@ <% end %> <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %> -
+
diff --git a/app/views/profile/_profile_scraps.html.erb b/app/views/profile/_profile_scraps.html.erb index f38f898..e4ebf33 100644 --- a/app/views/profile/_profile_scraps.html.erb +++ b/app/views/profile/_profile_scraps.html.erb @@ -5,7 +5,7 @@

<%= link_to scrap.sender.name, scrap.sender.url %>

<%= txt2html scrap.content %>

-

<%= time_ago_as_sentence(scrap.created_at) %>

+

<%= time_ago_in_words(scrap.created_at) %>

<% if logged_in? && current_person.follows?(scrap.sender) %> diff --git a/app/views/profile/_upload_image.html.erb b/app/views/profile/_upload_image.html.erb index 247e310..ec460d5 100644 --- a/app/views/profile/_upload_image.html.erb +++ b/app/views/profile/_upload_image.html.erb @@ -4,7 +4,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

-

<%= time_ago_as_sentence(activity.created_at) %>

+

<%= time_ago_in_words(activity.created_at) %>

<%= 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 %>
diff --git a/app/views/tasks/_abuse_complaint_accept_details.html.erb b/app/views/tasks/_abuse_complaint_accept_details.html.erb index 0f678fa..9c3f03f 100644 --- 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| %>
"<%= abuse_report.reason %>"
- <%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_as_sentence(abuse_report.created_at) }%>
+ <%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_in_words(abuse_report.created_at) }%>
<% if !abuse_report.content.blank? %>