event-calendar 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG.rdoc +38 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +274 -0
  4. data/Rakefile +37 -0
  5. data/VERSION +1 -0
  6. data/generators/event_calendar/USAGE +20 -0
  7. data/generators/event_calendar/event_calendar_generator.rb +50 -0
  8. data/generators/event_calendar/lib/insert_routes.rb +55 -0
  9. data/generators/event_calendar/templates/controller.rb.erb +12 -0
  10. data/generators/event_calendar/templates/helper.rb.erb +35 -0
  11. data/generators/event_calendar/templates/javascript.js +49 -0
  12. data/generators/event_calendar/templates/jq_javascript.js +35 -0
  13. data/generators/event_calendar/templates/migration.rb.erb +18 -0
  14. data/generators/event_calendar/templates/model.rb.erb +4 -0
  15. data/generators/event_calendar/templates/stylesheet.css +233 -0
  16. data/generators/event_calendar/templates/view.html.erb +6 -0
  17. data/init.rb +2 -0
  18. data/install.rb +1 -0
  19. data/lib/event_calendar.rb +189 -0
  20. data/lib/event_calendar/calendar_helper.rb +366 -0
  21. data/lib/event_calendar/railtie.rb +12 -0
  22. data/lib/generators/event_calendar/USAGE +20 -0
  23. data/lib/generators/event_calendar/event_calendar_generator.rb +92 -0
  24. data/lib/generators/event_calendar/templates/controller.rb.erb +12 -0
  25. data/lib/generators/event_calendar/templates/helper.rb.erb +35 -0
  26. data/lib/generators/event_calendar/templates/javascript.js +49 -0
  27. data/lib/generators/event_calendar/templates/jq_javascript.js +35 -0
  28. data/lib/generators/event_calendar/templates/migration.rb.erb +21 -0
  29. data/lib/generators/event_calendar/templates/model.rb.erb +3 -0
  30. data/lib/generators/event_calendar/templates/stylesheet.css +233 -0
  31. data/lib/generators/event_calendar/templates/view.html.erb +6 -0
  32. data/lib/tasks/event_calendar_tasks.rake +4 -0
  33. data/spec/event_calendar_spec.rb +78 -0
  34. data/spec/fixtures/models.rb +6 -0
  35. data/spec/spec.opts +3 -0
  36. data/spec/spec_helper.rb +30 -0
  37. data/uninstall.rb +1 -0
  38. metadata +105 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ == 2010-07-02 / Version 2.3
2
+ * Added Rails 3 generators
3
+ * Minor improvement to the generated route. Default year and month are set in the controller instead.
4
+
5
+ == 2010-06-14 / Version 2.2
6
+ * Refactored plugin pattern to allow for class attributes.
7
+ * You can now pass in custom column names for the start and end fields.
8
+ has_event_calendar :start_at_field => 'custom_start_at', :end_at_field => 'custom_end_at'
9
+ * Can pass additional find conditions to event_strips_for_month.
10
+ * Added rpsec with a few specs.
11
+
12
+ == 2009-12-09 / Version 2.1
13
+ * Added the 'use_all_day' option. If this is set to true (by default it is false), it will check for an 'all_day' boolean field when displaying an event. If it is an all day event, or the event is multiple days, then it will display as usual. Otherwise it will display without a background color bar.
14
+ * Added a --use-all-day option to the generator
15
+ * Note, if updating, you will need to slightly change your helper. The block parameters passed to the calendar method are now in an argument hash. (More flexible, and future changes won't have this problem.) See the example in README for more.
16
+ calendar event_calendar_options do |args|
17
+ event = args[:event]
18
+ ...
19
+ end
20
+ * Javascript handles highlighting non-all-day events
21
+ * Re-factored javascript to be unobtrusive
22
+ * JQuery works the same as the Prototype version
23
+ * Minor changes to the stylesheet as a result of the new display option
24
+ * A helper method for displaying an event's time
25
+
26
+ == 2009-11-23 / Version 2
27
+ * Complete rewrite of the calendar's HTML generation and styling
28
+ * Event rows are now table cells which span the desired number of columns
29
+ * The width can be set arbitrarily, or it can be left to resize with the containing element
30
+ * Removes the use of background images for displaying the grid
31
+ * Increased ability to style calendar days
32
+ * Removed legacy options, comments, and code
33
+ * Caution, not backwards compatible with some of Version 1's options
34
+
35
+ == 2009-11-11 / Version 1
36
+ * The initial EventCalendar Rails Plugin
37
+ * Most bugs and issues have been resolved
38
+ * Works, but isn't as flexible as desired
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Elevation
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,274 @@
1
+ ==EventCalendar
2
+
3
+ Easily show multiple, overlapping events across calendar days and rows.
4
+
5
+ See http://dev.elevationblog.com/2009/7/23/event-calendar-rails-plugin for a screenshot.
6
+
7
+ After install, the "calendar" method will be available within your views.
8
+
9
+ To customize the look, modify the included stylesheet and/or change the default options.
10
+
11
+
12
+ ==Install
13
+
14
+ === Rails 2
15
+
16
+ script/plugin install git://github.com/elevation/event_calendar.git
17
+
18
+ To generate the necessary static files AND the example below:
19
+
20
+ script/generate event_calendar
21
+
22
+ === Rails 3
23
+
24
+ rails plugin install git://github.com/elevation/event_calendar.git
25
+
26
+ To generate the necessary static files AND the example below:
27
+
28
+ rails generate event_calendar
29
+
30
+ === Generator Options
31
+
32
+ script/generate event_calendar --help
33
+
34
+ --static-only: Only generate the stylesheet and javascript
35
+ --use-jquery: Generate jquery javascript
36
+ --use-all-day: Include an 'all_day' field on events, and display appropriately
37
+
38
+ You can change the default event model name (Event) and controller/view name (Calendar) by passing in two name arguments:
39
+
40
+ script/generate event_calendar EventModel ControllerName
41
+
42
+
43
+ ==Generated Files
44
+
45
+ Make sure to include the stylesheet and javascript in your layout/view.
46
+
47
+ ====Static files
48
+
49
+ public/stylesheets/event_calendar.css
50
+ public/javascripts/event_calendar.js
51
+
52
+ Unless the --static-only option is given, the following will be
53
+ generated. Names will differ if name arguments were passed to the
54
+ generator.
55
+
56
+ ====db/migrate/XXXX_create_events.rb
57
+
58
+ class CreateEvents < ActiveRecord::Migration
59
+ def self.up
60
+ create_table :events do |t|
61
+ t.string :name
62
+ t.datetime :start_at
63
+ t.datetime :end_at
64
+
65
+ t.timestamps
66
+ end
67
+ end
68
+
69
+ def self.down
70
+ drop_table :events
71
+ end
72
+ end
73
+
74
+ At minimum we need to have start_at and end_at fields. Altnernatively, you can configure the columns to be used by passing options to has_event_calendar.
75
+
76
+ If the '--use-all-day' option is passed to the generator, it will also add a boolean all_day field. Set :start_at to be any time on the day of the event and set :all_day to true.
77
+
78
+ An event can also have a *color* field (any string which is a valid CSS color) which determines the color of the event. Or simply override the default virtual attribute on the model. For example, if events are associated to a calendar model, then the events can get their color from the calendar.
79
+
80
+ ====app/models/event.rb
81
+
82
+ class Event < ActiveRecord::Base
83
+ has_event_calendar
84
+
85
+ # To specify the columns to use call it like this:
86
+ #
87
+ # has_event_calendar :start_at_field => 'custom_start_at', :end_at_field => 'custom_end_at'
88
+ #
89
+
90
+ end
91
+
92
+ ====config/routes.rb
93
+
94
+ map.calendar '/calendar/:year/:month', :controller => 'calendar', :action => 'index', :requirements => {:year => /\d{4}/, :month => /\d{1,2}/}, :year => nil, :month => nil
95
+
96
+ ====app/controllers/calendar_controller.rb
97
+
98
+ class CalendarController < ApplicationController
99
+
100
+ def index
101
+ @month = (params[:month] || Time.zone.now.month).to_i
102
+ @year = (params[:year] || Time.zone.now.year).to_i
103
+
104
+ @shown_month = Date.civil(@year, @month)
105
+
106
+ @event_strips = Event.event_strips_for_month(@shown_month)
107
+
108
+ # To restrict what events are included in the result you can pass additional find options like this:
109
+ #
110
+ # @event_strips = Event.event_strips_for_month(@shown_month, :include => :some_relation, :conditions => 'some_relations.some_column = true')
111
+ #
112
+
113
+ end
114
+
115
+ end
116
+
117
+ ====app/helpers/calendar_helper.rb
118
+
119
+ Some helper methods are created, but you could put this in the view. The key is our calendar method, which takes some options.
120
+
121
+ module CalendarHelper
122
+ def month_link(month_date)
123
+ link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year})
124
+ end
125
+
126
+ # custom options for this calendar
127
+ def event_calendar_options
128
+ {
129
+ :year => @year,
130
+ :month => @month,
131
+ :event_strips => @event_strips,
132
+ :month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
133
+ :previous_month_text => "<< " + month_link(@shown_month.last_month),
134
+ :next_month_text => month_link(@shown_month.next_month) + " >>"
135
+ }
136
+ end
137
+
138
+ def event_calendar
139
+ calendar event_calendar_options do |args|
140
+ event = args[:event]
141
+ %(<a href="/events/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
142
+ end
143
+ end
144
+ end
145
+
146
+ Notice you can pass in a block to the calendar method. In this example I'm passing a link to the event details, and displaying the event's name.
147
+
148
+ ====app/views/calendar/index.html.erb
149
+
150
+ Then in calendar view, simply:
151
+
152
+ <%= event_calendar %>
153
+
154
+ In Rails 3, use raw(event_calendar)
155
+
156
+
157
+ ==Default Options
158
+
159
+ The default options for the calendar are:
160
+
161
+ defaults = {
162
+ :year => Time.zone.now.year,
163
+ :month => Time.zone.now.month,
164
+ :abbrev => true,
165
+ :first_day_of_week => 0, # See note below when setting this
166
+ :show_today => true,
167
+ :month_name_text => Time.zone.now.strftime("%B %Y"),
168
+ :previous_month_text => nil,
169
+ :next_month_text => nil,
170
+ :event_strips => [],
171
+
172
+ # it would be nice to have these in the CSS file
173
+ # but they are needed to perform height calculations
174
+ :width => nil,
175
+ :height => 500,
176
+ :day_names_height => 18,
177
+ :day_nums_height => 18,
178
+ :event_height => 18,
179
+ :event_margin => 1,
180
+ :event_padding_top => 1,
181
+
182
+ :use_all_day => false,
183
+ :use_javascript => true,
184
+ :link_to_day_action => false
185
+ }
186
+
187
+ You can override any of these by passing your options to the calendar method. In the above example, update the event_calendar_options helper method.
188
+
189
+ ====Details
190
+
191
+ * See the notes in the plugin's calendar_helper.rb for more info.
192
+
193
+ * *width*: Optional, if none is given it will stretch to the containing element.
194
+
195
+ * *height*: Defaults to 500px. This is the approx minimum total height of the calendar. It could be greater if a calendar row(s) need to stretch to fit additional events.
196
+
197
+ * *use_all_day*: If set to true, will check for an 'all_day' boolean field when displaying an event. If it is an all day event, or the event is multiple days, then it will display as usual. Otherwise it will display without a background color bar.
198
+
199
+ Helper/View:
200
+ :use_all_day => true
201
+
202
+ If using this option, you probably want to also show times for non-all-day events:
203
+ calendar event_calendar_options do |args|
204
+ event, day = args[:event], args[:day]
205
+ html = %(<a href="/events/#{event.id}" title="#{h(event.name)}">)
206
+ html << display_event_time(event, day)
207
+ html << %(#{h(event.name)}</a>)
208
+ html
209
+ end
210
+
211
+ * *use_javascript*: If set to false, it won't add custom HTML data attributes that are needed for javascript highlighting. (Note, custom attributes will be valid in HTML 5.) The actual javascript is unobtrusive and found in the event_calendar.js file.
212
+
213
+ * *link_to_day_action*: Will make the calendar's day numbers links to the given Rails action. Note, you'll probably want a corresponding route, controller action, and view to go with this action. Example:
214
+
215
+ Helper/View calendar option:
216
+ :link_to_day_action => "day"
217
+
218
+ Route (the controller is the same as your other calendar route):
219
+ map.calendar_day "/calendar/:year/:month/:day", :controller => "calendar", :action => "day"
220
+
221
+
222
+ ==Notes
223
+
224
+ * If you want to change the <b>first day of the week</b> from the default of Sunday (0), then set the new value in an instance variable and pass it to event_strips_for_month (in the controller), and to the event calendar options (in the helper/view).
225
+
226
+ Controller:
227
+ @first_day_of_week = 1
228
+ @event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week)
229
+
230
+ Helper/View calendar options:
231
+ :first_day_of_week => @first_day_of_week
232
+
233
+ * If you need access to the events, not just the event strips, then instead of calling event_strips_for_month call these 3 methods:
234
+
235
+ start_d, end_d = Event.get_start_and_end_dates(@shown_month) # optionally pass in @first_day_of_week
236
+ @events = Event.events_for_date_range(start_d, end_d)
237
+ @event_strips = Event.create_event_strips(start_d, end_d, @events)
238
+
239
+ * The event <b>select color</b> is set in the event_calendar.js file.
240
+
241
+ ==il8n
242
+
243
+ To localize month and day names, add the following to your localization file(s) in config/locales:
244
+
245
+ date -> formats, day_names, abbr_day_names, month_names, abbr_month_names
246
+
247
+ For example, in es.yml:
248
+
249
+ es:
250
+ date:
251
+ formats:
252
+ default: "%e/%m/%Y"
253
+
254
+ day_names: [Domingo, Lunes, Martes, Miércoles, Jueves, Viernes, Sábado]
255
+ abbr_day_names: [Dom, Lun, Mar, Mie, Jue, Vie, Sab]
256
+
257
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
258
+ month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre]
259
+ abbr_month_names: [~, Ene, Feb, Mar, Abr, May, Jun, Jul, Ago, Sep, Oct, Nov, Dic]
260
+
261
+
262
+ ==Contributors
263
+
264
+ * Jeff Schuil
265
+ * See commit history for list of additional contributors.
266
+ * Thanks to those who have added features, fixed bugs, and/or reported issues.
267
+
268
+ == History
269
+
270
+ * Though EventCalendar has diverged greatly, it was...
271
+ * Originally based off of James Urquhart's http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
272
+ * This in turn started as Geoffrey Grosenbach's CalendarHelper.
273
+
274
+ Copyright (c) 2009 Elevation, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "event-calendar"
8
+ gem.summary = "Rails helper for generating a calendar of events."
9
+ gem.email = ""
10
+ gem.description = "Rails helper for generating a calendar of events. These events can optionally span multiple days."
11
+ gem.authors = ["Jeff Schuil"]
12
+ gem.homepage = "http://github.com/elevation/event_calendar"
13
+ gem.require_path = 'lib'
14
+ # Runtime dependencies
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ task :default => :spec
23
+ desc "Run all specs"
24
+ Spec::Rake::SpecTask.new do |t|
25
+ t.spec_files = FileList['spec/**/*_spec.rb']
26
+ t.spec_opts = ['--options', 'spec/spec.opts']
27
+ end
28
+
29
+ require 'rake/rdoctask'
30
+ desc 'Generate documentation for the event_calendar plugin.'
31
+ Rake::RDocTask.new(:rdoc) do |rdoc|
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = 'EventCalendar'
34
+ rdoc.options << '--line-numbers' << '--inline-source'
35
+ rdoc.rdoc_files.include('README')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,20 @@
1
+ Usage:
2
+
3
+ script/generate event_calendar [EVENT_MODEL VIEW_NAME]
4
+
5
+ This will create:
6
+
7
+ # static files
8
+ public/stylesheets/event_calendar.css
9
+ public/javascripts/event_calendar.js
10
+
11
+ # Unless --static-only option is given
12
+ # MVC and supporting files (depending on model and view name)
13
+ app/models/event.rb
14
+ app/controllers/calendar_controller.rb
15
+ app/views/calendar
16
+ app/views/calendar/index.html.erb
17
+ app/helpers/calendar_helper.rb
18
+ db/migrate
19
+ db/migrate/XXXX_create_events.rb
20
+ route map.calendar
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_routes.rb")
2
+
3
+ class EventCalendarGenerator < Rails::Generator::Base
4
+ default_options :static_only => false,
5
+ :use_jquery => false,
6
+ :use_all_day => false
7
+
8
+ attr_reader :class_name, :view_name
9
+
10
+ def initialize(args, runtime_options = {})
11
+ super
12
+ usage if args.length > 0 and args.length < 2
13
+ @class_name = (args.shift || "event").underscore
14
+ @view_name = (args.shift || "calendar").underscore
15
+ end
16
+
17
+ def manifest
18
+ record do |m|
19
+ # static files
20
+ m.file "stylesheet.css", "public/stylesheets/event_calendar.css"
21
+
22
+ script = options[:use_jquery] ? 'jq_javascript.js' : 'javascript.js'
23
+ m.file script, "public/javascripts/event_calendar.js"
24
+
25
+ # MVC and other supporting files
26
+ unless options[:static_only]
27
+ m.template "model.rb.erb", File.join("app/models", "#{@class_name}.rb")
28
+ m.template "controller.rb.erb", File.join("app/controllers", "#{@view_name}_controller.rb")
29
+ m.directory File.join("app/views", @view_name)
30
+ m.template "view.html.erb", File.join("app/views", @view_name, "index.html.erb")
31
+ m.template "helper.rb.erb", File.join("app/helpers", "#{@view_name}_helper.rb")
32
+ m.migration_template "migration.rb.erb", "db/migrate", :migration_file_name => "create_#{@class_name.pluralize}"
33
+ m.route_name(@view_name, "/#{@view_name}/:year/:month", ":controller => '#{@view_name}', :action => 'index', :requirements => {:year => /\d{4}/, :month => /\d{1,2}/}, :year => nil, :month => nil")
34
+ end
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def add_options!(opt)
41
+ opt.separator ''
42
+ opt.separator 'Options:'
43
+ opt.on("--static-only",
44
+ "Only generate the static files. (stylesheet, javascript, and images)") { |v| options[:static_only] = v }
45
+ opt.on("--use-jquery",
46
+ "Use jquery template file when generating the javascript.") { |v| options[:use_jquery] = v }
47
+ opt.on("--use-all-day",
48
+ "Include an 'all_day' field on events, and display appropriately.") { |v| options[:use_all_day] = v }
49
+ end
50
+ end