From 66dc253437e7ce2e3e8984513b3ecf96603d6670 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Feb 2009 18:38:45 -0500 Subject: [PATCH] Add noextension parameter to htmlize hooks to support, eg, Makefile. --- IkiWiki.pm | 23 +++++++++++-------- debian/changelog | 1 + doc/plugins/write.mdwn | 7 +++++- .../Allow_filenames_that_are_all_type.mdwn | 4 ++++ t/pagename.t | 23 +++++++++++++++---- t/pagetype.t | 15 ------------ 6 files changed, 43 insertions(+), 30 deletions(-) delete mode 100755 t/pagetype.t diff --git a/IkiWiki.pm b/IkiWiki.pm index ce1ceb351..f580d1f0d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -627,27 +627,32 @@ sub dirname ($) { return $file; } -sub pagetype ($) { +sub isinternal ($) { my $page=shift; + return exists $pagesources{$page} && + $pagesources{$page} =~ /\._([^.]+)$/; +} + +sub pagetype ($) { + my $file=shift; - if ($page =~ /\.([^.]+)$/) { + if ($file =~ /\.([^.]+)$/) { return $1 if exists $hooks{htmlize}{$1}; } + elsif ($hooks{htmlize}{basename($file)}{noextension}) { + return basename($file); + } return; } -sub isinternal ($) { - my $page=shift; - return exists $pagesources{$page} && - $pagesources{$page} =~ /\._([^.]+)$/; -} - 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; } diff --git a/debian/changelog b/debian/changelog index b644ac99c..810c59f4e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sun, 15 Feb 2009 20:11:57 -0500 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 2e907938f..696bc6bc3 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -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); diff --git a/doc/todo/Allow_filenames_that_are_all_type.mdwn b/doc/todo/Allow_filenames_that_are_all_type.mdwn index e165da7dc..bebbcafa8 100644 --- a/doc/todo/Allow_filenames_that_are_all_type.mdwn +++ b/doc/todo/Allow_filenames_that_are_all_type.mdwn @@ -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 diff --git a/t/pagename.t b/t/pagename.t index 488e341fa..540d10f4c 100755 --- a/t/pagename.t +++ b/t/pagename.t @@ -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"); diff --git a/t/pagetype.t b/t/pagetype.t deleted file mode 100755 index bb06a1568..000000000 --- a/t/pagetype.t +++ /dev/null @@ -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); -- 2.32.0.93.g670b81a890