Show More
@@ -78,7 +78,7 class templater(object): | |||
|
78 | 78 | raise SyntaxError(_("%s:%s: parse error") % (mapfile, i)) |
|
79 | 79 | |
|
80 | 80 | def __contains__(self, key): |
|
81 | return key in self.cache | |
|
81 | return key in self.cache or key in self.map | |
|
82 | 82 | |
|
83 | 83 | def __call__(self, t, **map): |
|
84 | 84 | '''perform expansion. |
@@ -86,20 +86,18 class templater(object): | |||
|
86 | 86 | map is added elements to use during expansion.''' |
|
87 | 87 | m = self.defaults.copy() |
|
88 | 88 | m.update(map) |
|
89 | if not self.cache.has_key(t): | |
|
89 | 90 | try: |
|
90 |
|
|
|
91 | except KeyError: | |
|
92 | try: | |
|
93 | tmpl = self.cache[t] = file(self.map[t]).read() | |
|
91 | self.cache[t] = file(self.map[t]).read() | |
|
94 | 92 | except IOError, inst: |
|
95 | 93 | raise IOError(inst.args[0], _('template file %s: %s') % |
|
96 | 94 | (self.map[t], inst.args[1])) |
|
97 |
return self.template( |
|
|
95 | return self.template(self.cache[t], **m) | |
|
98 | 96 | |
|
99 | 97 | template_re = re.compile(r"(?:(?:#(?=[\w\|%]+#))|(?:{(?=[\w\|%]+})))" |
|
100 | 98 | r"(\w+)((%\w+)*)((\|\w+)*)[#}]") |
|
101 | 99 | |
|
102 |
def template(self, tmpl, |
|
|
100 | def template(self, tmpl, **map): | |
|
103 | 101 | while tmpl: |
|
104 | 102 | m = self.template_re.search(tmpl) |
|
105 | 103 | if m: |
@@ -128,7 +126,7 class templater(object): | |||
|
128 | 126 | |
|
129 | 127 | elif fl: |
|
130 | 128 | for f in fl.split("|")[1:]: |
|
131 | v = filters[f](v) | |
|
129 | v = self.filters[f](v) | |
|
132 | 130 | |
|
133 | 131 | yield v |
|
134 | 132 | tmpl = tmpl[end:] |
General Comments 0
You need to be logged in to leave comments.
Login now