##// END OF EJS Templates
templater: load aliases from [templatealias] section in map file...
Yuya Nishihara -
r34716:f17a0e18 default
parent child Browse files
Show More
@@ -418,8 +418,8 b' def lookuptemplate(ui, topic, tmpl):'
418
418
419 A map file defines a stand-alone template environment. If a map file
419 A map file defines a stand-alone template environment. If a map file
420 selected, all templates defined in the file will be loaded, and the
420 selected, all templates defined in the file will be loaded, and the
421 template matching the given topic will be rendered. No aliases will be
421 template matching the given topic will be rendered. Aliases won't be
422 loaded from user config.
422 loaded from user config, but from the map file.
423
423
424 If no map file selected, all templates in [templates] section will be
424 If no map file selected, all templates in [templates] section will be
425 available as well as aliases in [templatealias].
425 available as well as aliases in [templatealias].
@@ -1344,6 +1344,7 b' def _readmapfile(mapfile):'
1344
1344
1345 cache = {}
1345 cache = {}
1346 tmap = {}
1346 tmap = {}
1347 aliases = []
1347
1348
1348 val = conf.get('templates', '__base__')
1349 val = conf.get('templates', '__base__')
1349 if val and val[0] not in "'\"":
1350 if val and val[0] not in "'\"":
@@ -1362,7 +1363,7 b' def _readmapfile(mapfile):'
1362 path = p3
1363 path = p3
1363 break
1364 break
1364
1365
1365 cache, tmap = _readmapfile(path)
1366 cache, tmap, aliases = _readmapfile(path)
1366
1367
1367 for key, val in conf['templates'].items():
1368 for key, val in conf['templates'].items():
1368 if not val:
1369 if not val:
@@ -1378,7 +1379,8 b' def _readmapfile(mapfile):'
1378 if ':' in val[1]:
1379 if ':' in val[1]:
1379 val = val[1].split(':', 1)
1380 val = val[1].split(':', 1)
1380 tmap[key] = val[0], os.path.join(base, val[1])
1381 tmap[key] = val[0], os.path.join(base, val[1])
1381 return cache, tmap
1382 aliases.extend(conf['templatealias'].items())
1383 return cache, tmap, aliases
1382
1384
1383 class TemplateNotFound(error.Abort):
1385 class TemplateNotFound(error.Abort):
1384 pass
1386 pass
@@ -1412,9 +1414,10 b' class templater(object):'
1412 minchunk=1024, maxchunk=65536):
1414 minchunk=1024, maxchunk=65536):
1413 """Create templater from the specified map file"""
1415 """Create templater from the specified map file"""
1414 t = cls(filters, defaults, cache, [], minchunk, maxchunk)
1416 t = cls(filters, defaults, cache, [], minchunk, maxchunk)
1415 cache, tmap = _readmapfile(mapfile)
1417 cache, tmap, aliases = _readmapfile(mapfile)
1416 t.cache.update(cache)
1418 t.cache.update(cache)
1417 t.map = tmap
1419 t.map = tmap
1420 t._aliases = aliases
1418 return t
1421 return t
1419
1422
1420 def __contains__(self, key):
1423 def __contains__(self, key):
@@ -259,11 +259,13 b' Test templates and style maps in files:'
259 $ hg log -l1 -T./map-simple
259 $ hg log -l1 -T./map-simple
260 8
260 8
261
261
262 a map file may have [templates] section:
262 a map file may have [templates] and [templatealias] sections:
263
263
264 $ cat <<'EOF' > map-simple
264 $ cat <<'EOF' > map-simple
265 > [templates]
265 > [templates]
266 > changeset = "{rev}\n"
266 > changeset = "{a}\n"
267 > [templatealias]
268 > a = rev
267 > EOF
269 > EOF
268 $ hg log -l1 -T./map-simple
270 $ hg log -l1 -T./map-simple
269 8
271 8
@@ -277,6 +279,8 b' Test templates and style maps in files:'
277 > EOF
279 > EOF
278 $ HGRCPATH=./myhgrc hg log -l1 -Tfoo
280 $ HGRCPATH=./myhgrc hg log -l1 -Tfoo
279 8
281 8
282 $ HGRCPATH=./myhgrc hg log -l1 -T'{a}\n'
283 8
280
284
281 Test template map inheritance
285 Test template map inheritance
282
286
General Comments 0
You need to be logged in to leave comments. Login now