]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
initial support for css and threading
authorDavid Bremner <bremner@unb.ca>
Sat, 2 Aug 2008 21:18:05 +0000 (18:18 -0300)
committerDavid Bremner <bremner@unb.ca>
Sun, 3 Aug 2008 12:52:37 +0000 (09:52 -0300)
IkiWiki/Plugin/mailbox.pm
README
test/in/mailbox.css [new file with mode: 0644]

index 6e2939d690851a48f76e3d5374d2d0a520a96c52..09e7a30f90b1563d08a086cbbac9ebc809c89469 100644 (file)
@@ -10,12 +10,27 @@ use warnings;
 use strict;
 use IkiWiki 2.00;
 use Email::Folder;
+use Email::Thread;
 use CGI 'escapeHTML';
+use Data::Dumper;
+
+my %metaheaders;
 
 sub import { #{{{
        hook(type => "preprocess", id => "mailbox", call => \&preprocess);
+       hook(type => "scan", id => "mailbox", call => \&scan);
+       hook(type => "pagetemplate", id=>"mailbox", call => \&pagetemplate);
 } # }}}
 
+sub scan(@){
+       my %params=@_;
+       my $page=$params{page};
+
+       debug('calling scan');
+       push @{$metaheaders{$page}}, 
+              '<link rel="stylesheet" href="mailbox.css" type="text/css"/>'
+}
+
 sub preprocess (@) { #{{{
        my %params=@_;
        
@@ -23,6 +38,11 @@ sub preprocess (@) { #{{{
        my $type=$params{type} || 'maildir';
 
        my $path=$params{path} ||  error gettext("missing parameter") . " path";
+       
+       my $output="";
+
+       # hmm, this should probably only be inserted once per page.
+       $output .= htmllink($page,$page,"mailbox.css",rel=>"stylesheet",type=>"text/css");
 
        # note, mbox is not a directory, needs to be special cased
        my $dir=bestdir($page,$params{path}) || 
@@ -30,8 +50,9 @@ sub preprocess (@) { #{{{
 
        $params{path} = $config{srcdir} ."/" . $dir;
 
-       return  format_mailbox(path=>$dir,%params);
+       $output.=  format_mailbox(path=>$dir,%params);
 
+       return $output;
 } # }}}
 
 
@@ -42,8 +63,36 @@ sub format_mailbox(@){
     my $path=$params{path} || error("path parameter mandatory");
 
     my $folder=Email::Folder->new($path) || error("mailbox could not be opened");
-    return join "\n", map { format_message(message=>$_) } $folder->messages;
+    my $threader=new Email::Thread($folder->messages);
 
+    $threader->thread();
+
+    return join "\n", map { format_thread(thread=>$_) } $threader->rootset;
+}
+
+sub format_thread(@){
+    my %params=@_;
+    
+    my $thread=$params{thread} || error gettext("missing parameter") . "thread";
+
+    my $output="";
+
+    if ($thread->message) {
+       $output .= format_message(message=>$thread->message);
+    } else {
+       $output .= sprintf gettext("Message %s not available"), $thread;
+    }
+
+    if ($thread->child){
+       $output .= '<div class="emailthreadindent">' .
+           format_thread(thread=>$thread->child).
+           '</div>';
+    }
+
+    if ($thread->next){
+       $output .= format_thread(thread=>$thread->next);
+    }
+    return $output;
 }
 
 sub make_pair($$){
@@ -81,7 +130,7 @@ sub format_message(@){
 sub format_body($){
     my $body=shift;
 
-    # it is not completely clear to me the right way to go here.  some
+    # it is not completely clear to me the right way to go here.  
     # passing things straight to markdown is not working all that
     # well.
     return "<pre>".escapeHTML($body)."</pre>";
@@ -120,25 +169,19 @@ sub bestdir ($$) { #{{{
        return "";
 } #}}}
 
-
-
-sub fill_template(@){
-    my  %params=@_;
-    my $template = $params{template} || error gettext("missing parameter");
-
-    $params{basename}=IkiWiki::basename($params{page});
-
-    foreach my $param (keys %params) {
-       if ($template->query(name => $param)) {
-           $template->param($param =>
-                            IkiWiki::htmlize($params{page}, $params{destpage},
-                                             pagetype($pagesources{$params{page}}),
-                                             $params{$param}));
-       }
-       if ($template->query(name => "raw_$param")) {
-           $template->param("raw_$param" => $params{$param});
+sub pagetemplate (@) { #{{{
+       my %params=@_;
+        my $page=$params{page};
+        my $destpage=$params{destpage};
+        my $template=$params{template};
+
+       if (exists $metaheaders{$page} && $template->query(name => "meta")) {
+               # avoid duplicate meta lines
+               my %seen;
+               $template->param(meta => join("\n", grep { (! $seen{$_}) && ($seen{$_}=1) } @{$metaheaders{$page}}));
        }
-    }
 }
 
-1
+
+
+1;
diff --git a/README b/README
index 74c3ca39c85e4da7804ac8f9a6c3400ebed2386a..0712e3474b336d763344f57def904119f839e4de 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,6 @@
 
-Required perl modules
+Required perl modules (only top level dependencies are listed)
 
 Email::Folder
+Email::Thread
+CGI (distributed with perl 5.10.0; maybe before?)
\ No newline at end of file
diff --git a/test/in/mailbox.css b/test/in/mailbox.css
new file mode 100644 (file)
index 0000000..d8d2cf7
--- /dev/null
@@ -0,0 +1,16 @@
+
+/* ikiwiki local style sheet */
+
+/* Add local styling here, instead of modifying style.css. */
+
+
+
+
+.headername {
+font-weight: bold;
+  }
+
+.emailthreadindent{
+position: relative;
+left: 5%;
+}
\ No newline at end of file