]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/theme.pm
Remember to run all the tests before committing!
[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 }
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 0,
19                         section => "web",
20                 },
21                 theme => {
22                         type => "string",
23                         example => "actiontabs",
24                         description => "name of theme to enable",
25                         safe => 1,
26                         rebuild => 0,
27                 },
28 }
30 my $added=0;
31 sub checkconfig () {
32         if (! $added && exists $config{theme} && $config{theme} =~ /^\w+$/) {
33                 add_underlay("themes/".$config{theme});
34                 $added=1;
35         }
36 }
38 sub needsbuild ($) {
39         my $needsbuild=shift;
40         if (($config{theme} || '') ne ($wikistate{theme}{currenttheme} || '')) {
41                 # theme changed; ensure all files in the theme are built
42                 my %needsbuild=map { $_ => 1 } @$needsbuild;
43                 if ($config{theme}) {
44                         foreach my $file (glob("$config{underlaydirbase}/themes/$config{theme}/*")) {
45                                 if (-f $file) {
46                                         my $f=IkiWiki::basename($file);
47                                         push @$needsbuild, $f
48                                                 unless $needsbuild{$f};
49                                 }
50                         }
51                 }
52                 elsif ($wikistate{theme}{currenttheme}) {
53                         foreach my $file (glob("$config{underlaydirbase}/themes/$wikistate{theme}{currenttheme}/*")) {
54                                 my $f=IkiWiki::basename($file);
55                                 if (-f $file && defined eval { srcfile($f) }) {
56                                         push @$needsbuild, $f;
57                                 }
58                         }
59                 }
60                 
61                 $wikistate{theme}{currenttheme}=$config{theme};
62         }
63         return $needsbuild;
64 }
66 1