]> scripts.mit.edu Git - www/ikiwiki.git/commitdiff
add displaytime hook
authorJoey Hess <joey@kodama.kitenet.net>
Mon, 20 Oct 2008 00:12:37 +0000 (20:12 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Mon, 20 Oct 2008 00:12:37 +0000 (20:12 -0400)
Need to use a hook because an exported function cannot be reliably
overridden. The replacement verstion was actually only affecting plugins
loaded after it.

formattime doesn't need a hook, since there's no reason to export it.

IkiWiki.pm
IkiWiki/Plugin/relativedate.pm
doc/plugins/write.mdwn
po/ikiwiki.pot

index 1f4d40d417d3a91056c275eda57538339bf7de96..207ca87fb4d96dbecacddc897015647559d91a62 100644 (file)
@@ -898,12 +898,23 @@ sub abs2rel ($$) { #{{{
 } #}}}
 
 sub displaytime ($;$) { #{{{
 } #}}}
 
 sub displaytime ($;$) { #{{{
-       # Plugins can override this function to mark up the time for
-       # display.
-       return formattime(@_);
+       my $time=shift;
+       my $format=shift;
+       if (exists $hooks{displaytime}) {
+               my $ret;
+               run_hooks(displaytime => sub {
+                       $ret=shift->($time, $format)
+               });
+               return $ret;
+       }
+       else {
+               return formattime($time, $format);
+       }
 } #}}}
 
 sub formattime ($;$) { #{{{
 } #}}}
 
 sub formattime ($;$) { #{{{
+       # Plugins can override this function to mark up the time for
+       # display.
        my $time=shift;
        my $format=shift;
        if (! defined $format) {
        my $time=shift;
        my $format=shift;
        if (! defined $format) {
index 0c9426dda074fc5eb2ded88d82e8387b88e58414..d9d8f7776c18ace866eaef44a690844b5793b556 100644 (file)
@@ -12,6 +12,7 @@ sub import { #{{{
        add_underlay("javascript");
        hook(type => "getsetup", id => "relativedate", call => \&getsetup);
        hook(type => "format", id => "relativedate", call => \&format);
        add_underlay("javascript");
        hook(type => "getsetup", id => "relativedate", call => \&getsetup);
        hook(type => "format", id => "relativedate", call => \&format);
+       hook(type => "displaytime", id => "relativedate", call => \&display);
 } # }}}
 
 sub getsetup () { #{{{
 } # }}}
 
 sub getsetup () { #{{{
@@ -42,7 +43,7 @@ sub include_javascript ($;$) { #{{{
                '" type="text/javascript" charset="utf-8"></script>';
 } #}}}
 
                '" type="text/javascript" charset="utf-8"></script>';
 } #}}}
 
-sub IkiWiki::displaytime ($;$) { #{{{
+sub display ($;$) { #{{{
        my $time=shift;
        my $format=shift;
 
        my $time=shift;
        my $format=shift;
 
index daf70c8e23393d5b860b30e324523da6f46c45ab..856b34ba1e1a262794c54a5684d78acdf2cd00f1 100644 (file)
@@ -196,7 +196,6 @@ generating the page.
 
        hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
 
 
        hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
 
-
 [[Templates|wikitemplates]] are filled out for many different things in
 ikiwiki, like generating a page, or part of a blog page, or an rss feed, or
 a cgi. This hook allows modifying the variables available on those
 [[Templates|wikitemplates]] are filled out for many different things in
 ikiwiki, like generating a page, or part of a blog page, or an rss feed, or
 a cgi. This hook allows modifying the variables available on those
@@ -361,6 +360,13 @@ This hook is called whenever ikiwiki normally saves its state, just before
 the state is saved. The function can save other state, modify values before
 they're saved, etc.
 
 the state is saved. The function can save other state, modify values before
 they're saved, etc.
 
+### displaytime
+
+       hook(type => "displaytime", id => "foo", call => \&display);
+
+This hook can be registered to override the regular `displaytime` function.
+Only the last displaytime hook will be used.
+
 ### renamepage
 
        hook(type => "renamepage", id => "foo", call => \&renamepage);
 ### renamepage
 
        hook(type => "renamepage", id => "foo", call => \&renamepage);
index 89cca9ff4cd2ed617f7e585600da666501c149b3..335575f02713f069bc85fa3566cc770b5e4746c2 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-10-19 19:13-0400\n"
+"POT-Creation-Date: 2008-10-19 20:06-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -48,7 +48,7 @@ msgstr ""
 msgid "You are banned."
 msgstr ""
 
 msgid "You are banned."
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1173
+#: ../IkiWiki/CGI.pm:385 ../IkiWiki/CGI.pm:386 ../IkiWiki.pm:1182
 msgid "Error"
 msgstr ""
 
 msgid "Error"
 msgstr ""
 
@@ -926,12 +926,12 @@ msgstr ""
 msgid "failed to load external plugin needed for %s plugin: %s"
 msgstr ""
 
 msgid "failed to load external plugin needed for %s plugin: %s"
 msgstr ""
 
-#: ../IkiWiki.pm:1156
+#: ../IkiWiki.pm:1165
 #, perl-format
 msgid "preprocessing loop detected on %s at depth %i"
 msgstr ""
 
 #, perl-format
 msgid "preprocessing loop detected on %s at depth %i"
 msgstr ""
 
-#: ../IkiWiki.pm:1665
+#: ../IkiWiki.pm:1674
 msgid "yes"
 msgstr ""
 
 msgid "yes"
 msgstr ""