Module: EventsHelper

Defined in:
app/helpers/events_helper.rb

Instance Method Summary collapse

Instance Method Details

#date(d) ⇒ Object



6
7
8
# File 'app/helpers/events_helper.rb', line 6

def date(d)
  I18n.localize(d, :format => "%B %d, %Y")
end

#datetime(d) ⇒ Object



2
3
4
# File 'app/helpers/events_helper.rb', line 2

def datetime(d)
  I18n.localize(d, :format => "%B %d, %Y %l:%M %p")
end

#event_calendar(calendar) ⇒ Object



43
44
45
46
47
48
49
50
# File 'app/helpers/events_helper.rb', line 43

def event_calendar(calendar)
  # args is an argument hash containing :event, :day, and :options
  calendar event_calendar_opts(calendar) do |args|
    event = args[:event]
    title = event.all_day?? h(event.title) : timed_title(event)
    link_to(title, event_path(event))
  end
end

#event_calendar_opts(calendar) ⇒ Object

custom options for this calendar



19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/events_helper.rb', line 19

def event_calendar_opts(calendar)
  { 
    :year => @calendar.year,
    :month => @calendar.month,
    :event_strips => @calendar.event_strips,
    :month_name_text => I18n.localize(@calendar.date, :format => "%B %Y"),
    :previous_month_text => month_link(@calendar.date.last_month),
    :next_month_text => month_link(@calendar.date.next_month),
    :use_all_day => true
  }
end

#event_list(options = Hash.new) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/events_helper.rb', line 52

def event_list(options = Hash.new)
  grouped_events = Event.
    all(:limit => options.fetch(:limit) { 10 }, :order => 'start_at ASC',
        :conditions => [ 'start_at >= ? OR end_at >= ?', Time.now, Time.now ]).
    group_by { |e| e.start_at.to_date }

  render(:partial => '/events/event_list',
         :object => grouped_events,
         :locals => { :heading => options[:heading],
                      :see_more_link => options.fetch(:see_more_link) { 'View the calendar' } } )
end

#event_title(event) ⇒ Object



35
36
37
38
39
40
41
# File 'app/helpers/events_helper.rb', line 35

def event_title(event)
  if event.all_day?
    h(event.title)
  else
    timed_title(event)
  end
end


14
15
16
# File 'app/helpers/events_helper.rb', line 14

def month_link(date)
  link_to(I18n.localize(date, :format => "%B"), {:date => date})
end

#time(d) ⇒ Object



10
11
12
# File 'app/helpers/events_helper.rb', line 10

def time(d)
  I18n.localize(d, :format => "%l:%M%p")
end

#timed_title(event) ⇒ Object



31
32
33
# File 'app/helpers/events_helper.rb', line 31

def timed_title(event)
  "#{time(event.start_at)} #{h(event.title)}"
end