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: , , , , , ,

Enjoy. Share. Be Happy.
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Tumblr
  • Google Bookmarks
  • FriendFeed
  • Yahoo! Buzz
  • Reddit
  • Digg
  • HackerNews
  • Suggest to Techmeme via Twitter
  • LinkedIn
  • Ping.fm
  • Identi.ca
  • Mixx
  • Furl

Related posts:

  1. Graphs Rails Plugin
  2. Class HighLite Calendar
  3. Rails PDF Plugin
  4. Ruby Symbols
  5. Rails Google Analytics Plugin

This entry was posted in Ruby, TechKnow. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Luis
    Posted May 26, 2008 at 3:25 pm | Permalink

    Very, very helpfull post. Saved me an evening of trying to recode the helper ;-) (Meant the link thingy)

  2. Posted May 28, 2009 at 5:05 am | Permalink

    Hi I want to use calendar_helper plugin.Can anyone provide me some references on how to use it.
    Thanks.

  3. Posted May 28, 2009 at 2:10 pm | Permalink

    @Prabesh – I thought this was a reference on how to use it…. LOL

    Plugins like these are not large framework or libraries, it would take me longer to list all references than it would take a capable programmer from looking through the code and figuring it out. Take a look a the code, it is open, it is a plain ol’ script!

  4. Posted June 7, 2009 at 6:23 am | Permalink

    I think this tutorial is a good reference point.Thanks for the suggestion,I will go try to go through the code.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*