--- /dev/null
+#!/usr/bin/perl
+# -*- cperl-indent-level: 8; -*-
+# Ikiwiki pedigree plugin.
+package IkiWiki::Plugin::pedigree;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import { #{{{
+ hook(type => "pagetemplate", id => "pedigree", call => \&pagetemplate);
+} # }}}
+
+sub pedigree ($) { #{{{
+ my $page=shift;
+
+ my @ret;
+ my $path="";
+ my $title=$config{wikiname};
+ my $i=0;
+ my $depth=0;
+ my $height=0;
+
+ my @pagepath=(split("/", $page));
+ my $pagedepth=@pagepath;
+ foreach my $dir (@pagepath) {
+ next if $dir eq 'index';
+ $depth=$i;
+ $height=($pagedepth - $depth);
+ push @ret, {
+ url => urlto($path, $page),
+ page => $title,
+ depth => $depth,
+ height => $height,
+ "depth_$depth" => 1,
+ "height_$height" => 1,
+ };
+ $path.="/".$dir;
+ $title=IkiWiki::pagetitle($dir);
+ $i++;
+ }
+ return @ret;
+} #}}}
+
+sub pagetemplate (@) { #{{{
+ my %params=@_;
+ my $page=$params{page};
+ my $template=$params{template};
+
+ if ($template->query(name => "pedigree")) {
+ $template->param(pedigree => [pedigree($page)]);
+ }
+} # }}}
+
+1
+++ /dev/null
-#!/usr/bin/perl
-# -*- cperl-indent-level: 8; -*-
-# Ikiwiki pedigree plugin.
-package IkiWiki::Plugin::pedigree;
-
-use warnings;
-use strict;
-use IkiWiki 2.00;
-
-sub import { #{{{
- hook(type => "pagetemplate", id => "pedigree", call => \&pagetemplate);
-} # }}}
-
-sub pedigree ($) { #{{{
- my $page=shift;
-
- my @ret;
- my $path="";
- my $title=$config{wikiname};
- my $i=0;
- my $depth=0;
- my $height=0;
-
- my @pagepath=(split("/", $page));
- my $pagedepth=@pagepath;
- foreach my $dir (@pagepath) {
- next if $dir eq 'index';
- $depth=$i;
- $height=($pagedepth - $depth);
- push @ret, {
- url => urlto($path, $page),
- page => $title,
- depth => $depth,
- height => $height,
- "depth_$depth" => 1,
- "height_$height" => 1,
- };
- $path.="/".$dir;
- $title=IkiWiki::pagetitle($dir);
- $i++;
- }
- return @ret;
-} #}}}
-
-sub pagetemplate (@) { #{{{
- my %params=@_;
- my $page=$params{page};
- my $template=$params{template};
-
- if ($template->query(name => "pedigree")) {
- $template->param(pedigree => [pedigree($page)]);
- }
-} # }}}
-
-1
--- /dev/null
+[[!template id=plugin name=pedigree author="intrigeri"]]
+[[!tag type/useful]]
+
+This plugin offers a `HTML::Template` loop that iterates over all or
+a subset of a page's parents, providing a few bonus possibilities,
+such as styling the parent links depending on their place in the path.
+One can think of pedigree as "`PARENTLINKS` on steroids".
+
+[[!toc ]]
+
+Content
+=======
+
+This plugin provides one template loop, called `PEDIGREE`, that
+returns the same parents list as `PARENTLINKS` would; as a bonus,
+every path element returned by the `PEDIGREE` loop has the following
+variables set:
+
+* `URL` (string): url to the current path element
+* `PAGE` (string): title of the current path element
+* `DEPTH` (positive integer): depth of the path leading to the
+ current path element, counting from the wiki's root, which has
+ `DEPTH=0`
+* `HEIGHT` (positive integer): distance, expressed in path elements,
+ from the current page to the current path element; e.g. this is
+ 1 for the current page's mother, 2 for its grand-mother, etc.
+* `DEPTH_n` (boolean): true if, and only if, `DEPTH==n`
+* `HEIGHT_n` (boolean): true if, and only if, `HEIGHT==n`
+
+Usage
+=====
+
+The `DEPTH_n` and `HEIGHT_n` variables allow the template writer to
+skip arbitrary elements in the parents list: they are arbitrary
+page-range selectors.
+
+The `DEPTH` and `HEIGHT` variables allow the template writer to apply
+general treatment, depending on one of these variables, to *every*
+parent: they are counters.
+
+Styling parents depending on their depth
+----------------------------------------
+
+Say you want the parent links to be styled depending on their depth in
+the path going from the wiki root to the current page; just add the
+following lines in `page.tmpl`:
+
+ <TMPL_LOOP NAME="PEDIGREE">
+ <a href="<TMPL_VAR NAME="URL">" class="depth<TMPL_VAR NAME="DEPTH">">
+ <TMPL_VAR NAME="PAGE">
+ </a> /
+ </TMPL_LOOP>
+
+Then write the appropriate CSS bits for `a.depth1`, etc.
+
+Skip some parents, style the others depending on their distance to the current page
+-----------------------------------------------------------------------------------
+
+Say you want to display all the parents links but the wiki homepage,
+styled depending on their distance to the current page; just add the
+following lines in `page.tmpl`:
+
+ <TMPL_LOOP NAME="PEDIGREE">
+ <TMPL_IF NAME="DEPTH_0">
+ <TMPL_ELSE>
+ <a href="<TMPL_VAR NAME="URL">" class="height<TMPL_VAR NAME="HEIGHT">">
+ <TMPL_VAR NAME="PAGE">
+ </a> /
+ </TMPL_LOOP>
+
+Then write the appropriate CSS bits for `a.height1`, etc.
+
+Full-blown example
+------------------
+
+Let's have a look at a more complicated example; combining the boolean
+loop variables provided by this plugin (`IS_ROOT` and friends) and
+`HTML::Template` flow control structures, you can have custom HTML
+and/or CSS generated for some special path components; e.g.:
+
+ <!-- all parents, skipping mother and grand'ma, inside a common div+ul -->
+ <div id="oldestparents">
+ <ul>
+ <TMPL_LOOP NAME="PEDIGREE">
+ <TMPL_IF NAME="HEIGHT_2">
+ <TMPL_ELSE>
+ <TMPL_IF NAME="HEIGHT_1">
+ <TMPL_ELSE>
+ <li><a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a></li>
+ </TMPL_IF>
+ </TMPL_IF>
+ </TMPL_LOOP>
+ </ul>
+ </div>
+
+ <!-- dedicated div's for mother and grand'ma -->
+ <TMPL_LOOP NAME="PEDIGREE">
+ <TMPL_IF NAME="HEIGHT_2">
+ <div id="grandma">
+ <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a>
+ </div>
+ <TMPL_ELSE>
+ <TMPL_IF NAME="HEIGHT_1">
+ <div id="mother">
+ <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a>
+ </div>
+ </TMPL_IF>
+ </TMPL_IF>
+ </TMPL_LOOP>
+
+ <!-- eventually, the current page title -->
+ <TMPL_VAR NAME="TITLE">
+ </div>
+++ /dev/null
-[[!template id=plugin name=pedigree author="intrigeri"]]
-[[!tag type/useful]]
-
-This plugin offers a `HTML::Template` loop that iterates over all or
-a subset of a page's parents, providing a few bonus possibilities,
-such as styling the parent links depending on their place in the path.
-One can think of pedigree as "`PARENTLINKS` on steroids".
-
-[[!toc ]]
-
-Content
-=======
-
-This plugin provides one template loop, called `PEDIGREE`, that
-returns the same parents list as `PARENTLINKS` would; as a bonus,
-every path element returned by the `PEDIGREE` loop has the following
-variables set:
-
-* `URL` (string): url to the current path element
-* `PAGE` (string): title of the current path element
-* `DEPTH` (positive integer): depth of the path leading to the
- current path element, counting from the wiki's root, which has
- `DEPTH=0`
-* `HEIGHT` (positive integer): distance, expressed in path elements,
- from the current page to the current path element; e.g. this is
- 1 for the current page's mother, 2 for its grand-mother, etc.
-* `DEPTH_n` (boolean): true if, and only if, `DEPTH==n`
-* `HEIGHT_n` (boolean): true if, and only if, `HEIGHT==n`
-
-Usage
-=====
-
-The `DEPTH_n` and `HEIGHT_n` variables allow the template writer to
-skip arbitrary elements in the parents list: they are arbitrary
-page-range selectors.
-
-The `DEPTH` and `HEIGHT` variables allow the template writer to apply
-general treatment, depending on one of these variables, to *every*
-parent: they are counters.
-
-Styling parents depending on their depth
-----------------------------------------
-
-Say you want the parent links to be styled depending on their depth in
-the path going from the wiki root to the current page; just add the
-following lines in `page.tmpl`:
-
- <TMPL_LOOP NAME="PEDIGREE">
- <a href="<TMPL_VAR NAME="URL">" class="depth<TMPL_VAR NAME="DEPTH">">
- <TMPL_VAR NAME="PAGE">
- </a> /
- </TMPL_LOOP>
-
-Then write the appropriate CSS bits for `a.depth1`, etc.
-
-Skip some parents, style the others depending on their distance to the current page
------------------------------------------------------------------------------------
-
-Say you want to display all the parents links but the wiki homepage,
-styled depending on their distance to the current page; just add the
-following lines in `page.tmpl`:
-
- <TMPL_LOOP NAME="PEDIGREE">
- <TMPL_IF NAME="DEPTH_0">
- <TMPL_ELSE>
- <a href="<TMPL_VAR NAME="URL">" class="height<TMPL_VAR NAME="HEIGHT">">
- <TMPL_VAR NAME="PAGE">
- </a> /
- </TMPL_LOOP>
-
-Then write the appropriate CSS bits for `a.height1`, etc.
-
-Full-blown example
-------------------
-
-Let's have a look at a more complicated example; combining the boolean
-loop variables provided by this plugin (`IS_ROOT` and friends) and
-`HTML::Template` flow control structures, you can have custom HTML
-and/or CSS generated for some special path components; e.g.:
-
- <!-- all parents, skipping mother and grand'ma, inside a common div+ul -->
- <div id="oldestparents">
- <ul>
- <TMPL_LOOP NAME="PEDIGREE">
- <TMPL_IF NAME="HEIGHT_2">
- <TMPL_ELSE>
- <TMPL_IF NAME="HEIGHT_1">
- <TMPL_ELSE>
- <li><a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a></li>
- </TMPL_IF>
- </TMPL_IF>
- </TMPL_LOOP>
- </ul>
- </div>
-
- <!-- dedicated div's for mother and grand'ma -->
- <TMPL_LOOP NAME="PEDIGREE">
- <TMPL_IF NAME="HEIGHT_2">
- <div id="grandma">
- <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a>
- </div>
- <TMPL_ELSE>
- <TMPL_IF NAME="HEIGHT_1">
- <div id="mother">
- <a href="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="PAGE"></a>
- </div>
- </TMPL_IF>
- </TMPL_IF>
- </TMPL_LOOP>
-
- <!-- eventually, the current page title -->
- <TMPL_VAR NAME="TITLE">
- </div>
--- /dev/null
+#!/usr/bin/perl
+# -*- cperl-indent-level: 8; -*-
+# Testcases for the Ikiwiki pedigree plugin.
+
+use warnings;
+use strict;
+use Test::More 'no_plan';
+
+my %expected;
+
+BEGIN { use_ok("IkiWiki"); }
+
+# Init
+%config=IkiWiki::defaultconfig();
+$config{srcdir}=$config{destdir}="/dev/null";
+$config{underlaydir}="underlays/basewiki";
+$config{templatedir}="t/pedigree/templates";
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+ok(IkiWiki::loadplugin("pedigree"), "pedigree plugin loaded");
+
+# Test data
+$expected{'pedigree'} =
+ {
+ "" => [],
+ "ikiwiki" => [],
+ "ikiwiki/pagespec" =>
+ [ {depth => 0, height => 2, },
+ {depth => 1, height => 1, },
+ ],
+ "ikiwiki/pagespec/attachment" =>
+ [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
+ {depth => 1, height => 2, },
+ {depth => 2, height => 1, },
+ ],
+ };
+
+# Test function
+sub test_loop($$) {
+ my $loop=shift;
+ my $expected=shift;
+ my $template;
+ my %params;
+
+ ok($template=template('pedigree.tmpl'), "template created");
+ ok($params{template}=$template, "params populated");
+
+ while ((my $page, my $exp) = each %{$expected}) {
+ my @path=(split("/", $page));
+ my $pagedepth=@path;
+ my $msgprefix="$page $loop";
+
+ # manually run the plugin hook
+ $params{page}=$page;
+ $template->clear_params();
+ IkiWiki::Plugin::pedigree::pagetemplate(%params);
+ my $res=$template->param($loop);
+
+ is(scalar(@$res), $pagedepth, "$msgprefix: path length");
+ # logic & arithmetic validation tests
+ for (my $i=0; $i<$pagedepth; $i++) {
+ my $r=$res->[$i];
+ is($r->{height}, $pagedepth - $r->{depth},
+ "$msgprefix\[$i\]: height = pagedepth - depth");
+ ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
+ ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
+ }
+ # comparison tests, iff the test-suite has been written
+ if (scalar(@$exp) eq $pagedepth) {
+ for (my $i=0; $i<$pagedepth; $i++) {
+ my $e=$exp->[$i];
+ my $r=$res->[$i];
+ map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
+ }
+ }
+ # else {
+ # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
+ # }
+ }
+}
+
+# Main
+test_loop('pedigree', $expected{'pedigree'});
--- /dev/null
+<!-- This template file only has to "use" the loops tested by pedigree.t -->
+
+<TMPL_LOOP NAME="PEDIGREE">
+</TMPL_LOOP>
+++ /dev/null
-#!/usr/bin/perl
-# -*- cperl-indent-level: 8; -*-
-# Testcases for the Ikiwiki pedigree plugin.
-
-use warnings;
-use strict;
-use Test::More 'no_plan';
-
-my %expected;
-
-BEGIN { use_ok("IkiWiki"); }
-
-# Init
-%config=IkiWiki::defaultconfig();
-$config{srcdir}=$config{destdir}="/dev/null";
-$config{underlaydir}="underlays/basewiki";
-$config{templatedir}="t/pedigree/templates";
-IkiWiki::loadplugins();
-IkiWiki::checkconfig();
-ok(IkiWiki::loadplugin("pedigree"), "pedigree plugin loaded");
-
-# Test data
-$expected{'pedigree'} =
- {
- "" => [],
- "ikiwiki" => [],
- "ikiwiki/pagespec" =>
- [ {depth => 0, height => 2, },
- {depth => 1, height => 1, },
- ],
- "ikiwiki/pagespec/attachment" =>
- [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
- {depth => 1, height => 2, },
- {depth => 2, height => 1, },
- ],
- };
-
-# Test function
-sub test_loop($$) {
- my $loop=shift;
- my $expected=shift;
- my $template;
- my %params;
-
- ok($template=template('pedigree.tmpl'), "template created");
- ok($params{template}=$template, "params populated");
-
- while ((my $page, my $exp) = each %{$expected}) {
- my @path=(split("/", $page));
- my $pagedepth=@path;
- my $msgprefix="$page $loop";
-
- # manually run the plugin hook
- $params{page}=$page;
- $template->clear_params();
- IkiWiki::Plugin::pedigree::pagetemplate(%params);
- my $res=$template->param($loop);
-
- is(scalar(@$res), $pagedepth, "$msgprefix: path length");
- # logic & arithmetic validation tests
- for (my $i=0; $i<$pagedepth; $i++) {
- my $r=$res->[$i];
- is($r->{height}, $pagedepth - $r->{depth},
- "$msgprefix\[$i\]: height = pagedepth - depth");
- ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
- ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
- }
- # comparison tests, iff the test-suite has been written
- if (scalar(@$exp) eq $pagedepth) {
- for (my $i=0; $i<$pagedepth; $i++) {
- my $e=$exp->[$i];
- my $r=$res->[$i];
- map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
- }
- }
- # else {
- # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
- # }
- }
-}
-
-# Main
-test_loop('pedigree', $expected{'pedigree'});
+++ /dev/null
-<!-- This template file only has to "use" the loops tested by pedigree.t -->
-
-<TMPL_LOOP NAME="PEDIGREE">
-</TMPL_LOOP>