Merge remote-tracking branch 'smcv/comments-metadata'
authorJoey Hess <joey@kitenet.net>
Wed, 29 Jun 2011 21:55:53 +0000 (17:55 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 29 Jun 2011 21:55:53 +0000 (17:55 -0400)
IkiWiki/Plugin/comments.pm
IkiWiki/Render.pm
t/comments.t [new file with mode: 0755]

index 9fb81d15aea5b22035e44ac42813c723caa5fc80..3ad2a0e13a2a51ffce1301e020687b4b0c6b36d3 100755 (executable)
@@ -21,7 +21,8 @@ my %commentstate;
 sub import {
        hook(type => "checkconfig", id => 'comments',  call => \&checkconfig);
        hook(type => "getsetup", id => 'comments',  call => \&getsetup);
-       hook(type => "preprocess", id => 'comment', call => \&preprocess);
+       hook(type => "preprocess", id => 'comment', call => \&preprocess,
+               scan => 1);
        hook(type => "preprocess", id => 'commentmoderation', call => \&preprocess_moderation);
        # here for backwards compatability with old comments
        hook(type => "preprocess", id => '_comment', call => \&preprocess);
@@ -143,22 +144,27 @@ sub preprocess {
        }
        $content =~ s/\\"/"/g;
 
-       if ($config{comments_allowdirectives}) {
-               $content = IkiWiki::preprocess($page, $params{destpage},
-                       $content);
-       }
+       if (defined wantarray) {
+               if ($config{comments_allowdirectives}) {
+                       $content = IkiWiki::preprocess($page, $params{destpage},
+                               $content);
+               }
 
-       # no need to bother with htmlize if it's just HTML
-       $content = IkiWiki::htmlize($page, $params{destpage}, $format, $content)
-               if defined $format;
+               # no need to bother with htmlize if it's just HTML
+               $content = IkiWiki::htmlize($page, $params{destpage}, $format, $content)
+                       if defined $format;
 
-       IkiWiki::run_hooks(sanitize => sub {
-               $content = shift->(
-                       page => $page,
-                       destpage => $params{destpage},
-                       content => $content,
-               );
-       });
+               IkiWiki::run_hooks(sanitize => sub {
+                       $content = shift->(
+                               page => $page,
+                               destpage => $params{destpage},
+                               content => $content,
+                       );
+               });
+       }
+       else {
+               IkiWiki::preprocess($page, $params{destpage}, $content, 1);
+       }
 
        # set metadata, possibly overriding [[!meta]] directives from the
        # comment itself
index 5288abc6dc40549c8debe95c6259172deb51b7b1..05132a8a81560a3ce0039b748ce0458d5742ad53 100644 (file)
@@ -475,8 +475,18 @@ sub find_changed ($) {
                        $pagemtime{$page}=$stat[9];
 
                        if (isinternal($page)) {
+                               my $content = readfile($srcfile);
+
                                # Preprocess internal page in scan-only mode.
-                               preprocess($page, $page, readfile($srcfile), 1);
+                               preprocess($page, $page, $content, 1);
+
+                               run_hooks(scan => sub {
+                                       shift->(
+                                               page => $page,
+                                               content => $content,
+                                       );
+                               });
+
                                push @internal_changed, $file;
                        }
                        else {
diff --git a/t/comments.t b/t/comments.t
new file mode 100755 (executable)
index 0000000..4721d7a
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use IkiWiki;
+
+ok(! system("rm -rf t/tmp"));
+ok(mkdir "t/tmp");
+ok(! system("cp -R t/tinyblog t/tmp/in"));
+ok(mkdir "t/tmp/in/post" or -d "t/tmp/in/post");
+
+my $comment;
+
+$comment = <<EOF;
+[[!comment username="neil"
+  date="1969-07-20T20:17:40Z"
+  content="I landed"]]
+EOF
+#ok(eval { writefile("post/comment_3._comment", "t/tmp/in", $comment); 1 });
+writefile("post/comment_3._comment", "t/tmp/in", $comment);
+
+$comment = <<EOF;
+[[!comment username="christopher"
+  date="1492-10-12T07:00:00Z"
+  content="I explored"]]
+EOF
+writefile("post/comment_2._comment", "t/tmp/in", $comment);
+
+$comment = <<EOF;
+[[!comment username="william"
+  date="1066-10-14T12:00:00Z"
+  content="I conquered"]]
+EOF
+writefile("post/comment_1._comment", "t/tmp/in", $comment);
+
+# Give the files mtimes in the wrong order
+ok(utime(111111111, 111111111, "t/tmp/in/post/comment_3._comment"));
+ok(utime(222222222, 222222222, "t/tmp/in/post/comment_2._comment"));
+ok(utime(333333333, 333333333, "t/tmp/in/post/comment_1._comment"));
+
+# Build the wiki
+ok(! system("make -s ikiwiki.out"));
+ok(! system("perl -I. ./ikiwiki.out -verbose -plugin comments -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -set comments_pagespec='*' -templatedir=templates t/tmp/in t/tmp/out"));
+
+# Check that the comments are in the right order
+
+sub slurp {
+    open my $fh, "<", shift or return undef;
+    local $/;
+    my $content = <$fh>;
+    close $fh or return undef;
+    return $content;
+}
+
+my $content = slurp("t/tmp/out/post/index.html");
+ok(defined $content);
+ok($content =~ m/I conquered.*I explored.*I landed/s);