From adac1363ae91097b12d48e1e98b5834af20fcce9 Mon Sep 17 00:00:00 2001 From: Lauri Kolmonen Date: Fri, 27 Sep 2013 16:54:38 +0300 Subject: [PATCH] Enabled other month cell text and attributes to be changed with block parameter. --- lib/calendar_helper.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/calendar_helper.rb b/lib/calendar_helper.rb index e24c610..2d063ef 100644 --- a/lib/calendar_helper.rb +++ b/lib/calendar_helper.rb @@ -153,7 +153,7 @@ def calendar(options = {}, &block) cal << %(#{week_number(begin_of_week, options[:week_number_format])}) 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| @@ -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 << "" @@ -242,22 +242,25 @@ def generate_cell(cell_text, cell_attrs) "#{cell_text}" 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 += %() end - generate_cell(date.day, cell_attrs) + generate_cell(cell_text, cell_attrs) end # Calculates id for th element.