Module: SimpleCalendarJuliusRobertOppenheimer::ViewHelpers

Defined in:
lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb

Instance Method Summary collapse

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

   :tbody do
    weeks = []
    while current_date < end_date(day)
      weeks << (:tr) do
        tags = []
        while not current_date.saturday?
          tags << day(current_date, events, block)
          current_date = current_date.tomorrow
        end
        tags << day(current_date, events, block)
        current_date = current_date.tomorrow
        tags.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)

   :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)
   :td do
    concat (: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_headerObject



35
36
37
38
39
40
41
# File 'lib/simple_calendar_julius_robert_oppenheimer/view_helpers.rb', line 35

def day_header
   :thead do
     :tr do
      I18n.t(:"date.abbr_day_names").map{ |day|  :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)
   :h2 do
    previous_month = day.advance :months => -1
    next_month = day.advance :months => 1
    tags = []
    tags << link_to("<", request.fullpath.split('?').first + "?month=#{previous_month.month}&year=#{previous_month.year}")
    tags << day.strftime("%B %Y")
    tags << link_to(">", request.fullpath.split('?').first + "?month=#{next_month.month}&year=#{next_month.year}")
    tags.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