Show More
@@ -64,25 +64,6 b' def write(*things):' | |||||
64 | else: |
|
64 | else: | |
65 | sys.stdout.write(str(thing)) |
|
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 | class templater: |
|
67 | class templater: | |
87 | def __init__(self, mapfile, filters = {}, defaults = {}): |
|
68 | def __init__(self, mapfile, filters = {}, defaults = {}): | |
88 | self.cache = {} |
|
69 | self.cache = {} | |
@@ -109,7 +90,37 b' class templater:' | |||||
109 | tmpl = self.cache[t] |
|
90 | tmpl = self.cache[t] | |
110 | except KeyError: |
|
91 | except KeyError: | |
111 | tmpl = self.cache[t] = file(self.map[t]).read() |
|
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 | def rfc822date(x): |
|
125 | def rfc822date(x): | |
115 | return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) |
|
126 | return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) | |
@@ -560,10 +571,9 b' class hgweb:' | |||||
560 | def entries(**map): |
|
571 | def entries(**map): | |
561 | parity = 0 |
|
572 | parity = 0 | |
562 | for k,n in i: |
|
573 | for k,n in i: | |
563 |
yield |
|
574 | yield {"parity": parity, | |
564 |
|
|
575 | "tag": k, | |
565 |
|
|
576 | "node": hex(n)} | |
566 | node = hex(n)) |
|
|||
567 | parity = 1 - parity |
|
577 | parity = 1 - parity | |
568 |
|
578 | |||
569 | yield self.t("tags", |
|
579 | yield self.t("tags", |
General Comments 0
You need to be logged in to leave comments.
Login now