]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add no_override parameter to hook().
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 15 Oct 2006 19:33:52 +0000 (19:33 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 15 Oct 2006 19:33:52 +0000 (19:33 +0000)
* 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.

IkiWiki.pm
IkiWiki/Plugin/shortcut.pm [new file with mode: 0644]
basewiki/shortcuts.mdwn [new file with mode: 0644]
debian/changelog
doc/plugins/contrib/googlemaps.mdwn
doc/plugins/contrib/img.mdwn
doc/plugins/contrib/linguas.mdwn
doc/plugins/contrib/shortcuts.mdwn
doc/plugins/contrib/shortcuts/discussion.mdwn
doc/plugins/shortcut.mdwn [new file with mode: 0644]
doc/plugins/write.mdwn

index a39e317f574304fbbde0d49aaec9ac2c5c1612a1..7084e9627aa5258d3f3f9bc34d3b82f867d89c3e 100644 (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;
 } # }}}
diff --git a/IkiWiki/Plugin/shortcut.pm b/IkiWiki/Plugin/shortcut.pm
new file mode 100644 (file)
index 0000000..d09d587
--- /dev/null
@@ -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
diff --git a/basewiki/shortcuts.mdwn b/basewiki/shortcuts.mdwn
new file mode 100644 (file)
index 0000000..7dde791
--- /dev/null
@@ -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.
index 01a63aae1f32032d350effd3198dd970ec06526c..3aeeccb1117338d01e24f6b1e65db5bf453d97cb 100644 (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.
index 2ea4e4fa41ff478bbe2db1f379c17a354238814c..56d2d6031da7a4108a5ad173c8b0e99695db4cf3 100644 (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.
index f2133a38b93e32116d810991c3ba8bb0d610b622..72b8579e0737e072d4e404f40c1acf5a61d6c7f0 100644 (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.
 
index cf7a458c72a46e5e291bbba65e3cfd9219262d39..c90e11a5477d3c75eeceb32d446015829ee72106 100644 (file)
@@ -1,4 +1,5 @@
 [[template id=plugin name=linguas author="Jordà Polo"]]
+[[meta title"linguas (third-party plugin)"]]
 
 Linguas
 =======
index eb13bb106df241ccaf8a401046460f038dd41b59..81c2cf8dcc9c05e880b1651d328bb38298be6232 100644 (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
index 367d1b9a343c2f5f5ca152faeccf01475446fbf2..70f962f1da91f98181c699545f346cf8a78b0368 100644 (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]]
diff --git a/doc/plugins/shortcut.mdwn b/doc/plugins/shortcut.mdwn
new file mode 100644 (file)
index 0000000..33180b1
--- /dev/null
@@ -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.
index 18aa34dca7b304f9028c6d3b5a98583aa91e75a1..1beafa3952f37d44b2e853e25fff6c21471bece5 100644 (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