templatepath.py
changeset 0 f59a7c3bf23e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/templatepath.py	Tue Oct 20 12:51:05 2009 -0500
     1.3 @@ -0,0 +1,47 @@
     1.4 +# vim: set ts=4 sw=4 tw=99 et ft=python:
     1.5 +
     1.6 +'''allows overriding of templates directory for hgwebdir
     1.7 +
     1.8 +The code in hgweb/hgweb_mod.py allows you to override the templates directory path using the
     1.9 +web.templates option. However, this is not allowed by hgweb/hgwebdir_mod.py. This extension fixes
    1.10 +this problem by using the same web.templates option.
    1.11 +
    1.12 +However, extensions are not normally loaded when hgwebdir is in use. In order to fix this, you must
    1.13 +modify the hgwebdir CGI script like so:
    1.14 +
    1.15 +    from mercurial import extensions
    1.16 +    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    1.17 +    import mercurial.hgweb.wsgicgi as wsgicgi
    1.18 +
    1.19 +    application = hgwebdir('hgweb.config')
    1.20 +    extensions.loadall(application.ui)
    1.21 +    wsgicgi.launch(application)
    1.22 +
    1.23 +To enable this extension:
    1.24 +
    1.25 +    [extensions]
    1.26 +    templatepath = /path/to/templatepath.py
    1.27 +'''
    1.28 +
    1.29 +import os
    1.30 +from mercurial import extensions, templater
    1.31 +
    1.32 +_ui = None
    1.33 +
    1.34 +def uisetup(ui):
    1.35 +    global _ui
    1.36 +    _ui = ui
    1.37 +    extensions.wrapfunction(templater, 'templatepath', hook_templatepath)
    1.38 +
    1.39 +def hook_templatepath(orig, name=None):
    1.40 +    templates = _ui.config('web', 'templates')
    1.41 +
    1.42 +    if not templates:
    1.43 +        return orig(name)
    1.44 +
    1.45 +    if name:
    1.46 +        path = os.path.join(templates, name)
    1.47 +        if os.path.exists(path):
    1.48 +            return os.path.normpath(path)
    1.49 +
    1.50 +    return [templates]