* Add no_override parameter to hook().

* Add a shortcut plugin, inspired by Victor Moral's contributed shortcuts 
  plugin, but featuring a more ikiwiki-ish syntax and with shortcuts that
  can be configured using a page in wiki.
master
joey 2006-10-15 19:33:52 +00:00
parent 8544d52fe9
commit b973ed8269
11 changed files with 105 additions and 0 deletions

View File

@ -641,6 +641,8 @@ sub hook (@) { # {{{
if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
error "hook requires type, call, and id parameters";
}
return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
$hooks{$param{type}}{$param{id}}=\%param;
} # }}}

View File

@ -0,0 +1,58 @@
#!/usr/bin/perl
package IkiWiki::Plugin::shortcut;
use warnings;
use strict;
use IkiWiki;
sub import { #{{{
hook(type => "checkconfig", id => "shortcut", call => \&checkconfig);
hook(type => "preprocess", id => "shortcut", call => \&preprocess_shortcut);
} #}}}
sub checkconfig () { #{{{
# Preprocess the shortcuts page to get all the available shortcuts
# defined before other pages are rendered.
IkiWiki::preprocess("shortcuts", "shortcuts",
readfile(srcfile("shortcuts.mdwn")));
} # }}}
sub preprocess_shortcut (@) { #{{{
my %params=@_;
if (! defined $params{name} || ! defined $params{url}) {
return "[[shortcut missing name or url parameter]]";
}
hook(type => "preprocess", no_override => 1, id => $params{name},
call => sub { shortcut_expand($params{name}, $params{url}, @_) });
return "shortcut $params{name} points to $params{url}";
} # }}}
sub shortcut_expand ($$@) { #{{{
my $name=shift;
my $url=shift;
my %params=@_;
# Get params in original order.
my @params;
while (@_) {
my $key=shift;
my $value=shift;
push @params, $key if ! length $value;
}
# If the shortcuts page changes, all pages that use shortcuts will
# need to be updated.
add_depends($params{destpage}, "shortcuts");
my $text=join(" ", @params);
my $encoded_text=$text;
$encoded_text=~s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
$url=~s/\%s/$encoded_text/g;
return "<a href=\"$url\">$text</a>";
} #}}}
1

View File

@ -0,0 +1,8 @@
This page is used to control what shortcut links are supported by the wiki.
* [[shortcut name=google url="http://www.google.com/search?q=%s"]]
* [[shortcut name=wikipedia url="http://en.wikipedia.org/wiki/%s"]]
* [[shortcut name=debbug url="http://bugs.debian.org/%s"]]
To add a new shortcut, use the "shortcut" preprocessor directive. "%s" in
the url is replaced by the text of the shortcut.

9
debian/changelog vendored
View File

@ -1,3 +1,12 @@
ikiwiki (1.30) UNRELEASED; urgency=low
* Add no_override parameter to hook().
* Add a shortcut plugin, inspired by Victor Moral's contributed shortcuts
plugin, but featuring a more ikiwiki-ish syntax and with shortcuts that
can be configured using a page in wiki.
-- Joey Hess <joeyh@debian.org> Sun, 15 Oct 2006 14:49:28 -0400
ikiwiki (1.29) unstable; urgency=low
* Patch from Paul Tötterman to use CP in the Makefile.

View File

@ -1,5 +1,6 @@
[[template id=plugin name=googlemaps author="Christian Mock"]]
[[tag special-purpose]]
[[meta title"googlemaps (third-party plugin)"]]
`googlemaps` is a plugin that allows using the [Google Maps API][2]
from ikiwiki.

View File

@ -1,5 +1,6 @@
[[template id=plugin name=img author="Christian Mock"]]
[[tag chrome]]
[[meta title"img (third-party plugin)"]]
`img` is an enhanced image handling plugin.

View File

@ -1,4 +1,5 @@
[[template id=plugin name=linguas author="Jordà Polo"]]
[[meta title"linguas (third-party plugin)"]]
Linguas
=======

View File

@ -1,5 +1,10 @@
[[template id=plugin name=shortcuts included=0 author="[[VictorMoral]]"]]
[[tag type/format]]
[[meta title"shortcuts (third-party plugin)"]]
Note: This plugin is different than the "shortcut" plugin now included in
ikiwiki. I'm leaving it here in case people prefer how this one works.
--[[Joey]]
*shortcuts* is a plugin for make external links easy in a ikiwiki page.
It filter the raw source code, searching *wafl expresions* and replacing it

View File

@ -22,3 +22,6 @@ standard across wikis, this approach seems cleaner and easier to learn for
ikiwiki users.
--[[Joey]]
Update: I've added a "shortcut" plugin that works as described above.
--[[Joey]]

View File

@ -0,0 +1,12 @@
[[template id=plugin name=shortcut included=1 author="[[Joey]]"]]
[[tag type/format]]
This plugin allows external links to commonly linked to sites to be made
more easily using shortcuts. Some examples of using shortcuts include:
\[[google foo]]
\[[wikipedia War of 1812]]
\[[debbug 12345]]
The available shortcuts are defined on the [[shortcuts]] page in
the wiki.

View File

@ -210,6 +210,11 @@ ikiwiki program.
Hook into ikiwiki's processing. See the discussion of hooks above.
Note that in addition to the named parameters described above, a parameter
named no_override is supported, If it's set to a true value, then this hook
will not override any existing hook with the same id. This is useful if
the id can be controled by the user.
#### `debug($)`
Logs a debugging message. These are supressed unless verbose mode is turned