diff -r 000000000000 -r f59a7c3bf23e templatepath.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templatepath.py Tue Oct 20 12:51:05 2009 -0500 @@ -0,0 +1,47 @@ +# vim: set ts=4 sw=4 tw=99 et ft=python: + +'''allows overriding of templates directory for hgwebdir + +The code in hgweb/hgweb_mod.py allows you to override the templates directory path using the +web.templates option. However, this is not allowed by hgweb/hgwebdir_mod.py. This extension fixes +this problem by using the same web.templates option. + +However, extensions are not normally loaded when hgwebdir is in use. In order to fix this, you must +modify the hgwebdir CGI script like so: + + from mercurial import extensions + from mercurial.hgweb.hgwebdir_mod import hgwebdir + import mercurial.hgweb.wsgicgi as wsgicgi + + application = hgwebdir('hgweb.config') + extensions.loadall(application.ui) + wsgicgi.launch(application) + +To enable this extension: + + [extensions] + templatepath = /path/to/templatepath.py +''' + +import os +from mercurial import extensions, templater + +_ui = None + +def uisetup(ui): + global _ui + _ui = ui + extensions.wrapfunction(templater, 'templatepath', hook_templatepath) + +def hook_templatepath(orig, name=None): + templates = _ui.config('web', 'templates') + + if not templates: + return orig(name) + + if name: + path = os.path.join(templates, name) + if os.path.exists(path): + return os.path.normpath(path) + + return [templates]