Calendar Helper Plugin

This is a view plugin that can help developers with the creation of a simple calendar. Don’t think Google Calendar or Outlook but this will get you started. To install the plugin use the plugin install script:

script/plugin install http://topfunky.net/svn/plugins/calendar_helper

The plugin has a generate script that will create three CSS styles for the calendar.

script/generate calendar_styles

This CSS files will be saved in your rails app public/images/stylesheets/calendar directory. You will need to add one of these style sheets in your controller’s layout rthml file:

<%= stylesheet_link_tag 'calendar/blue/style' %>

Once you have added the right style sheet you can produce the HTML for a stylish calendar by adding the following line to an action’s rhtml view file.

<%= calendar :year => Time.now.year, :month => Time.now.month %>

The Calendar Helper plugin supports a few other options in how and what is displays as for the days of the month. For example, to display each day of the month as link you can do the following:

<%=
calendar(:year => Time.now.year, :month => Time.now.month) do |d|
  link_to d.mday, :action => ...
end
%>

The d variable is a Date instance so you will have the month, year, wday, yday, and other month functions at your disposal. Now, if you want to apply a CSS class on certains days you can replace the code in the block with something like this:

<%=
calendar(:year => Time.now.year, :month => Time.now.month) do |d|
  [link_to(d.mday, :action => ...), {:class => 'cssClass'}]
end
%>

Technorati Tags: , , , , , ,