]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/theme.pm
discount markdown can't handle URIs with parens e.g. mediawiki style
[git.ikiwiki.info.git] / IkiWiki / Plugin / theme.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::theme;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9         hook(type => "getsetup", id => "theme", call => \&getsetup);
10         hook(type => "checkconfig", id => "theme", call => \&checkconfig);
11         hook(type => "needsbuild", id => "theme", call => \&needsbuild);
12         hook(type => "pagetemplate", id => "theme", call => \&pagetemplate);
13 }
15 sub getsetup () {
16         return
17                 plugin => {
18                         safe => 1,
19                         rebuild => 0,
20                         section => "web",
21                 },
22                 theme => {
23                         type => "string",
24                         example => "actiontabs",
25                         description => "name of theme to enable",
26                         safe => 1,
27                         rebuild => 0,
28                 },
29 }
31 my $added=0;
32 sub checkconfig () {
33         if (! $added && exists $config{theme} && $config{theme} =~ /^\w+$/) {
34                 add_underlay("themes/".$config{theme});
35                 $added=1;
36         }
37 }
39 sub needsbuild ($) {
40         my $needsbuild=shift;
41         if (($config{theme} || '') ne ($wikistate{theme}{currenttheme} || '')) {
42                 # theme changed; ensure all files in the theme are built
43                 my %needsbuild=map { $_ => 1 } @$needsbuild;
44                 if ($config{theme}) {
45                         foreach my $file (glob("$config{underlaydirbase}/themes/$config{theme}/*")) {
46                                 if (-f $file) {
47                                         my $f=IkiWiki::basename($file);
48                                         push @$needsbuild, $f
49                                                 unless $needsbuild{$f};
50                                 }
51                         }
52                 }
53                 elsif ($wikistate{theme}{currenttheme}) {
54                         foreach my $file (glob("$config{underlaydirbase}/themes/$wikistate{theme}{currenttheme}/*")) {
55                                 my $f=IkiWiki::basename($file);
56                                 if (-f $file && defined eval { srcfile($f) }) {
57                                         push @$needsbuild, $f;
58                                 }
59                         }
60                 }
61                 
62                 $wikistate{theme}{currenttheme}=$config{theme};
63         }
64         return $needsbuild;
65 }
67 sub pagetemplate (@) {
68         my %params=@_;
69         my $template=$params{template};
70         if (exists $config{theme} && length $config{theme})  {
71                 $template->param("theme_$config{theme}" => 1);
72         }
73 }
75 1