[ home | blog home | recent activity ]
Yesterday I slam-dunked some code to form some infrastructure for plugin modules--I figured I've done this for Lyntin and Stringbean, might as well go for the hat trick! The code allows us to build a set of callback chains and such to let people extend the functionality of pyblosxom without having to re-write pyblosxom internals. Blah blah standard plugin stuff.
At some point, I'll write a tutorial to use it beyond the brief
documentation I left in the api module. Until then,
I leave the following excerpt for how it all ties together using the
pycalendar module as an example.
01: """ 02: This is my fancy pyfortune module. Basically what it's going to do 03: is call /usr/local/bin/fortune and populate the fortune variable 04: with the resulting string. 05: """ 06: import commands 07: from libs import api, tools 08: 09: class PyFortune: 10: def __init__(self): 11: self._fortune = None 12: 13: def getFortune(self, args): 14: entry_dict = args[0] 15: text_string = args[1] 16: if self._fortune == None: 17: self._fortune = commands.getoutput("/usr/games/fortune") 18: 19: return (entry_dict, tools.parse({"fortune": self._fortune}, text_string)) 20: 21: def initialize(): 22: api.parseitem.register(PyFortune().getFortune)
Figure 1: libs/plugins/pyfortune.py
Mmm... It occurs to me that this doesn't use the api
module at all. On the other hand, it's pretty neat looking, so
I'll leave it for now. At some point someone is going to have to
remind me to write an api usage example.
Have a dynamically generated fortune:
...
This fortune has been removed because it turns out that dynamically generated text causes RSS feeds to think this is a new entry every time. Thus, no fortune for you!
Comments:
Post a new comment:
Three things:
If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
pyblosxom::1.5-dev git-master
Copyright 1996 to 2012, Will Guaraldi Kahn-Greene, under the Creative Commons BY-SA 3.0 license

Will's Blog by William Kahn-Greene is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.