]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
goto: Support being passed a page title that is not a valid page name, to support...
[git.ikiwiki.info.git] / IkiWiki.pm
index e260fffea7aad7802e673541533056ad6960a118..d7c827c89b240d8d1b178be76934ce3c868ba4f8 100644 (file)
@@ -21,12 +21,12 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
                  pagespec_match_list bestlink htmllink readfile writefile
                 pagetype srcfile pagename displaytime will_render gettext urlto
                 targetpage add_underlay pagetitle titlepage linkpage
-                newpagefile inject
+                newpagefile inject add_link
                  %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
-our $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
+our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
 
 # Optimisation.
 use Memoize;
@@ -157,6 +157,13 @@ sub getsetup () {
                safe => 0, # path
                rebuild => 0,
        },
+       underlaydirbase => {
+               type => "internal",
+               default => "$installdir/share/ikiwiki",
+               description => "parent directory containing additional underlays",
+               safe => 0,
+               rebuild => 0,
+       },
        wrappers => {
                type => "internal",
                default => [],
@@ -715,7 +722,7 @@ sub add_underlay ($) {
        my $dir=shift;
 
        if ($dir !~ /^\//) {
-               $dir="$config{underlaydir}/../$dir";
+               $dir="$config{underlaydirbase}/$dir";
        }
 
        if (! grep { $_ eq $dir } @{$config{underlaydirs}}) {
@@ -1246,7 +1253,7 @@ sub preprocess ($$$;$$) {
                                                |
                                                "[^"]+"         # single-quoted value
                                                |
-                                               [^\s\]]+        # unquoted value
+                                               [^"\s\]]+       # unquoted value
                                        )
                                        \s*                     # whitespace or end
                                                                # of directive
@@ -1269,7 +1276,7 @@ sub preprocess ($$$;$$) {
                                                |
                                                "[^"]+"         # single-quoted value
                                                |
-                                               [^\s\]]+        # unquoted value
+                                               [^"\s\]]+       # unquoted value
                                        )
                                        \s*                     # whitespace or end
                                                                # of directive
@@ -1671,12 +1678,6 @@ sub rcs_receive () {
        $hooks{rcs}{rcs_receive}{call}->();
 }
 
-sub safequote ($) {
-       my $s=shift;
-       $s=~s/[{}]//g;
-       return "q{$s}";
-}
-
 sub add_depends ($$) {
        my $page=shift;
        my $pagespec=shift;
@@ -1757,6 +1758,14 @@ sub inject {
        use warnings;
 }
 
+sub add_link ($$) {
+       my $page=shift;
+       my $link=shift;
+
+       push @{$links{$page}}, $link
+               unless grep { $_ eq $link } @{$links{$page}};
+}
+
 sub pagespec_merge ($$) {
        my $a=shift;
        my $b=shift;
@@ -1770,6 +1779,7 @@ sub pagespec_translate ($) {
 
        # Convert spec to perl code.
        my $code="";
+       my @data;
        while ($spec=~m{
                \s*             # ignore whitespace
                (               # 1: match a single word
@@ -1797,14 +1807,17 @@ sub pagespec_translate ($) {
                }
                elsif ($word =~ /^(\w+)\((.*)\)$/) {
                        if (exists $IkiWiki::PageSpec::{"match_$1"}) {
-                               $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@_)";
+                               push @data, $2;
+                               $code.="IkiWiki::PageSpec::match_$1(\$page, \$data[$#data], \@_)";
                        }
                        else {
-                               $code.="IkiWiki::ErrorReason->new(".safequote(qq{unknown function in pagespec "$word"}).")";
+                               push @data, qq{unknown function in pagespec "$word"};
+                               $code.="IkiWiki::ErrorReason->new(\$data[$#data])";
                        }
                }
                else {
-                       $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@_)";
+                       push @data, $word;
+                       $code.=" IkiWiki::PageSpec::match_glob(\$page, \$data[$#data], \@_)";
                }
        }