Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled other month cell text and attributes to be changed with block parameter. #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/calendar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def calendar(options = {}, &block)
cal << %(<td class="#{options[:week_number_class]}">#{week_number(begin_of_week, options[:week_number_format])}</td>) if options[:show_week_numbers]

begin_of_week.upto(first - 1) do |d|
cal << generate_other_month_cell(d, options)
cal << generate_other_month_cell(d, options, block)
end unless first.wday == first_weekday

first.upto(last) do |cur|
Expand All @@ -180,7 +180,7 @@ def calendar(options = {}, &block)

# next month
(last + 1).upto(beginning_of_week(last + 7, first_weekday) - 1) do |d|
cal << generate_other_month_cell(d, options)
cal << generate_other_month_cell(d, options, block)
end unless last.wday == last_weekday

cal << "</tr></tbody></table>"
Expand Down Expand Up @@ -242,22 +242,25 @@ def generate_cell(cell_text, cell_attrs)
"<td #{cell_attrs}>#{cell_text}</td>"
end

def generate_other_month_cell(date, options)
def generate_other_month_cell(date, options, block)
unless options[:show_other_months]
return generate_cell("", {})
end
cell_attrs = {}
cell_attrs[:headers] = th_id(date, options[:table_id])
cell_attrs[:class] = options[:other_month_class]
cell_attrs[:class] += " weekendDay" if weekend?(date)
cell_attrs["data-date"] = date

cell_text = date.day
cell_attrs = {}
cell_text, cell_attrs = block.call(date) unless block.call(date).nil?

cell_attrs[:headers] = ((cell_attrs[:headers] || "") + " #{th_id(date, options[:table_id])}").strip
cell_attrs[:class] = ((cell_attrs[:class] || "") + " #{options[:other_month_class]}").strip
cell_attrs[:class] = ((cell_attrs[:class] || "") + " weekendDay").strip if weekend?(date)
cell_attrs["data-date"] = ((cell_attrs["data-date"] || "") + " #{date}").strip

if options[:accessible]
cell_text += %(<span class="hidden"> #{month_names[date.month]}</span>)
end

generate_cell(date.day, cell_attrs)
generate_cell(cell_text, cell_attrs)
end

# Calculates id for th element.
Expand Down