X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/33e3528cd9d758bd301ecabbb4b2d7bd43334881..2e19c82cb5974b5d2365ae11b6fd4053a299030d:/plugins/pythondemo diff --git a/plugins/pythondemo b/plugins/pythondemo index 7c562c043..213e9bb27 100755 --- a/plugins/pythondemo +++ b/plugins/pythondemo @@ -1,17 +1,38 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # pythondemo — demo Python ikiwiki plugin # # Copyright © martin f. krafft -# Released under the terms of the GNU GPL version 2 -# +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# . +# THIS SOFTWARE IS PROVIDED BY IKIWIKI AND CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# __name__ = 'pythondemo' __description__ = 'demo Python ikiwiki plugin' __version__ = '0.1' __author__ = 'martin f. krafft ' __copyright__ = 'Copyright © ' + __author__ -__licence__ = 'GPLv2' +__licence__ = 'BSD-2-clause' from proxy import IkiWikiProcedureProxy @@ -37,10 +58,11 @@ def getopt_demo(proxy, *args): # it sees an option it cannot process, and should just skip over those # options and leave them in @ARGV. # - # TODO: See - # http://ikiwiki.info/bugs/external_plugins_cannot_access_ARGV_needed_for_getopt debug("hook `getopt' called with arguments %s" % str(args)) - debug('getargv: %s' % str(proxy.rpc('getargv'))) + args = proxy.getargv() + if '--demo' in args: + args = [i for i in args if i != '--demo'] + proxy.setargv(args) proxy.hook('getopt', getopt_demo) def checkconfig_demo(proxy, *args): @@ -48,10 +70,12 @@ def checkconfig_demo(proxy, *args): # configuration. It's called early in the startup process. The function is # passed no values. It's ok for the function to call error() if something # isn't configured right. - # TODO: how do we tell ikiwiki about errors? debug("hook `checkconfig' called with arguments %s" % str(args)) - raise NotImplementedError -#proxy.hook('checkconfig', checkconfig_demo) + # check that --url has been set + url = proxy.getvar('config', 'url') + if url is None or len(url) == 0: + proxy.error('--url has not been set') +proxy.hook('checkconfig', checkconfig_demo) def refresh_demo(proxy, *args): # This hook is called just before ikiwiki scans the wiki for changed @@ -65,7 +89,8 @@ def needsbuild_demo(proxy, *args): # built when the wiki is refreshed. The function is passed a reference to # an array of pages that will be rebuilt, and can modify the array, either # adding or removing files from it. - # TODO: how do we modify the array? + # TODO: how do we modify the array? Joey sees no solution... + # we could just return the array and expect ikiwiki to use that... debug("hook `needsbuild' called with arguments %s" % str(args)) raise NotImplementedError #proxy.hook('needsbuild', needsbuild_demo) @@ -106,12 +131,17 @@ def preprocess_demo(proxy, *args): # through markdown (or whatever engine is used to htmlize the page) along # with the rest of the page. # - # TODO: needs to be handled differently, the ID cannot be the plugin name. kwargs = _arglist_to_dict(args) debug("hook `preprocess' called with arguments %s" % kwargs) - raise NotImplementedError - return kwargs['content'] -#proxy.hook('preprocess', preprocess_demo) + del kwargs['preview'] + del kwargs['page'] + del kwargs['destpage'] + ret = 'foobar preprocessor called with arguments:' + for i in kwargs.iteritems(): + ret += ' %s=%s' % i + return ret +# put [[!foobar ...]] somewhere to try this +proxy.hook('preprocess', preprocess_demo, id='foobar') def linkify_demo(proxy, *args): # This hook is called to convert WikiLinks on the page into html links. @@ -134,11 +164,12 @@ def scan_demo(proxy, *args): # The function is passed named parameters "page" and "content". Its return # value is ignored. # - # TODO: how do we add to %links? kwargs = _arglist_to_dict(args) debug("hook `scan' called with arguments %s" % kwargs) - raise NotImplementedError -#proxy.hook('scan', scan_demo) + links = proxy.getvar('links', kwargs['page']) + debug("links for page `%s' are: %s" % (kwargs['page'], links)) + proxy.setvar('links', kwargs['page'], links) +proxy.hook('scan', scan_demo) def htmlize_demo(proxy, *args): # Runs on the raw source of a page and turns it into html. The id @@ -151,7 +182,7 @@ def htmlize_demo(proxy, *args): kwargs = _arglist_to_dict(args) debug("hook `htmlize' called with arguments %s" % kwargs) return kwargs['content'] -#proxy.hook('htmlize', htmlize_demo) +proxy.hook('htmlize', htmlize_demo) def pagetemplate_demo(proxy, *args): # Templates are filled out for many different things in ikiwiki, like @@ -165,7 +196,7 @@ def pagetemplate_demo(proxy, *args): # # The most common thing to do is probably to call $template->param() to # add a new custom parameter to the template. - # TODO: how do we call $template->param() + # TODO: how do we call $template->param()? kwargs = _arglist_to_dict(args) debug("hook `pagetemplate' called with arguments %s" % kwargs) raise NotImplementedError @@ -180,7 +211,7 @@ def templatefile_demo(proxy, *args): # kwargs = _arglist_to_dict(args) debug("hook `templatefile' called with arguments %s" % kwargs) - return None + return None #leave the default proxy.hook('templatefile', templatefile_demo) def sanitize_demo(proxy, *args): @@ -276,7 +307,6 @@ def canedit_demo(proxy, *args): # since it's sometimes used to test to see which pages in a set of pages # a user can edit. # - # TODO: we cannot return undef/None, see above. # TODO: how do we return a function? debug("hook `canedit' called with arguments %s" % str(args)) raise NotImplementedError