]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/progressbar_plugin.mdwn
Add patch
[ikiwiki.git] / doc / todo / progressbar_plugin.mdwn
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.
5
6 Here is proposition of the plugin syntax:
7
8     \[[!progress done=50]]
9
10 Of course, `done` argument is integer from 0 to 100. 
11
12 A here is its HTML result:
13
14     <div class="progress">
15       <div class="progress-done" style="width: 50%">50%</div>
16     </div>
17
18 Note: I was trying with `<span>` tags too, but that tag is inline, so I can't
19 set `width` property for it.
20
21 Default CSS styles for the plugin can be like below:
22
23     div.progress {
24             border: 1px solid #ddd;
25             /* border: 2px solid #ddd; */
26             width: 200px;
27             background: #fff;
28             padding: 2px;
29             /* padding: 0px; */
30             border: 2px solid #aaa;
31             background: #eee;
32     }
33     div.progress-done {
34             height: 14px;
35             background: #ff6600;
36             font-size: 12px;
37             text-align: center;
38             vertical-align: middle;
39     }
40
41 You can use alternative, commented CSS code for `div.progress` if you dislike
42 padding around done strip.
43
44 Any comments? --[[PaweÅ‚|ptecza]]
45
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:
48
49     \[[!progress totalpages="bugs/* and backlink(milestoneB)" donepages="bugs/* and backlink(milestoneB) and !link(bugs/done)"]]
50
51 > to have a progress bar marking how many bugs were compete for a
52 > particular milestone.  -- [[Will]]
53
54 >> Attached is a [[patch]] (well, source) for this.  You also need to add the proposed CSS above to `style.css`.
55 >> At the moment this plugin interacts poorly with the [[plugins/htmlscrubber]] plugin.
56 >> HTMLScrubber plugin removes the `style` attribute from the `progress-done` `div` tag, and so it defaults
57 >> to a width of 100%. -- [[Will]]
58
59     #!/usr/bin/perl
60     package IkiWiki::Plugin::progress;
61     
62     use warnings;
63     use strict;
64     use IkiWiki 2.00;
65     
66     my $percentage_pattern = qr/[0-9]\%/; # pattern to validate percentages
67     
68     sub import { #{{{
69         hook(type => "getsetup", id => "progress", call => \&getsetup);
70         hook(type => "preprocess", id => "progress", call => \&preprocess);
71     } # }}}
72     
73     sub getsetup () { #{{{
74         return 
75                 plugin => {
76                         safe => 1,
77                         rebuild => undef,
78                 },
79     } #}}}
80     
81     sub preprocess (@) { #{{{
82         my %params=@_;
83         
84         my $fill;
85         
86         if (defined $params{percent}) {
87                 $fill = $params{percent};
88                 ($fill) = $fill =~ m/($percentage_pattern)/; # fill is untainted now
89         }
90         elsif (defined $params{totalpages} and defined $params{donepages}) {
91                 add_depends($params{page}, $params{totalpages});
92                 add_depends($params{page}, $params{donepages});
93     
94                 my @pages=keys %pagesources;
95                 my $totalcount=0;
96                 my $donecount=0;
97                 foreach my $page (@pages) {
98                         $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
99                         $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
100                 }
101                 
102                 if ($totalcount == 0) {
103                         $fill = "100%"
104                 } else {
105                         my $number = $donecount/$totalcount*100;
106                         $fill = sprintf("%u%%", $number);
107                 }
108         }
109         else {
110                 error("Missing parameters to progress plugin.  Need either `percent` or `totalpages` and `donepages` parameters.");
111         }
112     
113         return <<EODIV
114     <div class="progress">
115       <div class="progress-done" style="width: $fill">$fill</div>
116     </div>
117     EODIV
118     
119     } # }}}
120     
121     1