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 > In the poll plugin, I ended up using a `<hr>` for the progress-like
22 > thing. One reason I did so is because it actually works in text-mode
23 > browsers (w3m, lynx), that do not support css or colorized
24 > divs. Since the hr is an element they display, just setting its width can
25 > make a basic progress-type display. The style then makes it display
26 > better in more capable browsers.
28 > The other advantage to that approach is that the htmlscrubber lets
29 > through the `class` and `width` fields, that are all that are needed for
30 > it to work. No need to work around htmlscrubber.
32 > So I suggest adapting this to use similar html. --[[Joey]]
34 Default CSS styles for the plugin can be like below:
37 border: 1px solid #ddd;
38 /* border: 2px solid #ddd; */
43 border: 2px solid #aaa;
51 vertical-align: middle;
54 > Please make sure to always set a foreground color if a background color is
55 > set, and use '!important' so the foreground color can be overridden. (CSS
56 > best practices) --[[Joey]]
58 You can use alternative, commented CSS code for `div.progress` if you dislike
59 padding around done strip.
61 Any comments? --[[Paweł|ptecza]]
63 > This looks like a nice idea. If I could add one further suggestion: Allow your
64 > ratio to be a pair of pagespecs. Then you could have something like:
66 \[[!progress totalpages="bugs/* and backlink(milestoneB)" donepages="bugs/* and backlink(milestoneB) and !link(bugs/done)"]]
68 > to have a progress bar marking how many bugs were compete for a
69 > particular milestone. -- [[Will]]
71 >> Thanks a lot for your comment, Will! It seems very interesting for me.
72 >> I need to think more about improving that plugin. --[[Paweł|ptecza]]
74 >> Attached is a [[patch]] (well, source) for this. You also need to add the proposed CSS above to `style.css`.
75 >> At the moment this plugin interacts poorly with the [[plugins/htmlscrubber]] plugin.
76 >> HTMLScrubber plugin removes the `style` attribute from the `progress-done` `div` tag, and so it defaults
77 >> to a width of 100%. -- [[Will]]
79 >>> Thank you for the code! I know how to fix that problem, because I had
80 >>> the same issue while writing [[todo/color_plugin]] :) --[[Paweł|ptecza]]
82 >>>> Ahh - good idea. Patch updated to work with HTMLScrubber. --[[Will]]
84 >>>>> I like it, but I think that Joey should take a look at that patch too :)
85 >>>>> --[[Paweł|ptecza]]
88 package IkiWiki::Plugin::progress;
94 my $percentage_pattern = qr/[0-9]+\%/; # pattern to validate percentages
97 hook(type => "getsetup", id => "progress", call => \&getsetup);
98 hook(type => "preprocess", id => "progress", call => \&preprocess);
99 hook(type => "format", id => "progress", call => \&format);
102 sub getsetup () { #{{{
110 sub preprocess (@) { #{{{
115 if (defined $params{percent}) {
116 $fill = $params{percent};
117 ($fill) = $fill =~ m/($percentage_pattern)/; # fill is untainted now
119 elsif (defined $params{totalpages} and defined $params{donepages}) {
120 add_depends($params{page}, $params{totalpages});
121 add_depends($params{page}, $params{donepages});
123 my @pages=keys %pagesources;
126 foreach my $page (@pages) {
127 $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
128 $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
131 if ($totalcount == 0) {
134 my $number = $donecount/$totalcount*100;
135 $fill = sprintf("%u%%", $number);
139 error("Missing parameters to progress plugin. Need either `percent` or `totalpages` and `donepages` parameters.");
143 <div class="progress">
144 <div class="progress-done" style="width: $fill">$fill</div>
153 # If HTMLScrubber has removed the style attribute, then bring it back
155 $params{content} =~ s!<div class="progress-done">($percentage_pattern)</div>!<div class="progress-done" style="width: $1">$1</div>!g;
157 return $params{content};
162 Here is a potential documentation page:
166 [[!template id=plugin name=progress author="[[Will]]"]]
169 Provides a \\[[!progress ]] [[ikiwiki/PreProcessorDirective]] that is
170 replaced with a progress bar.
172 There are two possible parameter sets. The first is a single parameter
173 `percent` which holds a percentage figure for how complete the progress bar is.
175 The second possible set of parameters is a pair of [[ikiwiki/PageSpec]]s,
176 `totalpages` and `donepages`. The progress plugin counts the number of
177 pages in each pagespec and shows the percentage of the total pages that are
180 This plugin is included in ikiwiki, but is not enabled by default.
182 If it is turned on it can show what percentage of pages have discussion pages:
184 \[[!progress totalpages="* and !*/Discussion" donepages="*/Discussion"]]