]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/Add_DATE_parameter_for_use_in_templates.mdwn
comments
[ikiwiki.git] / doc / todo / Add_DATE_parameter_for_use_in_templates.mdwn
1 I sometimes want to inline things with the complete date and time, and
2 sometimes need only the date. I know about the prettydate plugin that
3 already makes the time a bit "nicer" to read, but sometimes I just
4 don't want it at all.
5
6 Here's a patch to add a DATE parameter for use in templates as
7 controlled by a Tdateformat setting in the setup.
8
9 I explicitly did not edit any date-related plugins, (for fear of
10 breaking them as I don't use them so I wouldn't be testing them). But
11 it occurs to me that it might be correct to not touch them anyway,
12 (since things like prettydate are really more concerned with changing
13 the presentation of the time, not the date).
14
15 I also didn't edit the sample setup file, (since I'm just using a git
16 repository setup on my local /usr/share/perl5/IkiWiki directory
17 here). But, ah, now that I look, I do see that there's a "real" git
18 repository advertised with the ikiwiki source. I'll have to start
19 using that for future patches, (so let me know if you want me to
20 regenerate this one against that).
21
22 -Carl
23
24         From 325d208d8dc8016a377bb7c923a51af2bd3355b0 Mon Sep 17 00:00:00 2001
25         From: Carl Worth <cworth@cworth.org>
26         Date: Tue, 3 Jul 2007 11:39:03 -0700
27         Subject: [PATCH] Allow DATE as a template parameter (with format controlled by dateformat setting)
28
29         ---
30          IkiWiki.pm       |   12 +++++++++++-
31          Plugin/inline.pm |    1 +
32          2 files changed, 12 insertions(+), 1 deletions(-)
33
34         diff --git a/IkiWiki.pm b/IkiWiki.pm
35         index cd42e8d..ebf0474 100644
36         --- a/IkiWiki.pm
37         +++ b/IkiWiki.pm
38         @@ -16,7 +16,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
39          use Exporter q{import};
40          our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
41                           bestlink htmllink readfile writefile pagetype srcfile pagename
42         -                 displaytime will_render gettext urlto targetpage
43         +                 displaytime displaydate will_render gettext urlto targetpage
44                           %config %links %renderedfiles %pagesources %destsources);
45          our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
46          our $version="2.1";my $installdir="/usr";
47         @@ -70,6 +70,7 @@ sub defaultconfig () {
48                 plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
49                               lockedit conditional}],
50                 timeformat => '%c',
51         +       dateformat => '%x',
52                 locale => undef,
53                 sslcookie => 0,
54                 httpauth => 0,
55         @@ -447,6 +448,15 @@ sub displaytime ($) {
56                                 $config{timeformat}, localtime($time)));
57          }
58
59         +sub displaydate ($) {
60         +       my $time=shift;
61         +
62         +       # strftime doesn't know about encodings, so make sure
63         +       # its output is properly treated as utf8
64         +       return decode_utf8(POSIX::strftime(
65         +                       $config{dateformat}, localtime($time)));
66         +}
67         +
68          sub beautify_url ($) {
69                 my $url=shift;
70
71         diff --git a/Plugin/inline.pm b/Plugin/inline.pm
72         index 8f6ab51..7bd6147 100644
73         --- a/Plugin/inline.pm
74         +++ b/Plugin/inline.pm
75         @@ -148,6 +148,7 @@ sub preprocess_inline (@) {
76                                 $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
77                                 $template->param(title => pagetitle(basename($page)));
78                                 $template->param(ctime => displaytime($pagectime{$page}));
79         +                       $template->param(date => displaydate($pagectime{$page}));
80
81                                 if ($actions) {
82                                         my $file = $pagesources{$page};
83         -- 
84         1.5.2.2
85
86 [[!tag patch patch/core plugins/inline]]