Simple Calendar Plugin for Ruby on Rails Tutorial

The Simple Calendar Plugin

Created by Slaive and Pullmonkey

With this plugin you can easily add calendar items for any day and then view it in month view or day view.

Install with:

./script/plugin install git://github.com/pullmonkey/simple_calendar.git

Installation

For this pugin you will need several javascript, stylesheet, and image files. These files should be installed automatically on installation. If not then you can use the rake command to install them.

To install these files use:

rake simple_calendar:install

If you want to remove these files then use:

rake simple_calendar:uninstall

Migrations

To generate migrations use:

./script/generate simple_calendar_migrations

This should create 2 migration files:

  • 01_create_simple_calendar.rb
  • 02_create_simple_calendar_entries.rb

Dependencies

This plugin only has 1 dependency which is the acts_as_taggable_on_steroids plugin. This plugin is only needed if you want to be able to make your entries taggable. To install this plugin do:

./script/plugin install http://github.com/jviney/acts_as_taggable_on_steroids.git

Environment.rb

You will need to set your timezone in your environment.rb file. I use the UTC setting so it should look like this:

config.time_zone = 'UTC'

Layout

You only need to add the color stylesheet to your layout. As of now all we have is red and gold. Just pick one and add it to your layout.

<%= stylesheet_link_tag 'simple_calendar_red' %>
<%= stylesheet_link_tag 'simple_calendar_gold' %>

Usage

Put this is your view wherever you want the simple calendar to show up:

<%= render :simple_calendar => "test", :admin => true, :mode => params[:mode], :date => params[:date] %>

You must pass params[:mode] and params[:date] so that after entering an entry the mode and date of where you are will be returned back to the simple calendar controller. This only happens after creating, updating, or removing an entry. So if you don’t plan on the admin to ever be true then you won’t need to pass this at all.

Additional Options

The options you can pass to simple_calendar are:

  • :admin => true/false
    • This decides whether the user can edit the calendar or not
    • defaults to false
  • :writable => true/false
    • This decides whether the user can can add and remove their own items or not. This is useful for a calendar where individual users can schedule their own items, but you don’t want them to mess with other users’ information.
    • Must pass a :user for this to work properly.
    • defaults to false
  • :user => “username"
    • This sets the user that is making changes. A user with :writable set to true can only edit or remove the entries that user created.
    • defaults to “”
  • :prefix => “/test"
    • This is whatever the prefix for your site is. Mainly used for image, stylesheet, javascript, etc. paths.
    • defaults to “”
  • :return_to => “/path/to/my/calendar"
    • This is the path in front of the simple_calendar/
    • defaults to “”
  • :mode => “month"
    • This is the starting mode you want the calendar to be in.
    • defaults to “month
  • :date => “2008-10-29".to_date
    • Passes the starting view date
    • defaults to Date.today
  • :year => 2008
    • If you don’t pass a date then you can pass year seperately
  • :month => 10
    • If you don’t pass a date then you can pass month separately
  • :day => 29
    • If you don’t pass a date then you can pass day separately
  • :show_wiki_entries => true/false
    • When set to true a “Wiki Entries” button will appear. Clicking on this button will pop up a modal with all the entries after the current date in a format easily copied to a Wiki.
    • defaults to false
  • :taggable => true/false
    • Pass true to enable taggable entries. When true you will be able to tag an entry and filter all entries depending on the tag.
    • defaults to false
  • :serial_only=> true/false
    • Pass true to force entries to only be added serially (no overlapping entries).
    • defaults to false
  • :entry_link_length => [integer]
    • The entry name will truncate at this value in the month view.
    • defaults to 15
  • :day_start_hour => [integer]
    • The hour you want to start at in the day view unless there is an entry before this time.
    • Time must be entered in military time (13 is 1pm, 14 is 2pm, etc.)
    • defaults to 0 (which will start at 12am current day)
  • :day_end_hour=> [integer]
    • The hour you want to end at in the day view unless there is an entry for after this time.
    • Time must be entered in military time (13 is 1pm, 14 is 2pm, etc.)
    • defaults to 24 (which will end at 12am the next day)

Small Calendar

This generates a small calendar with the month view and the day numbers are link to the day view in the large simple calendar. To do this put this anywhere in your view:

<%= render :small_simple_calendar => "test", :path => "/path/to/rendering/of/large/calendar" %>

The name of the calendar must be the same as the one you use for the large simple calendar or else the entry data won’t exist. The path is to where you render the simple_calendar.

Upcoming Events

This generates a list of the upcoming events from today’s date on.

<%= render :simple_calendar_upcoming_events => "test", :path => "/path/to/rendering/of/large/calendar" %>

The name of the calendar must be the same as the one you use for the large simple calendar or the entry data won’t exist. The path is to where you render the simple_calendar.

Additional Options

The additional options that you can pas to the simple_calendar_upcoming_events are:

  • :items => 5
    • This is the the max number of items you want listed.
    • default is everything
  • :tag => “mytag"
    • If you are using taggable entries then you can pass a tag or a string of tags (comma delimited) to find from the calendar
    • default is finding everything
  • :entry_name_length => 20
    • The entry name will truncate at this value. This does not include the length of the date.
    • defaults to 100 so pretty much everything

3 notes

  1. slaive-prog posted this