Class: Twitter::Bootstrap::Calendar::BootstrapCalendar
- Inherits:
-
Object
- Object
- Twitter::Bootstrap::Calendar::BootstrapCalendar
- Defined in:
- lib/twitter/bootstrap/calendar/bootstrap_calendar.rb
Constant Summary collapse
- DAY_NAMES =
%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]- MOBILE_DAY_NAMES =
%w[Sun Mon Tues Wed Thur Fri Sat]- START_DAY =
:sunday
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #calendar_div ⇒ Object
- #content_tag(*args, &block) ⇒ Object
- #day_cell(day) ⇒ Object
- #day_classes(day) ⇒ Object
- #day_names ⇒ Object
- #header ⇒ Object
-
#initialize(view, date, options = {}, callback) ⇒ BootstrapCalendar
constructor
A new instance of BootstrapCalendar.
- #mobile_day_names ⇒ Object
- #start_day ⇒ Object
- #start_day_index ⇒ Object
- #week_rows ⇒ Object
- #weeks ⇒ Object
Constructor Details
#initialize(view, date, options = {}, callback) ⇒ BootstrapCalendar
Returns a new instance of BootstrapCalendar.
16 17 18 19 20 21 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 16 def initialize(view, date, ={}, callback) @view = view @date = date = .symbolize_keys @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
10 11 12 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 10 def callback @callback end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 10 def date @date end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 10 def end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
10 11 12 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 10 def view @view end |
Instance Method Details
#calendar_div ⇒ Object
28 29 30 31 32 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 28 def calendar_div content_tag 'div', class: "calendar_grid" do header + week_rows end end |
#content_tag(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 12 def content_tag *args, &block view.content_tag(*args, &block) end |
#day_cell(day) ⇒ Object
73 74 75 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 73 def day_cell(day) content_tag :div, view.capture(day, &callback), class: day_classes(day) end |
#day_classes(day) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 77 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 |
#day_names ⇒ Object
38 39 40 41 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 38 def day_names return DAY_NAMES if start_day_index.zero? DAY_NAMES[start_day_index, DAY_NAMES.size - start_day_index] + DAY_NAMES[0, start_day_index] end |
#header ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 48 def header content_tag 'div', class: 'month_header row-fluid' do standard = day_names.map { |day| content_tag :div, class: 'span1 visible-desktop' do I18n.t(day.downcase) end }.join.html_safe mobile = mobile_day_names.map { |day| content_tag :div, class: 'span1 hidden-desktop', style: 'width: 14.1%' do I18n.t(day.downcase) end }.join.html_safe standard + mobile end end |
#mobile_day_names ⇒ Object
43 44 45 46 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 43 def mobile_day_names return MOBILE_DAY_NAMES if start_day_index.zero? MOBILE_DAY_NAMES[start_day_index, MOBILE_DAY_NAMES.size - start_day_index] + MOBILE_DAY_NAMES[0, start_day_index] end |
#start_day ⇒ Object
23 24 25 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 23 def start_day @start_day ||= ([:start_day] && DAY_NAMES.include?([:start_day].to_s.humanize)) ? [:start_day].to_s.downcase.to_sym : :sunday end |
#start_day_index ⇒ Object
34 35 36 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 34 def start_day_index @start_day_index ||= DAY_NAMES.index {|n| n.downcase == start_day.to_s} || 0 end |
#week_rows ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 65 def week_rows weeks.map {|week| content_tag :div, class: 'row-fluid week' do week.map { |day| day_cell(day) }.join.html_safe end }.join.html_safe end |
#weeks ⇒ Object
85 86 87 88 89 |
# File 'lib/twitter/bootstrap/calendar/bootstrap_calendar.rb', line 85 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 |