add paths to plugin files in copyright
[ikiwiki.git] / IkiWiki / Plugin / theme.pm
blobee94547e90c51dad608b020e1be6bc0a434d38d7
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);
14 sub getsetup () {
15 return
16 plugin => {
17 safe => 1,
18 rebuild => 0,
19 section => "web",
21 theme => {
22 type => "string",
23 example => "actiontabs",
24 description => "name of theme to enable",
25 safe => 1,
26 rebuild => 0,
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;
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};
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;
61 $wikistate{theme}{currenttheme}=$config{theme};
63 return $needsbuild;