1342 conf = config.config(includepaths=templatepaths()) |
1342 conf = config.config(includepaths=templatepaths()) |
1343 conf.read(mapfile, remap={'': 'templates'}) |
1343 conf.read(mapfile, remap={'': 'templates'}) |
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 "'\"": |
1350 # treat as a pointer to a base class for this style |
1351 # treat as a pointer to a base class for this style |
1351 path = util.normpath(os.path.join(base, val)) |
1352 path = util.normpath(os.path.join(base, val)) |
1360 p3 = util.normpath(os.path.join(p2, "map")) |
1361 p3 = util.normpath(os.path.join(p2, "map")) |
1361 if os.path.isfile(p3): |
1362 if os.path.isfile(p3): |
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: |
1369 raise error.ParseError(_('missing value'), |
1370 raise error.ParseError(_('missing value'), |
1370 conf.source('templates', key)) |
1371 conf.source('templates', key)) |
1376 elif key != '__base__': |
1377 elif key != '__base__': |
1377 val = 'default', val |
1378 val = 'default', val |
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 |
1385 |
1387 |
1386 class templater(object): |
1388 class templater(object): |
1410 @classmethod |
1412 @classmethod |
1411 def frommapfile(cls, mapfile, filters=None, defaults=None, cache=None, |
1413 def frommapfile(cls, mapfile, filters=None, defaults=None, cache=None, |
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): |
1421 return key in self.cache or key in self.map |
1424 return key in self.cache or key in self.map |
1422 |
1425 |