Class: BootstrapCalendarHelper::BootstrapCalendar

Inherits:
Struct
  • Object
show all
Defined in:
app/helpers/bootstrap_calendar_helper.rb

Constant Summary collapse

HEADER =
%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
START_DAY =
:sunday

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callbackObject

Returns the value of attribute callback

Returns:

  • (Object)

    the current value of callback



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

def callback
  @callback
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



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

def date
  @date
end

#viewObject

Returns the value of attribute view

Returns:

  • (Object)

    the current value of view



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

def view
  @view
end

Instance Method Details

#calendar_divObject



12
13
14
15
16
# File 'app/helpers/bootstrap_calendar_helper.rb', line 12

def calendar_div
   'div', class: "calendar_grid" do
    header + week_rows
  end
end

#day_cell(day) ⇒ Object



34
35
36
# File 'app/helpers/bootstrap_calendar_helper.rb', line 34

def day_cell(day)
   :div, view.capture(day, &callback), class: day_classes(day)
end

#day_classes(day) ⇒ Object



38
39
40
41
42
43
44
# File 'app/helpers/bootstrap_calendar_helper.rb', line 38

def day_classes(day)
  classes = ['span1']
  classes << "today" if day == Date.today
  classes << "notmonth" if day.month != date.month
  classes << "month" if day.month == date.month
  classes.empty? ? nil : classes.join(" ")
end

#headerObject



18
19
20
21
22
23
24
# File 'app/helpers/bootstrap_calendar_helper.rb', line 18

def header
   'div', class: 'month_header row-fluid' do
    HEADER.map { |day|  :div, class: 'span1' do
      day
    end }.join.html_safe
  end
end

#week_rowsObject



26
27
28
29
30
31
32
# File 'app/helpers/bootstrap_calendar_helper.rb', line 26

def week_rows
  weeks.map {|week|
     :div, class: 'row-fluid week' do
      week.map { |day| day_cell(day) }.join.html_safe
    end
  }.join.html_safe
end

#weeksObject



46
47
48
49
50
# File 'app/helpers/bootstrap_calendar_helper.rb', line 46

def weeks
  first = date.beginning_of_month.beginning_of_week(START_DAY)
  last = date.end_of_month.end_of_week(START_DAY)
  (first..last).to_a.in_groups_of(7)
end