2 package IkiWiki::Plugin::progress;
8 my $percentage_pattern = qr/[0-9]+\%/; # pattern to validate percentages
11 hook(type => "getsetup", id => "progress", call => \&getsetup);
12 hook(type => "preprocess", id => "progress", call => \&preprocess);
13 hook(type => "format", id => "progress", call => \&format);
16 sub getsetup () { #{{{
24 sub preprocess (@) { #{{{
29 if (defined $params{percent}) {
30 $fill = $params{percent};
31 ($fill) = $fill =~ m/($percentage_pattern)/; # fill is untainted now
33 elsif (defined $params{totalpages} and defined $params{donepages}) {
34 add_depends($params{page}, $params{totalpages});
35 add_depends($params{page}, $params{donepages});
37 my @pages=keys %pagesources;
40 foreach my $page (@pages) {
41 $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
42 $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
45 if ($totalcount == 0) {
49 my $number = $donecount/$totalcount*100;
50 $fill = sprintf("%u%%", $number);
54 error("need either `percent` or `totalpages` and `donepages` parameters");
58 <div class="progress">
59 <div class="progress-done" style="width: $fill">$fill</div>
67 # If HTMLScrubber has removed the style attribute, then bring it back
69 $params{content} =~ s!<div class="progress-done">($percentage_pattern)</div>!<div class="progress-done" style="width: $1">$1</div>!g;
71 return $params{content};