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