Commit 9a7f4e8eba3e13d53c9def7263a112ec16db92fb

Authored by Rafael Reggiani Manzo
1 parent fa17838c

Refactor EventBlock#date_to_html into a helper

This removes some HTML generation from the model class.
plugins/event/lib/event_block_helper.rb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +module EventBlockHelper
  2 + include DatesHelper
  3 +
  4 + def date_to_html(date)
  5 + content_tag(:span, show_day_of_week(date, true), :class => 'week-day') +
  6 + content_tag(:span, month_name(date.month, true), :class => 'month') +
  7 + content_tag(:span, date.day.to_s, :class => 'day') +
  8 + content_tag(:span, date.year.to_s, :class => 'year')
  9 + end
  10 +end
plugins/event/lib/event_plugin/event_block.rb
1 class EventPlugin::EventBlock < Block 1 class EventPlugin::EventBlock < Block
2 - include DatesHelper  
3 -  
4 attr_accessible :all_env_events, :limit, :future_only, :date_distance_limit 2 attr_accessible :all_env_events, :limit, :future_only, :date_distance_limit
5 3
6 settings_items :all_env_events, :type => :boolean, :default => false 4 settings_items :all_env_events, :type => :boolean, :default => false
@@ -74,13 +72,6 @@ class EventPlugin::EventBlock &lt; Block @@ -74,13 +72,6 @@ class EventPlugin::EventBlock &lt; Block
74 end 72 end
75 end 73 end
76 74
77 - def date_to_html(date)  
78 - content_tag(:span, show_day_of_week(date, true), :class => 'week-day') +  
79 - content_tag(:span, month_name(date.month, true), :class => 'month') +  
80 - content_tag(:span, date.day.to_s, :class => 'day') +  
81 - content_tag(:span, date.year.to_s, :class => 'year')  
82 - end  
83 -  
84 def self.expire_on 75 def self.expire_on
85 { :profile => [:article], :environment => [:article] } 76 { :profile => [:article], :environment => [:article] }
86 end 77 end
plugins/event/test/unit/event_block_helper_test.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +require 'test_helper'
  2 +
  3 +class EventBlockHelperTest < ActionView::TestCase
  4 + include EventBlockHelper
  5 +
  6 + should 'write formatable data in html' do
  7 + html = '<span class="week-day">Tue</span>'+
  8 + '<span class="month">Sep</span>'+
  9 + '<span class="day">27</span>'+
  10 + '<span class="year">1983</span>'
  11 +
  12 + assert_equal html, date_to_html(Date.new 1983, 9, 27)
  13 + end
  14 +end
plugins/event/test/unit/event_block_test.rb
@@ -97,15 +97,6 @@ class EventBlockTest &lt; ActiveSupport::TestCase @@ -97,15 +97,6 @@ class EventBlockTest &lt; ActiveSupport::TestCase
97 assert_match /Today/, @block.human_time_left(0) 97 assert_match /Today/, @block.human_time_left(0)
98 end 98 end
99 99
100 - should 'write formatable data in html' do  
101 - html = '<span class="week-day">Tue</span>'+  
102 - '<span class="month">Sep</span>'+  
103 - '<span class="day">27</span>'+  
104 - '<span class="year">1983</span>'  
105 -  
106 - assert_equal html, @block.date_to_html(Date.new 1983, 9, 27)  
107 - end  
108 -  
109 should 'show unlimited time distance events' do 100 should 'show unlimited time distance events' do
110 @block.box.owner = @env 101 @block.box.owner = @env
111 @block.all_env_events = true 102 @block.all_env_events = true
plugins/event/views/event_plugin/event_block_item.html.erb
1 <% 1 <%
  2 + extend EventBlockHelper
  3 +
2 # compute layout values 4 # compute layout values
3 ev_days_tag = '' 5 ev_days_tag = ''
4 if event.duration > 1 6 if event.duration > 1
@@ -18,7 +20,7 @@ @@ -18,7 +20,7 @@
18 <%= 20 <%=
19 link_to(safe_join([ 21 link_to(safe_join([
20 content_tag('time', 22 content_tag('time',
21 - block.date_to_html(event.start_date), 23 + date_to_html(event.start_date),
22 :itemprop => 'startDate', 24 :itemprop => 'startDate',
23 :datetime => show_date(event.start_date), 25 :datetime => show_date(event.start_date),
24 :class => 'date ' + img_class, :style => bg, 26 :class => 'date ' + img_class, :style => bg,