]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/incomplete_patch.pl
the incomplete patch for the map plugin
[ikiwiki.git] / doc / todo / incomplete_patch.pl
1 diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
2 index 38f090f..6b884cd 100644
3 --- a/IkiWiki/Plugin/map.pm
4 +++ b/IkiWiki/Plugin/map.pm
5 @@ -25,6 +25,42 @@ sub getsetup () {
6                 },
7  }
8  
9 +sub strategy_byparents (@) {
10 +       # Sort by parents only
11 +       #
12 +       # With this strategy, children are sorted *under* their parents
13 +       # regardless of their own position, and the parents' positions are
14 +       # determined only by comparing the parents themselves.
15 +
16 +       # FIXME this is *not* what's described above, but the old behavior (for
17 +       # testing/comparison)
18 +       use sort 'stable';
19 +       my (@sequence,) = @_;
20 +       @sequence = sort @sequence;
21 +       return @sequence;
22 +}
23 +
24 +sub strategy_forcedsequence (@) {
25 +       # Forced Sequence Mode
26 +       #
27 +       # Using this strategy, all entries will be shown in the sequence; this
28 +       # can cause parents to show up multiple times.
29 +       #
30 +       # The only reason why this is not the identical function is that
31 +       # parents that are sorted between their children are bubbled up to the
32 +       # top of their contiguous children to avoid being repeated in the
33 +       # output.
34 +
35 +       use sort 'stable';
36 +
37 +       my (@sequence,) = @_;
38 +       # FIXME: i'm surprised that this actually works. i'd expect this to
39 +       # work with bubblesort, but i'm afraid that this may just not yield the
40 +       # correct results with mergesort.
41 +       @sequence = sort {($b eq substr($a, 0, length($b))) - ($a eq substr($b, 0, length($a)))} @sequence;
42 +       return @sequence;
43 +}
44 +
45  sub preprocess (@) {
46         my %params=@_;
47         $params{pages}="*" unless defined $params{pages};
48 @@ -37,8 +73,11 @@ sub preprocess (@) {
49  
50         # Get all the items to map.
51         my %mapitems;
52 +       my @mapsequence;
53         foreach my $page (pagespec_match_list($params{page}, $params{pages},
54 -                                       deptype => $deptype)) {
55 +                                       deptype => $deptype,
56 +                                       sort => exists $params{sort} ? $params{sort} : "title")) {
57 +               push(@mapsequence, $page);
58                 if (exists $params{show} && 
59                     exists $pagestate{$page} &&
60                     exists $pagestate{$page}{meta}{$params{show}}) {
61 @@ -88,7 +127,15 @@ sub preprocess (@) {
62                 $map .= "<ul>\n";
63         }
64  
65 -       foreach my $item (sort keys %mapitems) {
66 +       if (!exists $params{strategy} || $params{strategy} eq "parent") {
67 +               @mapsequence = strategy_byparents(@mapsequence);
68 +       } elsif ($params{strategy} eq "forced") {
69 +               @mapsequence = strategy_forcedsequence(@mapsequence);
70 +       } else {
71 +               error("Unknown strategy.");
72 +       }
73 +
74 +       foreach my $item (@mapsequence) {
75                 my @linktext = (length $mapitems{$item} ? (linktext => $mapitems{$item}) : ());
76                 $item=~s/^\Q$common_prefix\E\///
77                         if defined $common_prefix && length $common_prefix;