Show More
@@ -984,6 +984,33 b' def stylelist():' | |||||
984 | stylelist.append(split[1]) |
|
984 | stylelist.append(split[1]) | |
985 | return ", ".join(sorted(stylelist)) |
|
985 | return ", ".join(sorted(stylelist)) | |
986 |
|
986 | |||
|
987 | def _readmapfile(mapfile): | |||
|
988 | """Load template elements from the given map file""" | |||
|
989 | if not os.path.exists(mapfile): | |||
|
990 | raise error.Abort(_("style '%s' not found") % mapfile, | |||
|
991 | hint=_("available styles: %s") % stylelist()) | |||
|
992 | ||||
|
993 | base = os.path.dirname(mapfile) | |||
|
994 | conf = config.config(includepaths=templatepaths()) | |||
|
995 | conf.read(mapfile) | |||
|
996 | ||||
|
997 | cache = {} | |||
|
998 | tmap = {} | |||
|
999 | for key, val in conf[''].items(): | |||
|
1000 | if not val: | |||
|
1001 | raise error.ParseError(_('missing value'), conf.source('', key)) | |||
|
1002 | if val[0] in "'\"": | |||
|
1003 | if val[0] != val[-1]: | |||
|
1004 | raise error.ParseError(_('unmatched quotes'), | |||
|
1005 | conf.source('', key)) | |||
|
1006 | cache[key] = unquotestring(val) | |||
|
1007 | else: | |||
|
1008 | val = 'default', val | |||
|
1009 | if ':' in val[1]: | |||
|
1010 | val = val[1].split(':', 1) | |||
|
1011 | tmap[key] = val[0], os.path.join(base, val[1]) | |||
|
1012 | return cache, tmap | |||
|
1013 | ||||
987 | class TemplateNotFound(error.Abort): |
|
1014 | class TemplateNotFound(error.Abort): | |
988 | pass |
|
1015 | pass | |
989 |
|
1016 | |||
@@ -1011,27 +1038,9 b' class templater(object):' | |||||
1011 |
|
1038 | |||
1012 | if not mapfile: |
|
1039 | if not mapfile: | |
1013 | return |
|
1040 | return | |
1014 | if not os.path.exists(mapfile): |
|
1041 | cache, tmap = _readmapfile(mapfile) | |
1015 | raise error.Abort(_("style '%s' not found") % mapfile, |
|
1042 | self.cache.update(cache) | |
1016 | hint=_("available styles: %s") % stylelist()) |
|
1043 | self.map = tmap | |
1017 |
|
||||
1018 | base = os.path.dirname(mapfile) |
|
|||
1019 | conf = config.config(includepaths=templatepaths()) |
|
|||
1020 | conf.read(mapfile) |
|
|||
1021 |
|
||||
1022 | for key, val in conf[''].items(): |
|
|||
1023 | if not val: |
|
|||
1024 | raise error.ParseError(_('missing value'), conf.source('', key)) |
|
|||
1025 | if val[0] in "'\"": |
|
|||
1026 | if val[0] != val[-1]: |
|
|||
1027 | raise error.ParseError(_('unmatched quotes'), |
|
|||
1028 | conf.source('', key)) |
|
|||
1029 | self.cache[key] = unquotestring(val) |
|
|||
1030 | else: |
|
|||
1031 | val = 'default', val |
|
|||
1032 | if ':' in val[1]: |
|
|||
1033 | val = val[1].split(':', 1) |
|
|||
1034 | self.map[key] = val[0], os.path.join(base, val[1]) |
|
|||
1035 |
|
1044 | |||
1036 | def __contains__(self, key): |
|
1045 | def __contains__(self, key): | |
1037 | return key in self.cache or key in self.map |
|
1046 | return key in self.cache or key in self.map |
General Comments 0
You need to be logged in to leave comments.
Login now