# calendar3.rb $Revision: 1.37.2.1 $ # # calendar3: 現在表示している月のカレンダーを表示します. # パラメタ: なし # # tdiary.confで指定するオプション: # @options['calendar3.show_todo'] # パラグラフのサブサイトルとここで指定した文字列が一致し # かつその日の日記が非表示の場合,そのパラグラフの内容を # 予定としてpopupする. # # @options['calendar3.show_popup'] # JavaScriptによるpopupを表示するかどうか. # 省略時の値はtrueなので,表示したくない場合のみfalseを設定する. # # Copyright (c) 2001,2002 Junichiro KITA # Distributed under the GPL # # # sample CSS for calendar3 # # .calendar-popup { # display: none; # text-align: left; # position: absolute; # border-style: solid; # border-width: 1px; # padding: 0 1ex 0 1ex; # } # # .calendar-sunday { # color: red; # } # # .calendar-saturday { # color: blue; # } # # .calendar-weekday { # color: black; # } # # .calendar-normal { # } # # .calendar-day { # font-weight: bold; # } # # .calendar-todo { # border-style: solid; # border-color: red; # border-width: 1px; # } # =begin ChengeLog 2003-09-25 TADA Tadashi * use @conf.shorten. 2003-03-25 Junichiro Kita * add css to navigation links to next, current, prev month. 2003-02-27 Junichiro Kita * @options['calendar.show_popup'] 2003-01-07 Junichiro Kita * append sample css 2003-01-07 MURAI Kensou * modify javascript for popdown-delay 2002-12-20 TADA Tadashi * use Plugin#apply_plugin. =end module Calendar3 WEEKDAY = 0 SATURDAY = 1 SUNDAY = 2 STYLE = { WEEKDAY => "calendar-weekday", SATURDAY => "calendar-saturday", SUNDAY => "calendar-sunday", } def make_cal(year, month) result = [] 1.upto(31) do |i| t = Time.local(year, month, i) break if t.month != month case t.wday when 0 result << [i, SUNDAY] when 1..5 result << [i, WEEKDAY] when 6 result << [i, SATURDAY] end end result end def prev_month(year, month) if month == 1 year -= 1 month = 12 else month -= 1 end [year, month] end def next_month(year, month) if month == 12 year += 1 month = 1 else month += 1 end [year, month] end module_function :make_cal, :next_month, :prev_month end def calendar3 return '' if bot? show_todo = @options['calendar3.show_todo'] show_todo = Regexp.new(show_todo) if show_todo result = '' if @options.has_key? 'calendar3.erb' result << %Q|

@options['calendar3.erb'] is obsolete!

| end if @mode == 'latest' date = Time.now else date = @date end year = date.year month = date.month day = date.day result << %Q|<<\n| result << %Q|#{"%04d/%02d" % [year, month]}/\n| #Calendar3.make_cal(year, month)[(day - num >= 0 ? day - num : 0)..(day - 1)].each do |day, kind| Calendar3.make_cal(year, month).each do |day, kind| date = "%04d%02d%02d" % [year, month, day] if @diaries[date].nil? result << %Q|#{day}\n| elsif !@diaries[date].visible? todos = [] if show_todo @diaries[date].each_section do |section| if show_todo === section.subtitle todos << CGI::escapeHTML(section.body_to_html).gsub(/\n/, " ") end end end if todos.size != 0 result << %Q|#{day}\n| else result << %Q|#{day}\n| end else if @calendar3_show_popup result << %Q|\n| else result << %Q|\n| end result << %Q| #{day}\n| if @calendar3_show_popup result << %Q| \n| i = 1 if !@plugin_files.grep(/\/category.rb$/).empty? and @diaries[date].categorizable? @diaries[date].each_section do |section| if section.stripped_subtitle text = apply_plugin( section.body_to_html, true ) subtitle = apply_plugin( section.stripped_subtitle_to_html ) result << %Q| #{i}. #{subtitle}
\n| end i += 1 end else @diaries[date].each_section do |section| if section.subtitle text = apply_plugin( section.body_to_html, true ) subtitle = apply_plugin( section.subtitle_to_html ) result << %Q| #{i}. #{subtitle}
\n| end i += 1 end end result << %Q|
\n| end result << %Q|
\n| end end result << %Q|>>\n| result end @calendar3_show_popup = true if @options.has_key?('calendar3.show_popup') @calendar3_show_popup = @options['calendar3.show_popup'] end if /w3m|MSIE.*Mac/ === @cgi.user_agent @calendar3_show_popup = false add_header_proc do < JAVASCRIPT end end if @calendar3_show_popup add_header_proc do < JAVASCRIPT end end # vim: set ts=3: