Module: SimpleCalendarJuliusRobertOppenheimer::ViewHelpers
- Defined in:
- lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb
Instance Method Summary collapse
- #body(day, events, block) ⇒ Object
- #calendar(events, &block) ⇒ Object
- #day(date, events, block) ⇒ Object
- #day_events(date, events) ⇒ Object
- #day_header ⇒ Object
- #end_date(date) ⇒ Object
- #month_header(day) ⇒ Object
- #start_date(date) ⇒ Object
Instance Method Details
#body(day, events, block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 43 def body(day, events, block) current_date = start_date(day).dup content_tag :tbody do weeks = [] while current_date < end_date(day) weeks << content_tag(:tr) do = [] while not current_date.saturday? << day(current_date, events, block) current_date = current_date.tomorrow end << day(current_date, events, block) current_date = current_date.tomorrow .join.html_safe end end weeks.join.html_safe end end |
#calendar(events, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 3 def calendar(events, &block) day = Date.civil((params[:year] || Time.zone.now.year).to_i, (params[:month] || Time.zone.now.month).to_i) content_tag :table, :class => "bordered-table calendar" do month_header(day) + day_header + body(day, events, block) end end |
#day(date, events, block) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 64 def day(date, events, block) content_tag :td do concat content_tag(:div, date.day, :class => "day") day_events(date, events).map do |event| block.call(event) end.join.html_safe end end |
#day_events(date, events) ⇒ Object
74 75 76 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 74 def day_events(date, events) events.select { |e| e.start_time_column.to_date == date } end |
#day_header ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 35 def day_header content_tag :thead do content_tag :tr do I18n.t(:"date.abbr_day_names").map{ |day| content_tag :th, day }.join.html_safe end end end |
#end_date(date) ⇒ Object
17 18 19 20 21 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 17 def end_date(date) end_date = date.end_of_month end_date = end_date.advance(:days => 1).end_of_week if end_date.sunday? end_date end |
#month_header(day) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 23 def month_header(day) content_tag :h2 do previous_month = day.advance :months => -1 next_month = day.advance :months => 1 = [] << link_to("<", request.fullpath.split('?').first + "?month=#{previous_month.month}&year=#{previous_month.year}") << day.strftime("%B %Y") << link_to(">", request.fullpath.split('?').first + "?month=#{next_month.month}&year=#{next_month.year}") .join.html_safe end end |
#start_date(date) ⇒ Object
11 12 13 14 15 |
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 11 def start_date(date) start_date = date.beginning_of_month start_date = start_date.beginning_of_week.advance(:days => -1) unless start_date.sunday? start_date end |