Class: CalendarHelper::Calendar
- Inherits:
-
Struct
- Object
- Struct
- CalendarHelper::Calendar
- Defined in:
- app/helpers/calendar_helper.rb
Constant Summary collapse
- HEADER =
HEADER = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
[%w(Sun Mon Tue Wed Thu Fri Sat)].freeze
- START_DAY =
:sunday
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#date ⇒ Object
Returns the value of attribute date.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
- #day_cell(day) ⇒ Object
- #day_classes(day) ⇒ Object
- #header ⇒ Object
- #table ⇒ Object
- #week_rows ⇒ Object
- #weeks ⇒ Object
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback
8 9 10 |
# File 'app/helpers/calendar_helper.rb', line 8 def callback @callback end |
#date ⇒ Object
Returns the value of attribute date
8 9 10 |
# File 'app/helpers/calendar_helper.rb', line 8 def date @date end |
#view ⇒ Object
Returns the value of attribute view
8 9 10 |
# File 'app/helpers/calendar_helper.rb', line 8 def view @view end |
Instance Method Details
#day_cell(day) ⇒ Object
35 36 37 |
# File 'app/helpers/calendar_helper.rb', line 35 def day_cell(day) content_tag :td, view.capture(day, &callback), class: day_classes(day) end |
#day_classes(day) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/helpers/calendar_helper.rb', line 39 def day_classes(day) classes = [] # classes << "today" if day == Time.zone.today # classes << "today" if day == Time.zone.today or day == @date.day classes << 'notmonth' if day.month != date.month classes.empty? ? nil : classes.join(' ') end |
#header ⇒ Object
21 22 23 24 25 |
# File 'app/helpers/calendar_helper.rb', line 21 def header content_tag :tr do HEADER.map { |day| content_tag :th, day }.join.html_safe end end |
#table ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/calendar_helper.rb', line 15 def table content_tag :table, class: 'calendar' do header + week_rows end end |
#week_rows ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/helpers/calendar_helper.rb', line 27 def week_rows weeks.map do |week| content_tag :tr do week.map { |day| day_cell(day) }.join.html_safe end end.join.html_safe end |