Add noextension parameter to htmlize hooks to support, eg, Makefile.

master
Joey Hess 2009-02-19 18:38:45 -05:00
parent 9ecb0036a3
commit 66dc253437
6 changed files with 44 additions and 31 deletions

View File

@ -627,27 +627,32 @@ sub dirname ($) {
return $file;
}
sub pagetype ($) {
my $page=shift;
if ($page =~ /\.([^.]+)$/) {
return $1 if exists $hooks{htmlize}{$1};
}
return;
}
sub isinternal ($) {
my $page=shift;
return exists $pagesources{$page} &&
$pagesources{$page} =~ /\._([^.]+)$/;
}
sub pagetype ($) {
my $file=shift;
if ($file =~ /\.([^.]+)$/) {
return $1 if exists $hooks{htmlize}{$1};
}
elsif ($hooks{htmlize}{basename($file)}{noextension}) {
return basename($file);
}
return;
}
sub pagename ($) {
my $file=shift;
my $type=pagetype($file);
my $page=$file;
$page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{keepextension};
$page=~s/\Q.$type\E*$//
if defined $type && !$hooks{htmlize}{$type}{keepextension}
&& !$hooks{htmlize}{$type}{noextension};
if ($config{indexpages} && $page=~/(.*)\/index$/) {
$page=$1;
}

1
debian/changelog vendored
View File

@ -6,6 +6,7 @@ ikiwiki (3.05) UNRELEASED; urgency=low
directives, and other links on templates affect the page using the
template reliably.
* goto: Fix redirect to comments.
* Add noextension parameter to htmlize hooks to support, eg, Makefile.
-- Joey Hess <joeyh@debian.org> Sun, 15 Feb 2009 20:11:57 -0500

View File

@ -189,9 +189,14 @@ The function is passed named parameters: "page" and "content" and should
return the htmlized content.
If `hook` is passed an optional "keepextension" parameter, set to a true
value, then this extension will not be stripped from the source filename when
value, then the extension will not be stripped from the source filename when
generating the page.
If `hook` is passed an optional "noextension" parameter, set to a true
value, then the id parameter specifies not a filename extension, but
a whole filename that can be htmlized. This is useful for files
like `Makefile` that have no extension.
### pagetemplate
hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);

View File

@ -22,6 +22,10 @@ lost because it didn't have its own bug to track it. Now it does :). -- [[Will
>>
>> So, yeah, I think this patch is complete. :) -- [[Will]]
>>> Thanks, [[applied|done]], but I added a noextension parameter,
>>> since having keepextension allow files with no extension didn't make
>>> sense. Also, made it work for pages in subdirs.. --[[Joey]]
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 8d728c9..1bd46a9 100644
--- a/IkiWiki.pm

View File

@ -1,22 +1,35 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 8;
use Test::More tests => 19;
BEGIN { use_ok("IkiWiki"); }
# Used internally.
# define mdwn as an extension
$IkiWiki::hooks{htmlize}{mdwn}={};
$IkiWiki::hooks{htmlize}{txt}={keepextension => 1};
is(pagetype("foo.mdwn"), "mdwn");
is(pagename("foo.mdwn"), "foo");
is(pagetype("foo/bar.mdwn"), "mdwn");
is(pagename("foo/bar.mdwn"), "foo/bar");
# bare files get the full filename as page name
# bare files get the full filename as page name, undef type
is(pagetype("foo.png"), undef);
is(pagename("foo.png"), "foo.png");
is(pagetype("foo/bar.png"), undef);
is(pagename("foo/bar.png"), "foo/bar.png");
is(pagetype("foo"), undef);
is(pagename("foo"), "foo");
# keepextension preserves the extension in the page name
$IkiWiki::hooks{htmlize}{txt}={keepextension => 1};
is(pagename("foo.txt"), "foo.txt");
is(pagetype("foo.txt"), "txt");
is(pagename("foo/bar.txt"), "foo/bar.txt");
is(pagetype("foo/bar.txt"), "txt");
# noextension makes extensionless files be treated as first-class pages
$IkiWiki::hooks{htmlize}{Makefile}={noextension =>1};
is(pagetype("Makefile"), "Makefile");
is(pagename("Makefile"), "Makefile");
is(pagetype("foo/Makefile"), "Makefile");
is(pagename("foo/Makefile"), "foo/Makefile");

View File

@ -1,15 +0,0 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 6;
BEGIN { use_ok("IkiWiki"); }
# Used internally.
$IkiWiki::hooks{htmlize}{mdwn}={};
is(pagetype("foo.mdwn"), "mdwn");
is(pagetype("foo/bar.mdwn"), "mdwn");
is(pagetype("foo.png"), undef);
is(pagetype("foo/bar.png"), undef);
is(pagetype("foo"), undef);