Class: Clndr

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers, ActiveSupport::Inflector
Defined in:
lib/clndr-rails.rb,
lib/clndr-rails/config.rb,
lib/clndr-rails/engine.rb,
lib/clndr-rails/errors.rb,
lib/clndr-rails/helpers.rb,
lib/clndr-rails/version.rb,
lib/clndr-rails/templates.rb

Defined Under Namespace

Modules: Error, Helpers, Rails, Template Classes: Engine, InstallGenerator

Constant Summary collapse

@@calendar_basket =
{}
@@template =

default config

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 =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Clndr

Returns a new instance of Clndr.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

Instance Attribute Details

#adjacent_days_change_monthObject

Returns the value of attribute adjacent_days_change_month.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def adjacent_days_change_month
  @adjacent_days_change_month
end

#days_of_the_weekObject

Returns the value of attribute days_of_the_week.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def days_of_the_week
  @days_of_the_week
end

#done_renderingObject

Returns the value of attribute done_rendering.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def done_rendering
  @done_rendering
end

#eventsObject (readonly)

Returns the value of attribute events.



40
41
42
# File 'lib/clndr-rails.rb', line 40

def events
  @events
end

#force_six_rowsObject

Returns the value of attribute force_six_rows.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def force_six_rows
  @force_six_rows
end

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/clndr-rails.rb', line 40

def name
  @name
end

#show_adjacent_monthsObject

Returns the value of attribute show_adjacent_months.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def show_adjacent_months
  @show_adjacent_months
end

#start_with_monthObject

Returns the value of attribute start_with_month.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def start_with_month
  @start_with_month
end

#templateObject

Returns the value of attribute template.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def template
  @template
end

#week_offsetObject

Returns the value of attribute week_offset.



37
38
39
# File 'lib/clndr-rails.rb', line 37

def week_offset
  @week_offset
end

Class Method Details

.adjacent_days_change_month=(boolean) ⇒ Object



91
92
93
# File 'lib/clndr-rails/config.rb', line 91

def self.adjacent_days_change_month=(boolean)
  @@adjacent_days_change_month= boolean
end

.classes {|@@custom_classes| ... } ⇒ Object

Yields:



111
112
113
# File 'lib/clndr-rails/config.rb', line 111

def self.classes
  yield @@custom_classes
end

.click_events {|@@click_events| ... } ⇒ Object

access to click_events hash

Yields:



82
83
84
# File 'lib/clndr-rails/config.rb', line 82

def self.click_events
  yield @@click_events
end

.configure {|_self| ... } ⇒ Object

todo check for available events and targets rails like config

Yields:

  • (_self)

Yield Parameters:

  • _self (Clndr)

    the object that the method was called on



30
31
32
# File 'lib/clndr-rails/config.rb', line 30

def self.configure
  yield self
end

.constraints_end=(date) ⇒ Object



103
104
105
# File 'lib/clndr-rails/config.rb', line 103

def self.constraints_end=(date)
  @@constraints[:endDate]= date_format date
end

.constraints_start=(date) ⇒ Object



99
100
101
# File 'lib/clndr-rails/config.rb', line 99

def self.constraints_start=(date)
  @@constraints[:startDate]= date_format date
end

.date_format(date) ⇒ Object

check date to available format if date is Time instance, convert to available string



5
6
7
8
9
10
11
12
13
# 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) ⇒ Object



69
70
71
72
73
74
75
# 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_settingsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



95
96
97
# File 'lib/clndr-rails/config.rb', line 95

def self.done_rendering=(jsfunction)
  @@done_rendering = jsfunction
end

.force_six_rows=(boolean) ⇒ Object



107
108
109
# File 'lib/clndr-rails/config.rb', line 107

def self.force_six_rows=(boolean)
  @@force_six_rows= boolean
end

.get_calendar(calendar) ⇒ Object

return calendar from calendars bean



27
28
29
30
31
32
33
34
# 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

.show_adjacent_months=(boolean) ⇒ Object



77
78
79
# File 'lib/clndr-rails/config.rb', line 77

def self.show_adjacent_months=(boolean)
  @@show_adjacent_months = boolean
end

.start_with_month=(date) ⇒ Object



65
66
67
# File 'lib/clndr-rails/config.rb', line 65

def self.start_with_month=(date)
  @@start_with_month = date_format date
end

.targets {|@@targets| ... } ⇒ Object

access to target hash

Yields:



87
88
89
# File 'lib/clndr-rails/config.rb', line 87

def self.targets
  yield @@targets
end

.template=(template) ⇒ Object



51
52
53
# File 'lib/clndr-rails/config.rb', line 51

def self.template=(template)
  @@template ||= template
end

.week_offset=(offset) ⇒ Object



55
56
57
58
59
60
61
62
63
# 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

Instance Method Details

#add_event(date, title, *other_data) ⇒ Object

add event to events array *other_data some data for tour access in template



182
183
184
185
186
187
188
# 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) ⇒ Object

add multiday event



191
192
193
194
195
196
197
198
# 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_eventObject

access to click_events hash



124
125
126
# File 'lib/clndr-rails.rb', line 124

def click_event
  @click_events
end

#constraints_endObject



141
142
143
# File 'lib/clndr-rails.rb', line 141

def constraints_end
  @constraints[:endDate]
end

#constraints_end=(date) ⇒ Object



145
146
147
# File 'lib/clndr-rails.rb', line 145

def constraints_end=(date)
  @constraints[:endDate] = Clndr.date_format date
end

#constraints_startObject



133
134
135
# File 'lib/clndr-rails.rb', line 133

def constraints_start
  @constraints[:startDate]
end

#constraints_start=(date) ⇒ Object



137
138
139
# File 'lib/clndr-rails.rb', line 137

def constraints_start=(date)
  @constraints[:startDate] = Clndr.date_format date
end

#custom_adjacent_month_class=(css_class) ⇒ Object



172
173
174
# File 'lib/clndr-rails.rb', line 172

def custom_adjacent_month_class=(css_class)
  @custom_classes[:adjacentMonth]=css_class
end

#custom_classesObject



149
150
151
# File 'lib/clndr-rails.rb', line 149

def custom_classes
  @custom_classes
end

#custom_event_class=(css_class) ⇒ Object



157
158
159
# File 'lib/clndr-rails.rb', line 157

def custom_event_class=(css_class)
  @custom_classes[:event]=css_class
end

#custom_inactive_class=(css_class) ⇒ Object



176
177
178
# 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) ⇒ Object



164
165
166
# 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) ⇒ Object



168
169
170
# 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) ⇒ Object



160
161
162
# File 'lib/clndr-rails.rb', line 160

def custom_past_class=(css_class)
  @custom_classes[:past]=css_class
end

#custom_today_class=(css_class) ⇒ Object



153
154
155
# File 'lib/clndr-rails.rb', line 153

def custom_today_class=(css_class)
  @custom_classes[:today]=css_class
end

#targetObject

access to targets hash



129
130
131
# File 'lib/clndr-rails.rb', line 129

def target
  @targets
end

#view(args = nil) ⇒ Object

return html of calendar



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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

  (:div,nil,args)do
    (: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