Semantics, Code and Circumstance
April 10, 2010: This afternoon I recieved a visit from a plushy black cat. I've never seen her before and since she has a collar she may be moved in with her owner in the last days.
Read more about project 365 ...Although the mephisto blog system contains a possibility to display a gravatar for a specific comment, I decided to do my own gravatar plugin, because I wanted to display gravatars not just on comments. You can download the first version from GitHub.
Installation is real simple. Just download it and put it into your vendor/plugins folder. After that, restart your server.
You may configure the following options in lib/mephisto_gravatar_plugin.rb:
default = 'identicon'
The guys at gravatar.com offer you three default avatars, in case there is no gravatar associated with that email address. Correct values for would be identicon, monsterid and wavatar.
rating = 'pg'
As you may know, all gravatars include a rating, done by the holder of the email. This rating may be one of the following: g, pg, r or x. To get only the gravatars you want, set the correct rating.
You can stuff any email into the filter, in order to get its gravatar. Sample usages:
{{ article.author.email | get_gravatar }}
{{ comment.author_email | get_gravatar, 30 }}
Note the object independence. An email address is all you need. You may deliver the desired size as an option to the filter. Leaving that out brings up the standard size of 80×80px.
There is still work to do. I think about pre-caching all gravatars for the registered bloggers. But that is subject to later exploration.
Something that bugged me with its non-existence in the past was a rails plugin that would display a weekly calendar, while being highly configurable. And by saying highly configurable, I mean it should have options for its look, its operation and, beyond that, it should accept any kind of data to display. As there was no such plugin, I did it myself. So today, I proudly present you the weekly_schedule plugin for rails.
This plugin is really easy to install. Just download it from GitHub and place it into the vendor/plugins directory.
The simplest possible call in your code would be
schedule()
which generates a plain calendar (which can then be customized using CSS) for the current week. However, this may be customized in a variety of ways—changing the default CSS classes, populating the individual day entries with appointments, and so on. Generating a calendar that shows the whole christmas week 2009, starting from monday, would require the following call:
schedule(:day => Date.civil(2009, 12, 25), :first_day_of_week => 1)
A more typical use case for schedules is to show what happening today or the very next time. The following code generates a calendar that always starts with today:
schedule(:first_day_of_week => Date.today.cwday)
A more convenient variant of this is the following:
schedule(:first_day_of_week => Date.today.cwday - 3)
This calendar starts three days earlier and therefore keeps today right in the middle of the display
As I said earlier in this post, I wanted this plugin to be as customizable as possible. So it is now packed with different options for the CSS classes:
:table_class
:month_name_class
:day_name_class
:day_class
An additional ‘weekend’ class is applied to weekend days.
The following options are available for customizing the behaviour of the calendar:
:day
This option specifies the day, whose week shall be displayed. Defaults to Date.today
:abbrev
This option specifies how the day names should be abbreviated. Use (0..2) for the first three letters, (0..0) for the first, and (0..-1) for the entire name.
:first_day_of_week
This renders a calendar starting on a specific weekday. Use 1 for Monday up to 7 for Sunday. This option applies only if :only_workdays is set to false.
:show_today
Highlights today on the calendar using the CSS class ‘today’. Defaults to true.
:only_workdays
Turns off weekend display. Defaults to false. When turned on, the value of :first_day_of_week is fixed to 1 (monday). If :day is a saturday or sunday, the following week is shown.
:show
Now, this gives us a hint where to search for info to show and is handed over to details(). Defaults to nil (showing no info).
This function evaluates if something is given in in the :show option. The following should give you a rough idea how this may be useful. Imagine, you’ve given @this_weeks_appointments as an array via the :show option. The value in date is the currently processed day as a Date object.
def details(date, options)
if options[:show]
appointments = options[:show].select{|a| a.date == date}.sort_by{|t| t.time}
appointments.map{|a| "#{a.time} #{a.place}"}
else
'Nothing to do today'
end
end
Feel free to download the plugin from GitHub. If you have some comment or a great idea, please let me know.