How do I hook that into TurboGears/Kid so that it's used in *addition*
to turbokid ( i.e. I can use py:extends from my external templates to
load both external and on-disk templates)?
In Kid, specifically in kid/importer.py you will find the import hooks that Kid uses to load files with a Kid extension. This is how they are treated the same as .py files on an import.
What you can do is create your own handlers for say .dbkid files. This will call code in your handler and allow you to do whatever you like. I would use a changed file extension like .dbkid so things are not confusing if you report errors.
This is NOT tested:
DBKID_FILE = object()
class DBKIDHooks(ihooks.Hooks):
def get_suffixes(self):
return [('.dbkid', 'r', DBKID_FILE)] + imp.get_suffixes()
class DBKIDLoader(ihooks.ModuleLoader):
def load_module(self, name, stuff):
file, filename, info = stuff
(suff, mode, type) = info
if type is DBKID_FILE:
# get your file here from the database and feed it into Kid
# and then return the resulting module object
else:
return ihooks.ModuleLoader.load_module(self, name, stuff)
-- David

