Show More
@@ -10,9 +10,7 b'' | |||||
10 |
|
10 | |||
11 | from mercurial import demandimport |
|
11 | from mercurial import demandimport | |
12 | demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',]) |
|
12 | demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',]) | |
13 |
|
||||
14 | from mercurial import util, encoding |
|
13 | from mercurial import util, encoding | |
15 | from mercurial.templatefilters import filters |
|
|||
16 |
|
14 | |||
17 | from pygments import highlight |
|
15 | from pygments import highlight | |
18 | from pygments.util import ClassNotFound |
|
16 | from pygments.util import ClassNotFound | |
@@ -55,7 +53,7 b' def pygmentize(field, fctx, style, tmpl)' | |||||
55 | colorized = colorized[colorized.find('<pre>')+5:] |
|
53 | colorized = colorized[colorized.find('<pre>')+5:] | |
56 | coloriter = iter(colorized.splitlines()) |
|
54 | coloriter = iter(colorized.splitlines()) | |
57 |
|
55 | |||
58 | filters['colorize'] = lambda x: coloriter.next() |
|
56 | tmpl.filters['colorize'] = lambda x: coloriter.next() | |
59 |
|
57 | |||
60 | oldl = tmpl.cache[field] |
|
58 | oldl = tmpl.cache[field] | |
61 | newl = oldl.replace('line|escape', 'line|colorize') |
|
59 | newl = oldl.replace('line|escape', 'line|colorize') |
@@ -712,10 +712,8 b' class changeset_templater(changeset_prin' | |||||
712 |
|
712 | |||
713 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): |
|
713 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): | |
714 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) |
|
714 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) | |
715 | filters = templatefilters.filters.copy() |
|
715 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) | |
716 | filters['formatnode'] = (ui.debugflag and (lambda x: x) |
|
716 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, | |
717 | or (lambda x: x[:12])) |
|
|||
718 | self.t = templater.templater(mapfile, filters, |
|
|||
719 | cache={ |
|
717 | cache={ | |
720 | 'parent': '{rev}:{node|formatnode} ', |
|
718 | 'parent': '{rev}:{node|formatnode} ', | |
721 | 'manifest': '{rev}:{node|formatnode}', |
|
719 | 'manifest': '{rev}:{node|formatnode}', |
@@ -7,8 +7,7 b'' | |||||
7 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | # GNU General Public License version 2, incorporated herein by reference. | |
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | from mercurial import ui, hg, util, hook, error, encoding |
|
10 | from mercurial import ui, hg, util, hook, error, encoding, templater | |
11 | from mercurial import templater, templatefilters |
|
|||
12 | from common import get_mtime, ErrorResponse |
|
11 | from common import get_mtime, ErrorResponse | |
13 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
12 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR | |
14 | from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED |
|
13 | from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED | |
@@ -246,7 +245,7 b' class hgweb(object):' | |||||
246 |
|
245 | |||
247 | # create the templater |
|
246 | # create the templater | |
248 |
|
247 | |||
249 |
tmpl = templater.templater(mapfile, |
|
248 | tmpl = templater.templater(mapfile, | |
250 | defaults={"url": req.url, |
|
249 | defaults={"url": req.url, | |
251 | "staticurl": staticurl, |
|
250 | "staticurl": staticurl, | |
252 | "urlbase": urlbase, |
|
251 | "urlbase": urlbase, |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | from mercurial.i18n import _ |
|
10 | from mercurial.i18n import _ | |
11 |
from mercurial import ui, hg, util, templater |
|
11 | from mercurial import ui, hg, util, templater | |
12 | from mercurial import error, encoding |
|
12 | from mercurial import error, encoding | |
13 | from common import ErrorResponse, get_mtime, staticfile, paritygen,\ |
|
13 | from common import ErrorResponse, get_mtime, staticfile, paritygen,\ | |
14 | get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
14 | get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR | |
@@ -304,7 +304,7 b' class hgwebdir(object):' | |||||
304 |
|
304 | |||
305 | style = 'style' in req.form and req.form['style'][0] or self.style |
|
305 | style = 'style' in req.form and req.form['style'][0] or self.style | |
306 | mapfile = templater.stylemap(style) |
|
306 | mapfile = templater.stylemap(style) | |
307 |
tmpl = templater.templater(mapfile, |
|
307 | tmpl = templater.templater(mapfile, | |
308 | defaults={"header": header, |
|
308 | defaults={"header": header, | |
309 | "footer": footer, |
|
309 | "footer": footer, | |
310 | "motd": motd, |
|
310 | "motd": motd, |
@@ -8,6 +8,12 b'' | |||||
8 | import cgi, re, os, time, urllib, textwrap |
|
8 | import cgi, re, os, time, urllib, textwrap | |
9 | import util, templater, encoding |
|
9 | import util, templater, encoding | |
10 |
|
10 | |||
|
11 | def stringify(thing): | |||
|
12 | '''turn nested template iterator into string.''' | |||
|
13 | if hasattr(thing, '__iter__') and not isinstance(thing, str): | |||
|
14 | return "".join([stringify(t) for t in thing if t is not None]) | |||
|
15 | return str(thing) | |||
|
16 | ||||
11 | agescales = [("second", 1), |
|
17 | agescales = [("second", 1), | |
12 | ("minute", 60), |
|
18 | ("minute", 60), | |
13 | ("hour", 3600), |
|
19 | ("hour", 3600), | |
@@ -194,7 +200,7 b' filters = {' | |||||
194 | "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"), |
|
200 | "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"), | |
195 | "short": lambda x: x[:12], |
|
201 | "short": lambda x: x[:12], | |
196 | "shortdate": util.shortdate, |
|
202 | "shortdate": util.shortdate, | |
197 |
"stringify": |
|
203 | "stringify": stringify, | |
198 | "strip": lambda x: x.strip(), |
|
204 | "strip": lambda x: x.strip(), | |
199 | "urlescape": lambda x: urllib.quote(x), |
|
205 | "urlescape": lambda x: urllib.quote(x), | |
200 | "user": lambda x: util.shortuser(x), |
|
206 | "user": lambda x: util.shortuser(x), |
@@ -7,9 +7,10 b'' | |||||
7 |
|
7 | |||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import re, sys, os |
|
9 | import re, sys, os | |
10 | import util, config |
|
10 | import util, config, templatefilters | |
11 |
|
11 | |||
12 | path = ['templates', '../templates'] |
|
12 | path = ['templates', '../templates'] | |
|
13 | stringify = templatefilters.stringify | |||
13 |
|
14 | |||
14 | def parsestring(s, quoted=True): |
|
15 | def parsestring(s, quoted=True): | |
15 | '''parse a string using simple c-like syntax. |
|
16 | '''parse a string using simple c-like syntax. | |
@@ -116,7 +117,8 b' class templater(object):' | |||||
116 | self.cache = cache.copy() |
|
117 | self.cache = cache.copy() | |
117 | self.map = {} |
|
118 | self.map = {} | |
118 | self.base = (mapfile and os.path.dirname(mapfile)) or '' |
|
119 | self.base = (mapfile and os.path.dirname(mapfile)) or '' | |
119 | self.filters = filters |
|
120 | self.filters = templatefilters.filters.copy() | |
|
121 | self.filters.update(filters) | |||
120 | self.defaults = defaults |
|
122 | self.defaults = defaults | |
121 | self.minchunk, self.maxchunk = minchunk, maxchunk |
|
123 | self.minchunk, self.maxchunk = minchunk, maxchunk | |
122 |
|
124 | |||
@@ -207,9 +209,3 b' def stylemap(style, paths=None):' | |||||
207 | return mapfile |
|
209 | return mapfile | |
208 |
|
210 | |||
209 | raise RuntimeError("No hgweb templates found in %r" % paths) |
|
211 | raise RuntimeError("No hgweb templates found in %r" % paths) | |
210 |
|
||||
211 | def stringify(thing): |
|
|||
212 | '''turn nested template iterator into string.''' |
|
|||
213 | if hasattr(thing, '__iter__') and not isinstance(thing, str): |
|
|||
214 | return "".join([stringify(t) for t in thing if t is not None]) |
|
|||
215 | return str(thing) |
|
General Comments 0
You need to be logged in to leave comments.
Login now