Class: SimpleCalendar::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_calendar/calendar.rb

Direct Known Subclasses

MonthCalendar, WeekCalendar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context, opts = {}) ⇒ Calendar

Returns a new instance of Calendar.



7
8
9
10
# File 'lib/simple_calendar/calendar.rb', line 7

def initialize(view_context, opts={})
  @view_context = view_context
  @options = opts
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/simple_calendar/calendar.rb', line 5

def options
  @options
end

#view_contextObject

Returns the value of attribute view_context.



5
6
7
# File 'lib/simple_calendar/calendar.rb', line 5

def view_context
  @view_context
end

Instance Method Details

#render(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simple_calendar/calendar.rb', line 12

def render(&block)
  view_context.render(
    partial: partial_name,
    locals: {
      block: block,
      calendar: self,
      date_range: date_range,
      start_date: start_date,
      sorted_events: sorted_events
    }
  )
end

#td_classes_for(day) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simple_calendar/calendar.rb', line 25

def td_classes_for(day)
  today = Time.zone.now.to_date

  td_class = ["day"]
  td_class << "wday-#{day.wday.to_s}"
  td_class << "today"         if today == day
  td_class << "past"          if today > day
  td_class << "future"        if today < day
  td_class << 'start-date'    if day.to_date == start_date.to_date
  td_class << "prev-month"    if start_date.month != day.month && day < start_date
  td_class << "next-month"    if start_date.month != day.month && day > start_date
  td_class << "current-month" if start_date.month == day.month
  td_class << "has-events"    if sorted_events.fetch(day, []).any?

  td_class
end