class Clndr
Attributes
adjacent_days_change_month[RW]
days_of_the_week[RW]
done_rendering[RW]
events[R]
force_six_rows[RW]
name[R]
show_adjacent_months[RW]
start_with_month[RW]
template[RW]
week_offset[RW]
Public Class Methods
adjacent_days_change_month=(boolean)
click to toggle source
# File lib/clndr-rails/config.rb, line 91 def self.adjacent_days_change_month=(boolean) @@adjacent_days_change_month= boolean end
classes() { |custom_classes| ... }
click to toggle source
# File lib/clndr-rails/config.rb, line 111 def self.classes yield @@custom_classes end
click_events() { |click_events| ... }
click to toggle source
access to click_events
hash
# File lib/clndr-rails/config.rb, line 82 def self.click_events yield @@click_events end
configure() { |self| ... }
click to toggle source
todo check for available events and targets rails like config
# File lib/clndr-rails/config.rb, line 30 def self.configure yield self end
constraints_end=(date)
click to toggle source
# File lib/clndr-rails/config.rb, line 103 def self.constraints_end=(date) @@constraints[:endDate]= date_format date end
constraints_start=(date)
click to toggle source
# File lib/clndr-rails/config.rb, line 99 def self.constraints_start=(date) @@constraints[:startDate]= date_format date end
date_format(date)
click to toggle source
check date to available format if date is Time instance, convert to available string
# File lib/clndr-rails/config.rb, line 5 def self.date_format(date) if date.is_a?(Time) date.strftime('%F') elsif date.match(/\d{4}\-\d{2}\-\d{2}/) date else raise Clndr::Error::WrongDateFormat end end
days_of_the_week=(array_of_days)
click to toggle source
# File lib/clndr-rails/config.rb, line 69 def self.days_of_the_week=(array_of_days) if array_of_days.length == 7 @@days_of_the_week=array_of_days else raise Clndr::Error::WrongDaysOfWeekArray end end
default_settings()
click to toggle source
# File lib/clndr-rails/config.rb, line 34 def self.default_settings @@template = Clndr::Template::BLANK @@week_offset = 1 @@start_with_month = nil @@days_of_the_week = nil @@click_events={} @@targets={} @@show_adjacent_months= true @@adjacent_days_change_month=false @@done_rendering=nil @@constraints ={} @@force_six_rows= true @@custom_classes = {} self end
done_rendering=(jsfunction)
click to toggle source
# File lib/clndr-rails/config.rb, line 95 def self.done_rendering=(jsfunction) @@done_rendering = jsfunction end
force_six_rows=(boolean)
click to toggle source
# File lib/clndr-rails/config.rb, line 107 def self.force_six_rows=(boolean) @@force_six_rows= boolean end
get_calendar(calendar)
click to toggle source
return calendar from calendars bean
# File lib/clndr-rails.rb, line 27 def get_calendar(calendar) clndr = @@calendar_basket[calendar.to_sym] if clndr.class == Clndr clndr else raise Clndr::Error::CalendarNotFound, "Calendar with name #{calendar} not found. Use Clndr.new(:#{calendar}) to create them" end end
new(name)
click to toggle source
# File lib/clndr-rails.rb, line 44 def initialize(name) @name = name.to_sym @template = @@template @week_offset = @@week_offset @start_with_month =@@start_with_month @days_of_the_week = @@days_of_the_week @click_events = @@click_events.clone @targets= @@targets.clone @show_adjacent_months= @@show_adjacent_months @adjacent_days_change_month = @@adjacent_days_change_month @done_rendering = @@done_rendering @constraints =@@constraints @force_six_rows =@@force_six_rows @custom_classes = @@custom_classes @has_multiday= false @events =[] @@calendar_basket.merge! Hash[@name,self] end
show_adjacent_months=(boolean)
click to toggle source
# File lib/clndr-rails/config.rb, line 77 def self.show_adjacent_months=(boolean) @@show_adjacent_months = boolean end
start_with_month=(date)
click to toggle source
# File lib/clndr-rails/config.rb, line 65 def self.start_with_month=(date) @@start_with_month = date_format date end
targets() { |targets| ... }
click to toggle source
access to target hash
# File lib/clndr-rails/config.rb, line 87 def self.targets yield @@targets end
template=(template)
click to toggle source
# File lib/clndr-rails/config.rb, line 51 def self.template=(template) @@template ||= template end
week_offset=(offset)
click to toggle source
# File lib/clndr-rails/config.rb, line 55 def self.week_offset=(offset) # convert offset to CLNDR format if offset @@week_offset = 1 else @@week_offset = 0 end end
Public Instance Methods
add_event(date,title,*other_data)
click to toggle source
add event to events array *other_data some data for tour access in template
# File lib/clndr-rails.rb, line 182 def add_event(date,title,*other_data) date = Clndr.date_format date event = {date: date,title:title} event.merge! *other_data if other_data.length>0 @events.push event end
add_multiday_event(start_date,end_date,title,*other_data)
click to toggle source
add multiday event
# File lib/clndr-rails.rb, line 191 def add_multiday_event(start_date,end_date,title,*other_data) start_date = Clndr.date_format start_date end_date = Clndr.date_format end_date event = {start_date:start_date,end_date:end_date,title:title} event.merge! *other_data if other_data.length >0 @has_multiday ||= true @events.push event end
click_event()
click to toggle source
access to click_events
hash
# File lib/clndr-rails.rb, line 124 def click_event @click_events end
constraints_end()
click to toggle source
# File lib/clndr-rails.rb, line 141 def constraints_end @constraints[:endDate] end
constraints_end=(date)
click to toggle source
# File lib/clndr-rails.rb, line 145 def constraints_end=(date) @constraints[:endDate] = Clndr.date_format date end
constraints_start()
click to toggle source
# File lib/clndr-rails.rb, line 133 def constraints_start @constraints[:startDate] end
constraints_start=(date)
click to toggle source
# File lib/clndr-rails.rb, line 137 def constraints_start=(date) @constraints[:startDate] = Clndr.date_format date end
custom_adjacent_month_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 172 def custom_adjacent_month_class=(css_class) @custom_classes[:adjacentMonth]=css_class end
custom_classes()
click to toggle source
# File lib/clndr-rails.rb, line 149 def custom_classes @custom_classes end
custom_event_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 157 def custom_event_class=(css_class) @custom_classes[:event]=css_class end
custom_inactive_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 176 def custom_inactive_class=(css_class) @custom_classes[:inactive]=css_class end
custom_last_month_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 164 def custom_last_month_class=(css_class) @custom_classes[:lastMonth]=css_class end
custom_next_month_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 168 def custom_next_month_class=(css_class) @custom_classes[:nextMonth]=css_class end
custom_past_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 160 def custom_past_class=(css_class) @custom_classes[:past]=css_class end
custom_today_class=(css_class)
click to toggle source
# File lib/clndr-rails.rb, line 153 def custom_today_class=(css_class) @custom_classes[:today]=css_class end
start_with_month=(date)
click to toggle source
if date is instance of Time convert to “YYYY-MM-DD” format
# File lib/clndr-rails.rb, line 119 def start_with_month=(date) @start_with_month = Clndr.date_format date end
target()
click to toggle source
access to targets hash
# File lib/clndr-rails.rb, line 129 def target @targets end
view(args=nil)
click to toggle source
return html of calendar
# File lib/clndr-rails.rb, line 64 def view(args=nil) case @template when Clndr::Template::FULL css_class = 'full-clndr-template' when Clndr::Template::MINI css_class = 'mini-clndr-template' when Clndr::Template::SIMPLE css_class = 'simple-clndr-template' else css_class = 'blank-clndr-template' end content_tag(:div,nil,args)do content_tag(:div,nil,id:"#{@name}-clndr",class:"clearfix #{css_class}")+ javascript_tag("var #{@name} = $('##{@name}-clndr').clndr({ #{'template:'+@template+',' unless @template.nil?} #{'weekOffset:'+@week_offset.to_s+',' if @week_offset==1} #{'startWithMonth:\''+@start_with_month.to_s+'\',' unless @start_with_month.nil?} #{'daysOfTheWeek:'+@days_of_the_week.to_s+',' unless @days_of_the_week.nil?} #{build_from_hash(@click_events,'clickEvents')} #{build_from_hash(@targets,'targets',true)} #{'showAdjacentMonths:'+@show_adjacent_months.to_s+',' unless @show_adjacent_months} #{'adjacentDaysChangeMonth:'+@adjacent_days_change_month.to_s+',' if @adjacent_days_change_month} #{'doneRendering:'+@done_rendering+',' unless @done_rendering.nil?} #{'forceSixRows:'+@force_six_rows.to_s+',' if @force_six_rows} #{build_from_hash(@custom_classes, 'classes',true)} #{ if @constraints.length >0 build_from_hash @constraints, 'constraints', true end} #{if @has_multiday "multiDayEvents: { startDate: 'startDate', endDate: 'endDate', singleDay: 'date' }," end} #{if @events.length > 0 'events:['+build_events+']' end} });".gsub(/\n\s*\n/,"\n")) end end
week_offset=(boolean)
click to toggle source
# File lib/clndr-rails.rb, line 110 def week_offset=(boolean) if boolean @week_offset=1 else @week_offset =0 end end
Private Instance Methods
build_events()
click to toggle source
generate events array from @event
# File lib/clndr-rails.rb, line 214 def build_events list_of_events='' @events.delete_if do |event| list_of_events +="{ #{'date:\''+event.delete(:date)+'\',' unless event[:date].nil?} #{'startDate: \''+event.delete(:start_date)+'\','+ 'endDate: \'' + event.delete(:end_date)+'\',' unless event[:start_date].nil?} title: '#{event.delete(:title).gsub("'",""")}', #{event.map{|k,v| "#{k}:'#{v.gsub("'",""")}'"}.join(',')}},".gsub(/\n\s*\n/,"\n") end # return string with events list_of_events end
build_from_hash(hash, parameter,safety=false)
click to toggle source
build string from hash to parameter this unsafe method use only for function or true/false value if you need generate js string (eg param:'some value') use .build_from_hash_safety
# File lib/clndr-rails.rb, line 206 def build_from_hash(hash, parameter,safety=false) if hash.length > 0 "#{parameter}: {#{hash.map { |k, v| "#{k}:#{'\'' if safety}#{v}#{'\'' if safety}," }.join}}," end end