diff --git a/plugins/event/lib/event_block_helper.rb b/plugins/event/lib/event_block_helper.rb deleted file mode 100644 index 690c0f9..0000000 --- a/plugins/event/lib/event_block_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -module EventBlockHelper - include DatesHelper - - def date_to_html(date) - content_tag(:span, show_day_of_week(date, true), :class => 'week-day') + - content_tag(:span, month_name(date.month, true), :class => 'month') + - content_tag(:span, date.day.to_s, :class => 'day') + - content_tag(:span, date.year.to_s, :class => 'year') - end -end diff --git a/plugins/event/lib/event_plugin/event_block.rb b/plugins/event/lib/event_plugin/event_block.rb index 43f9313..a750b57 100644 --- a/plugins/event/lib/event_plugin/event_block.rb +++ b/plugins/event/lib/event_plugin/event_block.rb @@ -47,21 +47,6 @@ class EventPlugin::EventBlock < Block event_list end - def human_time_left(days_left) - months_left = (days_left/30.0).round - if days_left <= -60 - n_('One month ago', '%d months ago', -months_left) % -months_left - elsif days_left < 0 - n_('Yesterday', '%d days ago', -days_left) % -days_left - elsif days_left == 0 - _("Today") - elsif days_left < 60 - n_('Tomorrow', '%d days left to start', days_left) % days_left - else - n_('One month left to start', '%d months left to start', months_left) % months_left - end - end - def self.expire_on { :profile => [:article], :environment => [:article] } end diff --git a/plugins/event/lib/event_plugin/event_block_helper.rb b/plugins/event/lib/event_plugin/event_block_helper.rb new file mode 100644 index 0000000..7cef76d --- /dev/null +++ b/plugins/event/lib/event_plugin/event_block_helper.rb @@ -0,0 +1,25 @@ +module EventPlugin::EventBlockHelper + include DatesHelper + + def date_to_html(date) + content_tag(:span, show_day_of_week(date, true), :class => 'week-day') + + content_tag(:span, month_name(date.month, true), :class => 'month') + + content_tag(:span, date.day.to_s, :class => 'day') + + content_tag(:span, date.year.to_s, :class => 'year') + end + + def human_time_left(days_left) + months_left = (days_left/30.0).round + if days_left <= -60 + n_('One month ago', '%d months ago', -months_left) % -months_left + elsif days_left < 0 + n_('Yesterday', '%d days ago', -days_left) % -days_left + elsif days_left == 0 + _("Today") + elsif days_left < 60 + n_('Tomorrow', '%d days left to start', days_left) % days_left + else + n_('One month left to start', '%d months left to start', months_left) % months_left + end + end +end diff --git a/plugins/event/test/unit/event_block_helper_test.rb b/plugins/event/test/unit/event_block_helper_test.rb index 3141ea6..ed51dd6 100644 --- a/plugins/event/test/unit/event_block_helper_test.rb +++ b/plugins/event/test/unit/event_block_helper_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class EventBlockHelperTest < ActionView::TestCase - include EventBlockHelper + include EventPlugin::EventBlockHelper should 'write formatable data in html' do html = 'Tue'+ @@ -11,4 +11,24 @@ class EventBlockHelperTest < ActionView::TestCase assert_equal html, date_to_html(Date.new 1983, 9, 27) end + + should 'say human left time for an event' do + assert_match /Tomorrow/, human_time_left(1) + assert_match /5 days left/, human_time_left(5) + assert_match /30 days left/, human_time_left(30) + assert_match /2 months left/, human_time_left(60) + assert_match /3 months left/, human_time_left(85) + end + + should 'say human past time for an event' do + assert_match /Yesterday/, human_time_left(-1) + assert_match /5 days ago/, human_time_left(-5) + assert_match /30 days ago/, human_time_left(-30) + assert_match /2 months ago/, human_time_left(-60) + assert_match /3 months ago/, human_time_left(-85) + end + + should 'say human present time for an event' do + assert_match /Today/, human_time_left(0) + end end diff --git a/plugins/event/test/unit/event_block_test.rb b/plugins/event/test/unit/event_block_test.rb index cb80e3c..c8f0997 100644 --- a/plugins/event/test/unit/event_block_test.rb +++ b/plugins/event/test/unit/event_block_test.rb @@ -77,26 +77,6 @@ class EventBlockTest < ActiveSupport::TestCase assert_equal 2, @block.events.length end - should 'say human left time for an event' do - assert_match /Tomorrow/, @block.human_time_left(1) - assert_match /5 days left/, @block.human_time_left(5) - assert_match /30 days left/, @block.human_time_left(30) - assert_match /2 months left/, @block.human_time_left(60) - assert_match /3 months left/, @block.human_time_left(85) - end - - should 'say human past time for an event' do - assert_match /Yesterday/, @block.human_time_left(-1) - assert_match /5 days ago/, @block.human_time_left(-5) - assert_match /30 days ago/, @block.human_time_left(-30) - assert_match /2 months ago/, @block.human_time_left(-60) - assert_match /3 months ago/, @block.human_time_left(-85) - end - - should 'say human present time for an event' do - assert_match /Today/, @block.human_time_left(0) - end - should 'show unlimited time distance events' do @block.box.owner = @env @block.all_env_events = true diff --git a/plugins/event/views/blocks/event.html.erb b/plugins/event/views/blocks/event.html.erb index 5824f49..eda175b 100644 --- a/plugins/event/views/blocks/event.html.erb +++ b/plugins/event/views/blocks/event.html.erb @@ -1,3 +1,5 @@ +<% extend EventPlugin::EventBlockHelper %> + <%= block_title(block.title, block.subtitle) %>