Show More
@@ -237,14 +237,17 b' class hgweb(object):' | |||||
237 | # figure out which style to use |
|
237 | # figure out which style to use | |
238 |
|
238 | |||
239 | vars = {} |
|
239 | vars = {} | |
240 | style = self.config("web", "style", "paper") |
|
240 | styles = ( | |
241 | if 'style' in req.form: |
|
241 | req.form.get('style', [None])[0], | |
242 | style = req.form['style'][0] |
|
242 | self.config('web', 'style'), | |
|
243 | 'paper', | |||
|
244 | ) | |||
|
245 | style, mapfile = templater.stylemap(styles, self.templatepath) | |||
|
246 | if style == styles[0]: | |||
243 | vars['style'] = style |
|
247 | vars['style'] = style | |
244 |
|
248 | |||
245 | start = req.url[-1] == '?' and '&' or '?' |
|
249 | start = req.url[-1] == '?' and '&' or '?' | |
246 | sessionvars = webutil.sessionvars(vars, start) |
|
250 | sessionvars = webutil.sessionvars(vars, start) | |
247 | mapfile = templater.stylemap(style, self.templatepath) |
|
|||
248 |
|
251 | |||
249 | if not self.reponame: |
|
252 | if not self.reponame: | |
250 | self.reponame = (self.config("web", "name") |
|
253 | self.reponame = (self.config("web", "name") |
@@ -315,18 +315,21 b' class hgwebdir(object):' | |||||
315 | url += '/' |
|
315 | url += '/' | |
316 |
|
316 | |||
317 | vars = {} |
|
317 | vars = {} | |
318 |
style = |
|
318 | styles = ( | |
319 | if 'style' in req.form: |
|
319 | req.form.get('style', [None])[0], | |
320 | vars['style'] = style = req.form['style'][0] |
|
320 | config('web', 'style'), | |
|
321 | 'paper' | |||
|
322 | ) | |||
|
323 | style, mapfile = templater.stylemap(styles) | |||
|
324 | if style == styles[0]: | |||
|
325 | vars['style'] = style | |||
|
326 | ||||
321 | start = url[-1] == '?' and '&' or '?' |
|
327 | start = url[-1] == '?' and '&' or '?' | |
322 | sessionvars = webutil.sessionvars(vars, start) |
|
328 | sessionvars = webutil.sessionvars(vars, start) | |
323 |
|
||||
324 | staticurl = config('web', 'staticurl') or url + 'static/' |
|
329 | staticurl = config('web', 'staticurl') or url + 'static/' | |
325 | if not staticurl.endswith('/'): |
|
330 | if not staticurl.endswith('/'): | |
326 | staticurl += '/' |
|
331 | staticurl += '/' | |
327 |
|
332 | |||
328 | style = 'style' in req.form and req.form['style'][0] or self.style |
|
|||
329 | mapfile = templater.stylemap(style) |
|
|||
330 | tmpl = templater.templater(mapfile, |
|
333 | tmpl = templater.templater(mapfile, | |
331 | defaults={"header": header, |
|
334 | defaults={"header": header, | |
332 | "footer": footer, |
|
335 | "footer": footer, |
@@ -220,7 +220,7 b' def templatepath(name=None):' | |||||
220 |
|
220 | |||
221 | return normpaths |
|
221 | return normpaths | |
222 |
|
222 | |||
223 | def stylemap(style, paths=None): |
|
223 | def stylemap(styles, paths=None): | |
224 | """Return path to mapfile for a given style. |
|
224 | """Return path to mapfile for a given style. | |
225 |
|
225 | |||
226 | Searches mapfile in the following locations: |
|
226 | Searches mapfile in the following locations: | |
@@ -234,12 +234,20 b' def stylemap(style, paths=None):' | |||||
234 | elif isinstance(paths, str): |
|
234 | elif isinstance(paths, str): | |
235 | paths = [paths] |
|
235 | paths = [paths] | |
236 |
|
236 | |||
237 | locations = style and [os.path.join(style, "map"), "map-" + style] or [] |
|
237 | if isinstance(styles, str): | |
238 | locations.append("map") |
|
238 | styles = [styles] | |
|
239 | ||||
|
240 | for style in styles: | |||
|
241 | ||||
|
242 | if not style: | |||
|
243 | continue | |||
|
244 | locations = [os.path.join(style, 'map'), 'map-' + style] | |||
|
245 | locations.append('map') | |||
|
246 | ||||
239 | for path in paths: |
|
247 | for path in paths: | |
240 | for location in locations: |
|
248 | for location in locations: | |
241 | mapfile = os.path.join(path, location) |
|
249 | mapfile = os.path.join(path, location) | |
242 | if os.path.isfile(mapfile): |
|
250 | if os.path.isfile(mapfile): | |
243 | return mapfile |
|
251 | return style, mapfile | |
244 |
|
252 | |||
245 | raise RuntimeError("No hgweb templates found in %r" % paths) |
|
253 | raise RuntimeError("No hgweb templates found in %r" % paths) |
@@ -7,8 +7,10 b' mkdir da' | |||||
7 | echo foo > da/foo |
|
7 | echo foo > da/foo | |
8 | echo foo > foo |
|
8 | echo foo > foo | |
9 | hg ci -Ambase |
|
9 | hg ci -Ambase | |
|
10 | ||||
10 | hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log |
|
11 | hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log | |
11 | cat hg.pid >> $DAEMON_PIDS |
|
12 | cat hg.pid >> $DAEMON_PIDS | |
|
13 | ||||
12 | echo % manifest |
|
14 | echo % manifest | |
13 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=raw') |
|
15 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=raw') | |
14 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/da?style=raw') |
|
16 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/da?style=raw') | |
@@ -30,6 +32,9 b' echo % should give a 404 - file does not' | |||||
30 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork' |
|
32 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork' | |
31 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/diff/tip/bork?style=raw' |
|
33 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/diff/tip/bork?style=raw' | |
32 |
|
34 | |||
|
35 | echo % try bad style | |||
|
36 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=foobar') | |||
|
37 | ||||
33 | echo % stop and restart |
|
38 | echo % stop and restart | |
34 | "$TESTDIR/killdaemons.py" |
|
39 | "$TESTDIR/killdaemons.py" | |
35 | hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log |
|
40 | hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log |
@@ -148,8 +148,96 b' 404 Not Found' | |||||
148 |
|
148 | |||
149 |
|
149 | |||
150 | error: bork@2ef0ac749a14: not found in manifest |
|
150 | error: bork@2ef0ac749a14: not found in manifest | |
|
151 | % try bad style | |||
|
152 | 200 Script output follows | |||
|
153 | ||||
|
154 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |||
|
155 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> | |||
|
156 | <head> | |||
|
157 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> | |||
|
158 | <meta name="robots" content="index, nofollow" /> | |||
|
159 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |||
|
160 | ||||
|
161 | <title>test: 2ef0ac749a14 /</title> | |||
|
162 | </head> | |||
|
163 | <body> | |||
|
164 | ||||
|
165 | <div class="container"> | |||
|
166 | <div class="menu"> | |||
|
167 | <div class="logo"> | |||
|
168 | <a href="http://mercurial.selenic.com/"> | |||
|
169 | <img src="/static/hglogo.png" alt="mercurial" /></a> | |||
|
170 | </div> | |||
|
171 | <ul> | |||
|
172 | <li><a href="/shortlog/2ef0ac749a14">log</a></li> | |||
|
173 | <li><a href="/graph/2ef0ac749a14">graph</a></li> | |||
|
174 | <li><a href="/tags">tags</a></li> | |||
|
175 | <li><a href="/branches">branches</a></li> | |||
|
176 | </ul> | |||
|
177 | <ul> | |||
|
178 | <li><a href="/rev/2ef0ac749a14">changeset</a></li> | |||
|
179 | <li class="active">browse</li> | |||
|
180 | </ul> | |||
|
181 | <ul> | |||
|
182 | ||||
|
183 | </ul> | |||
|
184 | </div> | |||
|
185 | ||||
|
186 | <div class="main"> | |||
|
187 | <h2><a href="/">test</a></h2> | |||
|
188 | <h3>directory / @ 0:2ef0ac749a14 <span class="tag">tip</span> </h3> | |||
|
189 | ||||
|
190 | <form class="search" action="/log"> | |||
|
191 | ||||
|
192 | <p><input name="rev" id="search1" type="text" size="30" /></p> | |||
|
193 | <div id="hint">find changesets by author, revision, | |||
|
194 | files, or words in the commit message</div> | |||
|
195 | </form> | |||
|
196 | ||||
|
197 | <table class="bigtable"> | |||
|
198 | <tr> | |||
|
199 | <th class="name">name</th> | |||
|
200 | <th class="size">size</th> | |||
|
201 | <th class="permissions">permissions</th> | |||
|
202 | </tr> | |||
|
203 | <tr class="fileline parity0"> | |||
|
204 | <td class="name"><a href="/file/2ef0ac749a14/">[up]</a></td> | |||
|
205 | <td class="size"></td> | |||
|
206 | <td class="permissions">drwxr-xr-x</td> | |||
|
207 | </tr> | |||
|
208 | ||||
|
209 | <tr class="fileline parity1"> | |||
|
210 | <td class="name"> | |||
|
211 | <a href="/file/2ef0ac749a14/da"> | |||
|
212 | <img src="/static/coal-folder.png" alt="dir."/> da/ | |||
|
213 | </a> | |||
|
214 | <a href="/file/2ef0ac749a14/da/"> | |||
|
215 | ||||
|
216 | </a> | |||
|
217 | </td> | |||
|
218 | <td class="size"></td> | |||
|
219 | <td class="permissions">drwxr-xr-x</td> | |||
|
220 | </tr> | |||
|
221 | ||||
|
222 | <tr class="fileline parity0"> | |||
|
223 | <td class="filename"> | |||
|
224 | <a href="/file/2ef0ac749a14/foo"> | |||
|
225 | <img src="/static/coal-file.png" alt="file"/> foo | |||
|
226 | </a> | |||
|
227 | </td> | |||
|
228 | <td class="size">4</td> | |||
|
229 | <td class="permissions">-rw-r--r--</td> | |||
|
230 | </tr> | |||
|
231 | </table> | |||
|
232 | </div> | |||
|
233 | </div> | |||
|
234 | ||||
|
235 | ||||
|
236 | </body> | |||
|
237 | </html> | |||
|
238 | ||||
151 | % stop and restart |
|
239 | % stop and restart | |
152 |
|
|
240 | 10 log lines written | |
153 | % static file |
|
241 | % static file | |
154 | 200 Script output follows |
|
242 | 200 Script output follows | |
155 |
|
243 |
General Comments 0
You need to be logged in to leave comments.
Login now