1 I would like to add next plugin to Ikiwiki. It's `progressbar` or simply `progress`.
2 I'm not sure what plugin name better is, probably that shorter ;) I know that
3 [DokuWiki](http://wiki.splitbrain.org/plugin:progressbar) has similar plugin,
4 so I think it can be useful also for Ikiwiki users.
6 Here is proposition of the plugin syntax:
10 Of course, `done` argument is integer from 0 to 100.
12 A here is its HTML result:
14 <div class="progress">
15 <div class="progress-done" style="width: 50%">50%</div>
18 Note: I was trying with `<span>` tags too, but that tag is inline, so I can't
19 set `width` property for it.
21 Default CSS styles for the plugin can be like below:
24 border: 1px solid #ddd;
25 /* border: 2px solid #ddd; */
30 border: 2px solid #aaa;
38 vertical-align: middle;
41 You can use alternative, commented CSS code for `div.progress` if you dislike
42 padding around done strip.
44 Any comments? --[[Paweł|ptecza]]
46 > This looks like a nice idea. If I could add one further suggestion: Allow your
47 > ratio to be a pair of pagespecs. Then you could have something like:
49 \[[!progress totalpages="bugs/* and backlink(milestoneB)" donepages="bugs/* and backlink(milestoneB) and !link(bugs/done)"]]
51 > to have a progress bar marking how many bugs were compete for a
52 > particular milestone. -- [[Will]]
54 >> Thanks a lot for your comment, Will! It seems very interesting for me.
55 >> I need to think more about improving that plugin. --[[Paweł|ptecza]]
57 >> Attached is a [[patch]] (well, source) for this. You also need to add the proposed CSS above to `style.css`.
58 >> At the moment this plugin interacts poorly with the [[plugins/htmlscrubber]] plugin.
59 >> HTMLScrubber plugin removes the `style` attribute from the `progress-done` `div` tag, and so it defaults
60 >> to a width of 100%. -- [[Will]]
62 >>> Thank you for the code! I know how to fix that problem, because I had
63 >>> the same issue while writing [[todo/color_plugin]] :) --[[Paweł|ptecza]]
66 package IkiWiki::Plugin::progress;
72 my $percentage_pattern = qr/[0-9]+\%/; # pattern to validate percentages
75 hook(type => "getsetup", id => "progress", call => \&getsetup);
76 hook(type => "preprocess", id => "progress", call => \&preprocess);
79 sub getsetup () { #{{{
87 sub preprocess (@) { #{{{
92 if (defined $params{percent}) {
93 $fill = $params{percent};
94 ($fill) = $fill =~ m/($percentage_pattern)/; # fill is untainted now
96 elsif (defined $params{totalpages} and defined $params{donepages}) {
97 add_depends($params{page}, $params{totalpages});
98 add_depends($params{page}, $params{donepages});
100 my @pages=keys %pagesources;
103 foreach my $page (@pages) {
104 $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
105 $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
108 if ($totalcount == 0) {
111 my $number = $donecount/$totalcount*100;
112 $fill = sprintf("%u%%", $number);
116 error("Missing parameters to progress plugin. Need either `percent` or `totalpages` and `donepages` parameters.");
120 <div class="progress">
121 <div class="progress-done" style="width: $fill">$fill</div>