Class: DateLabelHelper::GenericDateView
- Inherits:
-
Object
- Object
- DateLabelHelper::GenericDateView
show all
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- app/helpers/date_label_helper.rb
Constant Summary
collapse
- COLORS =
{
:overdue_by_more_than_one => :red,
:overdue_by_one => :red,
:today => :amber,
:tomorrow => :amber,
:this_week => :orange,
:more_than_a_week => :green
}.freeze
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GenericDateView.
15
16
17
18
19
20
|
# File 'app/helpers/date_label_helper.rb', line 15
def initialize(date, prefs)
@date = date
@days = date.nil? ? nil : days_from_today(date)
@days_sym = days_to_sym(@days)
@prefs = prefs
end
|
Instance Method Details
#date_html_wrapper ⇒ Object
51
52
53
54
55
56
57
|
# File 'app/helpers/date_label_helper.rb', line 51
def date_html_wrapper
return "" if @date.nil?
return content_tag(:a, { :title => @prefs.format_date(@date) }) {
content_tag(:span, { :class => get_color }) { yield }
}
end
|
#date_mobile_html_wrapper ⇒ Object
59
60
61
62
63
|
# File 'app/helpers/date_label_helper.rb', line 59
def date_mobile_html_wrapper
return "" if @date.nil?
return content_tag(:span, { :class => get_color }) { yield }
end
|
#days_from_today(date) ⇒ Object
26
27
28
|
# File 'app/helpers/date_label_helper.rb', line 26
def days_from_today(date)
(date.in_time_zone.to_date - Date.current).to_i
end
|
#days_to_sym(days) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/helpers/date_label_helper.rb', line 30
def days_to_sym(days)
case days
when nil
return nil
when 0
return :today
when 1
return :tomorrow
when 2..7
return :this_week
else
if days == -1
return :overdue_by_one
elsif days < -1
return :overdue_by_more_than_one
else
return :more_than_a_week
end
end
end
|
#get_color ⇒ Object
22
23
24
|
# File 'app/helpers/date_label_helper.rb', line 22
def get_color
COLORS[@days_sym]
end
|