Add noextension parameter to htmlize hooks to support, eg, Makefile.
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 19 Feb 2009 23:38:45 +0000 (18:38 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 19 Feb 2009 23:38:45 +0000 (18:38 -0500)
IkiWiki.pm
debian/changelog
doc/plugins/write.mdwn
doc/todo/Allow_filenames_that_are_all_type.mdwn
t/pagename.t
t/pagetype.t [deleted file]

index ce1ceb3517431440da8aa882ecea7a7dff83a5ef..f580d1f0d008fea8aec829914d1bdeca4bf5217f 100644 (file)
@@ -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;
        }
index b644ac99c17f8adea2a5ebe62ea8e7e47acb48dc..810c59f4e910a44eefa9a022cb840a019741f30b 100644 (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
 
index 2e907938fd0f98e2adfbba1263a3e10e05b78c7a..696bc6bc37bb910af72e256b90d2250159965c7e 100644 (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);
index e165da7dce436675c695c9a8b02c5979ee9d5ea4..bebbcafa8a4855d6895976a74802f92f5f1c33b8 100644 (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
index 488e341fa2daf05c0d1f07233fdd93fec18ac1eb..540d10f4c0bcc4a4a020674a0574e89ce42b3214 100755 (executable)
@@ -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 (executable)
index bb06a15..0000000
+++ /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);