]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/prettydate.pm
po: back to the cansave hook, as the form validation is not sufficient
[git.ikiwiki.info.git] / IkiWiki / Plugin / prettydate.pm
index 44ffb719e3b8aeb515b814784e52223b71c3f684..e155dd39b88285837007d51cc8da9b219d63be72 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 package IkiWiki::Plugin::prettydate;
 #!/usr/bin/perl
 package IkiWiki::Plugin::prettydate;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
 use warnings;
 no warnings 'redefine';
 use strict;
 use warnings;
 no warnings 'redefine';
 use strict;
@@ -22,7 +22,7 @@ sub default_timetable {
                gettext("early %A morning"),                    # 7
                "",                                             # 8
                "",                                             # 9
                gettext("early %A morning"),                    # 7
                "",                                             # 8
                "",                                             # 9
-               gettext("in mid-morning %A"),                   # 10
+               gettext("mid-morning %A"),                      # 10
                gettext("late %A morning"),                     # 11
                gettext("at lunch time on %A"),                 # 12
                "",                                             # 1
                gettext("late %A morning"),                     # 11
                gettext("at lunch time on %A"),                 # 12
                "",                                             # 1
@@ -39,11 +39,34 @@ sub default_timetable {
        ];
 }
 
        ];
 }
 
-sub import { #{{{
-       hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
-} # }}}
+sub import {
+       hook(type => "getsetup", id => "prettydate", call => \&getsetup);
+       hook(type => "checkconfig", id => "prettydate", call => \&checkconfig);
+}
+
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => 1,
+               },
+               prettydateformat => {
+                       type => "string",
+                       example => '%X, %B %o, %Y',
+                       description => "format to use to display date",
+                       advanced => 1,
+                       safe => 1,
+                       rebuild => 1,
+               },
+               timetable => {
+                       type => "internal",
+                       description => "array of time descriptions",
+                       safe => 1,
+                       rebuild => 1,
+               },
+}
 
 
-sub checkconfig () { #{{{
+sub checkconfig () {
        if (! defined $config{prettydateformat} ||
            $config{prettydateformat} eq '%c') {
                $config{prettydateformat}='%X, %B %o, %Y';
        if (! defined $config{prettydateformat} ||
            $config{prettydateformat} eq '%c') {
                $config{prettydateformat}='%X, %B %o, %Y';
@@ -59,10 +82,14 @@ sub checkconfig () { #{{{
                        $config{timetable}[$h] = $config{timetable}[$h - 1];
                }
        }
                        $config{timetable}[$h] = $config{timetable}[$h - 1];
                }
        }
-} #}}}
+}
 
 
-sub IkiWiki::displaytime ($) { #{{{
+sub IkiWiki::formattime ($;$) {
        my $time=shift;
        my $time=shift;
+       my $format=shift;
+       if (! defined $format) {
+               $format=$config{prettydateformat};
+       }
        
        eval q{use Date::Format};
        error($@) if $@;
        
        eval q{use Date::Format};
        error($@) if $@;
@@ -93,9 +120,8 @@ sub IkiWiki::displaytime ($) { #{{{
 
        $t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime("%A", \@yest)}eg;
 
 
        $t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime("%A", \@yest)}eg;
 
-       my $format=$config{prettydateformat};
        $format=~s/\%X/$t/g;
        return strftime($format, \@t);
        $format=~s/\%X/$t/g;
        return strftime($format, \@t);
-} #}}}
+}
 
 1
 
 1