]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge remote branch 'smcv/ready/urlto'
authorJoey Hess <joey@kitenet.net>
Sun, 26 Dec 2010 17:53:31 +0000 (13:53 -0400)
committerJoey Hess <joey@kitenet.net>
Sun, 26 Dec 2010 17:53:31 +0000 (13:53 -0400)
.gitignore
IkiWiki.pm
t/autoindex.t [new file with mode: 0755]
t/po.t
t/tag.t
t/urlto.t

index e9ab152b6413d20385e317c7020406b01268f607..6b7efe5c150a177fcd9c4bc5e5c297e48771078e 100644 (file)
@@ -16,3 +16,4 @@ po/underlays/basewiki/*/*/*.mdwn
 po/underlays/directives/ikiwiki/directive/*.mdwn
 po/underlays_copy_stamp
 underlays/locale
+/t/tmp/
index 926d42a497159845ae8ab94c62a054374a61d468..bbe1ad055b2935437c9d0ee6ccf76f8f51d6bf3d 100644 (file)
@@ -544,7 +544,7 @@ sub checkconfig () {
                error(gettext("Must specify url to wiki with --url when using --cgi"));
        }
 
-       if (length $config{url}) {
+       if (defined $config{url} && length $config{url}) {
                eval q{use URI};
                my $baseurl = URI->new($config{url});
 
@@ -1140,7 +1140,7 @@ sub urlto ($;$$) {
        my $absolute=shift;
        
        if (! length $to) {
-               return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
+               $to = 'index';
        }
 
        if (! $destsources{$to}) {
diff --git a/t/autoindex.t b/t/autoindex.t
new file mode 100755 (executable)
index 0000000..b47f2e0
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+package IkiWiki;
+
+use warnings;
+use strict;
+use Test::More;
+
+BEGIN { use_ok("IkiWiki"); }
+BEGIN { use_ok("IkiWiki::Render"); }
+BEGIN { use_ok("IkiWiki::Plugin::autoindex"); }
+BEGIN { use_ok("IkiWiki::Plugin::html"); }
+BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
+
+ok(! system("rm -rf t/tmp; mkdir t/tmp"));
+
+$config{verbose} = 1;
+$config{srcdir} = 't/tmp';
+$config{underlaydir} = 't/tmp';
+$config{underlaydirbase} = '.';
+$config{templatedir} = 'templates';
+$config{usedirs} = 1;
+$config{htmlext} = 'html';
+$config{wiki_file_chars} = "-[:alnum:]+/.:_";
+$config{userdir} = "users";
+$config{tagbase} = "tags";
+$config{default_pageext} = "mdwn";
+$config{wiki_file_prune_regexps} = [qr/^\./];
+
+is(checkconfig(), 1);
+
+%oldrenderedfiles=%pagectime=();
+%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
+%destsources=%renderedfiles=%pagecase=%pagestate=();
+
+# pages that (we claim) were deleted in an earlier pass
+$wikistate{autoindex}{deleted}{deleted} = 1;
+$wikistate{autoindex}{deleted}{expunged} = 1;
+$wikistate{autoindex}{deleted}{reinstated} = 1;
+
+foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) {
+       # we use a non-default extension for these, so they're distinguishable
+       # from programmatically-created pages
+       $pagesources{$page} = "$page.html";
+       $pagemtime{$page} = $pagectime{$page} = 1000000;
+       writefile("$page.html", "t/tmp", "your ad here");
+}
+
+# "gone" disappeared just before this refresh pass so it still has a mtime
+$pagemtime{gone} = $pagectime{gone} = 1000000;
+
+IkiWiki::Plugin::autoindex::refresh();
+
+# these pages are still on record as having been deleted, because they have
+# a reason to be re-created
+is($wikistate{autoindex}{deleted}{deleted}, 1);
+is($wikistate{autoindex}{deleted}{gone}, 1);
+ok(! -f "t/tmp/deleted.mdwn");
+ok(! -f "t/tmp/gone.mdwn");
+
+# this page does not exist and has no reason to be re-created, so we forget
+# about it - it will be re-created if it gains sub-pages
+ok(! exists $wikistate{autoindex}{deleted}{expunged});
+ok(! -f "t/tmp/expunged.mdwn");
+
+# this page was re-created, so it drops off the radar
+ok(! exists $wikistate{autoindex}{deleted}{reinstated});
+ok(! -f "t/tmp/reinstated.mdwn");
+
+# needs creating
+ok(! exists $wikistate{autoindex}{deleted}{tags});
+ok(-s "t/tmp/tags.mdwn");
+
+done_testing();
+1;
diff --git a/t/po.t b/t/po.t
index 51321fa96c73d3a325064fb59bda6aa6b10fbdea..da0bd68a7d89e6177ddc811e503444d75c59c264 100755 (executable)
--- a/t/po.t
+++ b/t/po.t
@@ -17,7 +17,7 @@ BEGIN {
        }
 }
 
-use Test::More tests => 91;
+use Test::More tests => 109;
 
 BEGIN { use_ok("IkiWiki"); }
 
@@ -34,6 +34,8 @@ $config{destdir} = "$dir/dst";
 $config{destdir} = "$dir/dst";
 $config{underlaydirbase} = "/dev/null";
 $config{underlaydir} = "/dev/null";
+$config{url} = "http://example.com";
+$config{cgiurl} = "http://example.com/ikiwiki.cgi";
 $config{discussion} = 0;
 $config{po_master_language} = { code => 'en',
                                name => 'English'
@@ -166,11 +168,32 @@ $msgprefix="urlto (po_link_to=current)";
 is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''");
 is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''");
 is(urlto('', 'translatable.fr'), '../index.fr.html', "$msgprefix translatable.fr -> ''");
+# when asking for a semi-absolute or absolute URL, we can't know what the
+# current language is, so for translatable pages we use the master language
+is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
+is(urlto('translatable'), '/translatable/index.en.html', "$msgprefix 1-arg -> translatable");
+is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
+is(urlto('index', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> index");
+is(urlto('', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> ''");
+# FIXME: should these three produce the negotiatable URL instead of the master
+# language?
+is(urlto(''), '/index.en.html', "$msgprefix 1-arg -> ''");
+is(urlto('index'), '/index.en.html', "$msgprefix 1-arg -> index");
+is(urlto('translatable', undef, 1), 'http://example.com/translatable/index.en.html', "$msgprefix 1-arg -> translatable");
+
 $config{po_link_to}='negotiated';
 $msgprefix="urlto (po_link_to=negotiated)";
 is(urlto('', 'index'), './', "$msgprefix index -> ''");
 is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''");
 is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''");
+is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
+is(urlto('translatable'), '/translatable/', "$msgprefix 1-arg -> translatable");
+is(urlto(''), '/', "$msgprefix 1-arg -> ''");
+is(urlto('index'), '/', "$msgprefix 1-arg -> index");
+is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
+is(urlto('translatable', undef, 1), 'http://example.com/translatable/', "$msgprefix 1-arg -> translatable");
+is(urlto('index', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> index");
+is(urlto('', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> ''");
 
 ### bestlink
 $config{po_link_to}='current';
@@ -192,6 +215,10 @@ $msgprefix="beautify_urlpath (po_link_to=negotiated)";
 is(IkiWiki::beautify_urlpath('test1/index.html'), './test1/', "$msgprefix test1/index.html");
 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html");
 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/', "$msgprefix test1/index.fr.html");
+$config{po_link_to}='current';
+$msgprefix="beautify_urlpath (po_link_to=current)";
+is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html");
+is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
 
 ### re-scan
 refresh_n_scan('index.mdwn');
diff --git a/t/tag.t b/t/tag.t
index fe547d85bc51eaa306d85b90e28d79d4793f8a4e..ec17d543418e4bb0bcc00fd81aa4ceb22d0f74a7 100755 (executable)
--- a/t/tag.t
+++ b/t/tag.t
@@ -3,15 +3,30 @@ package IkiWiki;
 
 use warnings;
 use strict;
-use Test::More tests => 7;
+use Test::More tests => 21;
 
 BEGIN { use_ok("IkiWiki"); }
+BEGIN { use_ok("IkiWiki::Render"); }
+BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
 BEGIN { use_ok("IkiWiki::Plugin::tag"); }
 
 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
 
+$config{verbose} = 1;
+$config{srcdir} = 't/tmp';
+$config{underlaydir} = 't/tmp';
+$config{templatedir} = 'templates';
+$config{usedirs} = 1;
+$config{htmlext} = 'html';
+$config{wiki_file_chars} = "-[:alnum:]+/.:_";
 $config{userdir} = "users";
 $config{tagbase} = "tags";
+$config{tag_autocreate} = 1;
+$config{default_pageext} = "mdwn";
+$config{wiki_file_prune_regexps} = [qr/^\./];
+$config{underlaydirbase} = '.';
+
+is(checkconfig(), 1);
 
 %oldrenderedfiles=%pagectime=();
 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
@@ -20,6 +35,7 @@ $config{tagbase} = "tags";
 foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
        $pagesources{$page} = "$page.mdwn";
        $pagemtime{$page} = $pagectime{$page} = 1000000;
+       writefile("$page.mdwn", "t/tmp", "your ad here");
 }
 
 $links{one}=[qw(tags/numbers alpha tags/letters)];
@@ -36,4 +52,31 @@ ok(!pagespec_match("two", "tagged(alpha)"));
 ok(pagespec_match("one", "link(tags/numbers)"));
 ok(pagespec_match("one", "link(alpha)"));
 
+# emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
+# the "numbers" and "primes" tag pages to be auto-created
+IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
+is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
+is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
+is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
+
+ok(!-e "t/tmp/tags/lucky.mdwn");
+my (%pages, @del);
+IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/tags/lucky" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
+ok(-s "t/tmp/tags/lucky.mdwn");
+
+# generating an autofile that already exists does nothing
+%pages = @del = ();
+IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
+is_deeply(\%pages, {}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
+
+# generating an autofile that we just deleted does nothing
+%pages = ();
+@del = ('tags/primes.mdwn');
+IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
+is_deeply(\%pages, {}) || diag explain \%pages;
+is_deeply(\@del, ['tags/primes.mdwn']) || diag explain \@del;
+
 1;
index 25445579248d2b8e94b4d1a7abf5460d992f084f..338632e9450399a02a2fa416f0746996e33d80ad 100755 (executable)
--- a/t/urlto.t
+++ b/t/urlto.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More tests => 21;
+use Test::More tests => 26;
 
 BEGIN { use_ok("IkiWiki"); }
 
@@ -19,6 +19,7 @@ is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}), "http://smcv.example.co.uk/cgi-bi
 is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}, do => 'badger'), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi?do=badger");
 is(IkiWiki::urlto('index', undef, 1), "http://smcv.example.co.uk/");
 is(IkiWiki::urlto('stoats', undef, 1), "http://smcv.example.co.uk/stoats/");
+is(IkiWiki::urlto('', undef, 1), "http://smcv.example.co.uk/");
 
 # "local" (absolute path within site) version (default for cgiurl)
 is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi");
@@ -28,10 +29,13 @@ is(IkiWiki::urlto('index', undef), "/");
 is(IkiWiki::urlto('index'), "/");
 is(IkiWiki::urlto('stoats', undef), "/stoats/");
 is(IkiWiki::urlto('stoats'), "/stoats/");
+is(IkiWiki::urlto(''), "/");
 
 # fully-relative version (default for urlto and baseurl)
 is(IkiWiki::baseurl('badger/mushroom'), "../../");
 is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/");
+is(IkiWiki::urlto('', 'snake'), "../");
+is(IkiWiki::urlto('', 'penguin/herring'), "../../");
 
 # explicit cgiurl override
 is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki");
@@ -44,3 +48,4 @@ is(IkiWiki::checkconfig(), 1);
 is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi");
 is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/");
 is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/");
+is(IkiWiki::urlto('', undef), "http://example.co.uk/~smcv/");