summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-02-19 18:38:45 -0500
committerJoey Hess <joey@gnu.kitenet.net>2009-02-19 18:38:45 -0500
commit66dc253437e7ce2e3e8984513b3ecf96603d6670 (patch)
tree8f45fb353322833217101c0239ecaf3330d7c53e
parent9ecb0036a32c6930d9400040161c3b9e41ef9b1f (diff)
Add noextension parameter to htmlize hooks to support, eg, Makefile.
-rw-r--r--IkiWiki.pm23
-rw-r--r--debian/changelog1
-rw-r--r--doc/plugins/write.mdwn7
-rw-r--r--doc/todo/Allow_filenames_that_are_all_type.mdwn4
-rwxr-xr-xt/pagename.t23
-rwxr-xr-xt/pagetype.t15
6 files changed, 43 insertions, 30 deletions
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 <joeyh@debian.org> 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);