##// END OF EJS Templates
Added support for #foo%bar# syntax...
Josef "Jeff" Sipek -
r974:aedb4776 default
parent child Browse files
Show More
@@ -64,25 +64,6 b' def write(*things):'
64 64 else:
65 65 sys.stdout.write(str(thing))
66 66
67 def template(tmpl, filters = {}, **map):
68 while tmpl:
69 m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl)
70 if m:
71 yield tmpl[:m.start(0)]
72 v = map.get(m.group(1), "")
73 v = callable(v) and v(**map) or v
74
75 fl = m.group(2)
76 if fl:
77 for f in fl.split("|")[1:]:
78 v = filters[f](v)
79
80 yield v
81 tmpl = tmpl[m.end(0):]
82 else:
83 yield tmpl
84 return
85
86 67 class templater:
87 68 def __init__(self, mapfile, filters = {}, defaults = {}):
88 69 self.cache = {}
@@ -109,7 +90,37 b' class templater:'
109 90 tmpl = self.cache[t]
110 91 except KeyError:
111 92 tmpl = self.cache[t] = file(self.map[t]).read()
112 return template(tmpl, self.filters, **m)
93 return self.template(tmpl, self.filters, **m)
94
95 def template(self, tmpl, filters = {}, **map):
96 while tmpl:
97 m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl)
98 if m:
99 yield tmpl[:m.start(0)]
100 v = map.get(m.group(1), "")
101 v = callable(v) and v(**map) or v
102
103 format = m.group(2)
104 fl = m.group(4)
105
106 if format:
107 q = v.__iter__
108 for i in q():
109 lm = map.copy()
110 lm.update(i)
111 yield self(format[1:], **lm)
112
113 v = ""
114
115 elif fl:
116 for f in fl.split("|")[1:]:
117 v = filters[f](v)
118
119 yield v
120 tmpl = tmpl[m.end(0):]
121 else:
122 yield tmpl
123 return
113 124
114 125 def rfc822date(x):
115 126 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x))
@@ -560,10 +571,9 b' class hgweb:'
560 571 def entries(**map):
561 572 parity = 0
562 573 for k,n in i:
563 yield self.t("tagentry",
564 parity = parity,
565 tag = k,
566 node = hex(n))
574 yield {"parity": parity,
575 "tag": k,
576 "node": hex(n)}
567 577 parity = 1 - parity
568 578
569 579 yield self.t("tags",
@@ -11,7 +11,7 b''
11 11 <h2>tags:</h2>
12 12
13 13 <ul id="tagEntries">
14 #entries#
14 #entries%tagentry#
15 15 </ul>
16 16
17 17 #footer#
General Comments 0
You need to be logged in to leave comments. Login now