# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # You can redistribute it and/or modify it under the terms of the GNU GPL 2. $LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..' require 'qwik/site-oldplan' module Qwik class Action D_PluginOldPlan = { :dt => 'Show oldplan plugin', :dd => 'You can show the oldplan of this group.', :dc => "* Example {{oldplan}} {{oldplan}} You can see oldplans of this group. If there are no oldplan for this group, you see nothing. " } D_PluginOldPlan_ja = { :dt => '過去の予定表示プラグイン', :dd => '過去の予定を表示します。', :dc => '* 例 {{oldlan}} {{oldplan}} もし過去の予定が登録されている場合は、このプラグインで表示されます。 * 予定の登録方法 サイドメニューに予定が表示されるようになります。 過去の予定は表示されません。また一年以上先の予定も表示されません。 一ヶ月先程度の予定を登録してみてください。 ' } def plg_side_oldplan div = [:div, [:h2, _('OldPlan')]] pages = @site.get_pages_with_date div << oldplan_make_html(pages) if ! pages.empty? div << [:p, plg_oldplan] return div end def plg_oldplan div = [:div, [:h2, _('OldPlan')]] pages = @site.get_pages_with_date return if pages.empty? div << oldplan_make_html(pages) return div end def oldplan_make_html(pages) day = 60 * 60 * 24 nowi = Time.now.to_i pages = pages.select {|pagekey, datei| page = @site[pagekey] diff = datei - nowi -day > diff } return nil if pages.empty? ul = [] pages.sort_by {|pagekey, datei| datei }.each {|pagekey, datei| page = @site[pagekey] title = page.get_title date = Time.at(datei) now = Time.at(nowi) date_abbr = Time.date_abbr(now, date) em_title = Time.date_emphasis(now, date, title) ul.unshift([:li, "#{date_abbr} ", [:a, {:href=>"#{pagekey}.html"}, em_title]]) } ul.unshift(:ul) return ul end end end if $0 == __FILE__ require 'qwik/test-common' $test = true end if defined?($test) && $test class TestActOldPlan < Test::Unit::TestCase include TestSession def create_oldplan_pages(site) page = site.create 'plan_19700101' page.store("* t") page = site.create 'plan_19700115' page.store("* t") page = site.create 'plan_19700201' page.store("* t") page = site.create 'plan_19710101' page.store("* t") end def test_plg_oldplan ok_wi([], '{{oldplan}}') create_oldplan_pages(@site) ok_wi [:div, [:h2, "OldPlan"], [:ul, [:li, "1971-01-01 ", [:a, {:href=>"plan_19710101.html"}, [:span, {:class=>"past"}, "t"]]], [:li, "1970-02-01 ", [:a, {:href=>"plan_19700201.html"}, [:span, {:class=>"past"}, "t"]]], [:li, "1970-01-15 ", [:a, {:href=>"plan_19700115.html"}, [:span, {:class=>"past"}, "t"]]], [:li, "1970-01-01 ", [:a, {:href=>"plan_19700101.html"}, [:span, {:class=>"past"}, "t"]]]]], '{{oldplan}}' # $KCODE = 'n' eq "\211\337\213\216\202\314\227\\\222\350",'過去の予定' end def ok_date(num, date) assert_equal(num, Time.parse(date).to_i + Time::now.utc_offset) end def test_parsedate ok_date 0, '1970-01-01' ok_date 0, '19700101' ok_date 0, '1970/01/01' ok_date 0, '1970/1/1' end end end