##// END OF EJS Templates
hgwebdir: split out templater creation
Dirkjan Ochtman -
r5602:d676d0f3 default
parent child Browse files
Show More
@@ -70,47 +70,6 b' class hgwebdir(object):'
70 return req
70 return req
71
71
72 def run_wsgi(self, req):
72 def run_wsgi(self, req):
73 def header(**map):
74 header_file = cStringIO.StringIO(
75 ''.join(tmpl("header", encoding=util._encoding, **map)))
76 msg = mimetools.Message(header_file, 0)
77 req.header(msg.items())
78 yield header_file.read()
79
80 def footer(**map):
81 yield tmpl("footer", **map)
82
83 def motd(**map):
84 if self.motd is not None:
85 yield self.motd
86 else:
87 yield config('web', 'motd', '')
88
89 def config(section, name, default=None, untrusted=True):
90 return self.parentui.config(section, name, default, untrusted)
91
92 url = req.env.get('SCRIPT_NAME', '')
93 if not url.endswith('/'):
94 url += '/'
95
96 staticurl = config('web', 'staticurl') or url + 'static/'
97 if not staticurl.endswith('/'):
98 staticurl += '/'
99
100 style = self.style
101 if style is None:
102 style = config('web', 'style', '')
103 if req.form.has_key('style'):
104 style = req.form['style'][0]
105 if self.stripecount is None:
106 self.stripecount = int(config('web', 'stripes', 1))
107 mapfile = style_map(templater.templatepath(), style)
108 tmpl = templater.templater(mapfile, templater.common_filters,
109 defaults={"header": header,
110 "footer": footer,
111 "motd": motd,
112 "url": url,
113 "staticurl": staticurl})
114
73
115 try:
74 try:
116 try:
75 try:
@@ -137,6 +96,7 b' class hgwebdir(object):'
137 # browse subdirectories
96 # browse subdirectories
138 subdir = virtual + '/'
97 subdir = virtual + '/'
139 if [r for r in repos if r.startswith(subdir)]:
98 if [r for r in repos if r.startswith(subdir)]:
99 tmpl = self.templater(req)
140 self.makeindex(req, tmpl, subdir)
100 self.makeindex(req, tmpl, subdir)
141 return
101 return
142
102
@@ -145,6 +105,7 b' class hgwebdir(object):'
145 break
105 break
146 virtual = virtual[:up]
106 virtual = virtual[:up]
147
107
108 tmpl = self.templater(req)
148 req.respond(404, tmpl("notfound", repo=virtual))
109 req.respond(404, tmpl("notfound", repo=virtual))
149 else:
110 else:
150 if req.form.has_key('static'):
111 if req.form.has_key('static'):
@@ -152,6 +113,7 b' class hgwebdir(object):'
152 fname = req.form['static'][0]
113 fname = req.form['static'][0]
153 req.write(staticfile(static, fname, req))
114 req.write(staticfile(static, fname, req))
154 else:
115 else:
116 tmpl = self.templater(req)
155 self.makeindex(req, tmpl)
117 self.makeindex(req, tmpl)
156 except ErrorResponse, err:
118 except ErrorResponse, err:
157 req.respond(err.code, tmpl('error', error=err.message or ''))
119 req.respond(err.code, tmpl('error', error=err.message or ''))
@@ -259,3 +221,48 b' class hgwebdir(object):'
259 req.write(tmpl("index", entries=entries, subdir=subdir,
221 req.write(tmpl("index", entries=entries, subdir=subdir,
260 sortcolumn=sortcolumn, descending=descending,
222 sortcolumn=sortcolumn, descending=descending,
261 **dict(sort)))
223 **dict(sort)))
224
225 def templater(self, req):
226
227 def header(**map):
228 header_file = cStringIO.StringIO(
229 ''.join(tmpl("header", encoding=util._encoding, **map)))
230 msg = mimetools.Message(header_file, 0)
231 req.header(msg.items())
232 yield header_file.read()
233
234 def footer(**map):
235 yield tmpl("footer", **map)
236
237 def motd(**map):
238 if self.motd is not None:
239 yield self.motd
240 else:
241 yield config('web', 'motd', '')
242
243 def config(section, name, default=None, untrusted=True):
244 return self.parentui.config(section, name, default, untrusted)
245
246 url = req.env.get('SCRIPT_NAME', '')
247 if not url.endswith('/'):
248 url += '/'
249
250 staticurl = config('web', 'staticurl') or url + 'static/'
251 if not staticurl.endswith('/'):
252 staticurl += '/'
253
254 style = self.style
255 if style is None:
256 style = config('web', 'style', '')
257 if req.form.has_key('style'):
258 style = req.form['style'][0]
259 if self.stripecount is None:
260 self.stripecount = int(config('web', 'stripes', 1))
261 mapfile = style_map(templater.templatepath(), style)
262 tmpl = templater.templater(mapfile, templater.common_filters,
263 defaults={"header": header,
264 "footer": footer,
265 "motd": motd,
266 "url": url,
267 "staticurl": staticurl})
268 return tmpl
General Comments 0
You need to be logged in to leave comments. Login now