winplusの日記 このページをアンテナに追加 RSSフィード

2007-03-30

calendar_helper(その1)

カレンダーを表示する。

XREA.COM

$ script/plugin install http://topfunky.net/svn/plugins/calendar_helper
$ script/generate calendar_styles
  • 曜日を日本語表示に。
  • 月は表示しない。(テーブルの外に表示する)
$ vi vendor/plugins/calendar_helper/lib/calendar_helper.rb
Date::DAYNAMES = ['日','月','火','水','木','金','土']
...
#    cal << %(<thead><tr class="#{options[:month_name_class]}"><th colspan="7">#{Date::MONTHNAMES[options[:month]]}</th></tr><tr class="#{options[:day_name_class]}">)
    cal << %(<thead><tr class="#{options[:day_name_class]}">)

とりあえず、今月のカレンダを表示してみる。

$ vi app/views/layouts/articles.rhtml
<% @year = Time.now.year %>
<% @month = Time.now.month %>
<h3><%= @year %> - <%= @month %></h3>
<ul class="links">
  <% @dates = Tag.find(:all, :conditions => ["name like ?", "#{@year}-#{0 if @month < 10}#{@month}%"]) %>
  <%= calendar(:year => @year, :month => @month){|d| link_to(d.mday, :action => 'tag_search', :id => d) if @dates.include?(d)} %>      
</ul>

見た目も対応。

$ vi app/views/layouts/articles.rhtml
<%= stylesheet_link_tag 'calendar/red/style' %>
$ vi public/stylesheets/calendar/red/style.css
.dayName{
  padding: 0.4em;
  padding-top: 0.2em;
  padding-bottom: 0.2em;
.otherMonth, .day, .specialDay {
  padding: 0.4em;
  padding-top: 0.2em;
  padding-bottom: 0.2em;
トラックバック - http://d.hatena.ne.jp/winplus/20070330/1175266294