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