Commit 9a7f4e8eba3e13d53c9def7263a112ec16db92fb
1 parent
fa17838c
Exists in
ratings_minor_fixes
and in
4 other branches
Refactor EventBlock#date_to_html into a helper
This removes some HTML generation from the model class.
Showing
5 changed files
with
27 additions
and
19 deletions
Show diff stats
... | ... | @@ -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 | 1 | class EventPlugin::EventBlock < Block |
2 | - include DatesHelper | |
3 | - | |
4 | 2 | attr_accessible :all_env_events, :limit, :future_only, :date_distance_limit |
5 | 3 | |
6 | 4 | settings_items :all_env_events, :type => :boolean, :default => false |
... | ... | @@ -74,13 +72,6 @@ class EventPlugin::EventBlock < Block |
74 | 72 | end |
75 | 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 | 75 | def self.expire_on |
85 | 76 | { :profile => [:article], :environment => [:article] } |
86 | 77 | end | ... | ... |
... | ... | @@ -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 < ActiveSupport::TestCase |
97 | 97 | assert_match /Today/, @block.human_time_left(0) |
98 | 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 | 100 | should 'show unlimited time distance events' do |
110 | 101 | @block.box.owner = @env |
111 | 102 | @block.all_env_events = true | ... | ... |
plugins/event/views/event_plugin/event_block_item.html.erb
1 | 1 | <% |
2 | + extend EventBlockHelper | |
3 | + | |
2 | 4 | # compute layout values |
3 | 5 | ev_days_tag = '' |
4 | 6 | if event.duration > 1 |
... | ... | @@ -18,7 +20,7 @@ |
18 | 20 | <%= |
19 | 21 | link_to(safe_join([ |
20 | 22 | content_tag('time', |
21 | - block.date_to_html(event.start_date), | |
23 | + date_to_html(event.start_date), | |
22 | 24 | :itemprop => 'startDate', |
23 | 25 | :datetime => show_date(event.start_date), |
24 | 26 | :class => 'date ' + img_class, :style => bg, | ... | ... |