Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 45328:ba50c8a95e2b
templater: move stylemap() to hgweb_mod, since that's its only user
`stylemap()` even has an error message that mentions "hgweb
templates", so it seems that it's meant specifically for hgweb.
Differential Revision: https://phab.mercurial-scm.org/D8890
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 04 Aug 2020 09:13:10 -0700 |
parents | d783f945a701 |
children | d12fba074cc6 |
comparison
equal
deleted
inserted
replaced
45327:9a5c4875a88c | 45328:ba50c8a95e2b |
---|---|
51 styles = ( | 51 styles = ( |
52 req.qsparams.get(b'style', None), | 52 req.qsparams.get(b'style', None), |
53 configfn(b'web', b'style'), | 53 configfn(b'web', b'style'), |
54 b'paper', | 54 b'paper', |
55 ) | 55 ) |
56 return styles, templater.stylemap(styles, templatepath) | 56 return styles, _stylemap(styles, templatepath) |
57 | |
58 | |
59 def _stylemap(styles, path=None): | |
60 """Return path to mapfile for a given style. | |
61 | |
62 Searches mapfile in the following locations: | |
63 1. templatepath/style/map | |
64 2. templatepath/map-style | |
65 3. templatepath/map | |
66 """ | |
67 | |
68 if path is None: | |
69 path = templater.templatedir() | |
70 | |
71 if path is not None: | |
72 for style in styles: | |
73 # only plain name is allowed to honor template paths | |
74 if ( | |
75 not style | |
76 or style in (pycompat.oscurdir, pycompat.ospardir) | |
77 or pycompat.ossep in style | |
78 or pycompat.osaltsep | |
79 and pycompat.osaltsep in style | |
80 ): | |
81 continue | |
82 locations = [os.path.join(style, b'map'), b'map-' + style] | |
83 locations.append(b'map') | |
84 | |
85 for location in locations: | |
86 mapfile = os.path.join(path, location) | |
87 if os.path.isfile(mapfile): | |
88 return style, mapfile | |
89 | |
90 raise RuntimeError(b"No hgweb templates found in %r" % path) | |
57 | 91 |
58 | 92 |
59 def makebreadcrumb(url, prefix=b''): | 93 def makebreadcrumb(url, prefix=b''): |
60 '''Return a 'URL breadcrumb' list | 94 '''Return a 'URL breadcrumb' list |
61 | 95 |