From b1daba6e9b0201d55926f8590035989df016e947 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 6 Aug 2008 00:55:29 +0200 Subject: clone plugin sidebar as branding, farbar, footer, and topbar [2/2] --- IkiWiki/Plugin/branding.pm | 63 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'IkiWiki/Plugin/branding.pm') diff --git a/IkiWiki/Plugin/branding.pm b/IkiWiki/Plugin/branding.pm index c1146b7..e1dd79e 100644 --- a/IkiWiki/Plugin/branding.pm +++ b/IkiWiki/Plugin/branding.pm @@ -1,17 +1,18 @@ #!/usr/bin/perl -# Sidebar plugin. -# by Tuomo Valkonen +# Branding plugin. +# by Jonas Smedegaard +# Heavily based on Sidebar by Tuomo Valkonen -package IkiWiki::Plugin::sidebar; +package IkiWiki::Plugin::branding; use warnings; use strict; use IkiWiki 3.00; sub import { - hook(type => "getsetup", id => "sidebar", call => \&getsetup); - hook(type => "preprocess", id => "sidebar", call => \&preprocess); - hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate); + hook(type => "getsetup", id => "branding", call => \&getsetup); + hook(type => "preprocess", id => "branding", call => \&preprocess); + hook(type => "pagetemplate", id => "branding", call => \&pagetemplate); } sub getsetup () { @@ -20,16 +21,16 @@ sub getsetup () { safe => 1, rebuild => 1, }, - global_sidebars => { + global_brandings => { type => "boolean", example => 1, - description => "show sidebar page on all pages?", + description => "show branding page on all pages?", safe => 1, rebuild => 1, }, } -my %pagesidebar; +my %pagebranding; sub preprocess (@) { my %params=@_; @@ -38,13 +39,13 @@ sub preprocess (@) { return "" unless $page eq $params{destpage}; if (! defined $params{content}) { - $pagesidebar{$page}=undef; + $pagebranding{$page}=undef; } else { my $file = $pagesources{$page}; my $type = pagetype($file); - $pagesidebar{$page}= + $pagebranding{$page}= IkiWiki::htmlize($page, $page, $type, IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, $params{content}))); @@ -56,39 +57,39 @@ sub preprocess (@) { my $oldfile; my $oldcontent; -sub sidebar_content ($) { +sub branding_content ($) { my $page=shift; - return delete $pagesidebar{$page} if defined $pagesidebar{$page}; + return delete $pagebranding{$page} if defined $pagebranding{$page}; - return if ! exists $pagesidebar{$page} && - defined $config{global_sidebars} && ! $config{global_sidebars}; + return if ! exists $pagebranding{$page} && + defined $config{global_brandings} && ! $config{global_brandings}; - my $sidebar_page=bestlink($page, "sidebar") || return; - my $sidebar_file=$pagesources{$sidebar_page} || return; - my $sidebar_type=pagetype($sidebar_file); + my $branding_page=bestlink($page, "branding") || return; + my $branding_file=$pagesources{$branding_page} || return; + my $branding_type=pagetype($branding_file); - if (defined $sidebar_type) { + if (defined $branding_type) { # FIXME: This isn't quite right; it won't take into account - # adding a new sidebar page. So adding such a page + # adding a new branding page. So adding such a page # currently requires a wiki rebuild. - add_depends($page, $sidebar_page); + add_depends($page, $branding_page); my $content; - if (defined $oldfile && $sidebar_file eq $oldfile) { + if (defined $oldfile && $branding_file eq $oldfile) { $content=$oldcontent; } else { - $content=readfile(srcfile($sidebar_file)); + $content=readfile(srcfile($branding_file)); $oldcontent=$content; - $oldfile=$sidebar_file; + $oldfile=$branding_file; } return unless length $content; - return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type, - IkiWiki::linkify($sidebar_page, $page, - IkiWiki::preprocess($sidebar_page, $page, - IkiWiki::filter($sidebar_page, $page, $content)))); + return IkiWiki::htmlize($branding_page, $page, $branding_type, + IkiWiki::linkify($branding_page, $page, + IkiWiki::preprocess($branding_page, $page, + IkiWiki::filter($branding_page, $page, $content)))); } } @@ -98,10 +99,10 @@ sub pagetemplate (@) { my $template=$params{template}; if ($params{destpage} eq $params{page} && - $template->query(name => "sidebar")) { - my $content=sidebar_content($params{destpage}); + $template->query(name => "branding")) { + my $content=branding_content($params{destpage}); if (defined $content && length $content) { - $template->param(sidebar => $content); + $template->param(branding => $content); } } } -- cgit v1.2.3