templatepath.py
author Scott Ehlert <ds@alliedmods.net>
Mon Oct 26 01:02:28 2009 -0500 (2009-10-26)
changeset 1 8a55da2d6618
parent 0 f59a7c3bf23e
permissions -rw-r--r--
Imported bugzilla extension from mercurial 1.3.1.
     1 # vim: set ts=4 sw=4 tw=99 et ft=python:
     2 
     3 '''allows overriding of templates directory for hgwebdir
     4 
     5 The code in hgweb/hgweb_mod.py allows you to override the templates directory path using the
     6 web.templates option. However, this is not allowed by hgweb/hgwebdir_mod.py. This extension fixes
     7 this problem by using the same web.templates option.
     8 
     9 However, extensions are not normally loaded when hgwebdir is in use. In order to fix this, you must
    10 modify the hgwebdir CGI script like so:
    11 
    12     from mercurial import extensions
    13     from mercurial.hgweb.hgwebdir_mod import hgwebdir
    14     import mercurial.hgweb.wsgicgi as wsgicgi
    15 
    16     application = hgwebdir('hgweb.config')
    17     extensions.loadall(application.ui)
    18     wsgicgi.launch(application)
    19 
    20 To enable this extension:
    21 
    22     [extensions]
    23     templatepath = /path/to/templatepath.py
    24 '''
    25 
    26 import os
    27 from mercurial import extensions, templater
    28 
    29 _ui = None
    30 
    31 def uisetup(ui):
    32     global _ui
    33     _ui = ui
    34     extensions.wrapfunction(templater, 'templatepath', hook_templatepath)
    35 
    36 def hook_templatepath(orig, name=None):
    37     templates = _ui.config('web', 'templates')
    38 
    39     if not templates:
    40         return orig(name)
    41 
    42     if name:
    43         path = os.path.join(templates, name)
    44         if os.path.exists(path):
    45             return os.path.normpath(path)
    46 
    47     return [templates]