From: David Bremner Date: Sat, 2 Aug 2008 21:18:05 +0000 (-0300) Subject: initial support for css and threading X-Git-Tag: 0.4~25 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/00b0d428c741fb81cb0fc846637f5c8a62205e1f initial support for css and threading --- diff --git a/IkiWiki/Plugin/mailbox.pm b/IkiWiki/Plugin/mailbox.pm index 6e2939d69..09e7a30f9 100644 --- a/IkiWiki/Plugin/mailbox.pm +++ b/IkiWiki/Plugin/mailbox.pm @@ -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}}, + '' +} + 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 .= '
' . + format_thread(thread=>$thread->child). + '
'; + } + + 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 "
".escapeHTML($body)."
"; @@ -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 74c3ca39c..0712e3474 100644 --- 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 index 000000000..d8d2cf7df --- /dev/null +++ b/test/in/mailbox.css @@ -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