Show More
@@ -237,14 +237,17 b' class hgweb(object):' | |||
|
237 | 237 | # figure out which style to use |
|
238 | 238 | |
|
239 | 239 | vars = {} |
|
240 | style = self.config("web", "style", "paper") | |
|
241 | if 'style' in req.form: | |
|
242 | style = req.form['style'][0] | |
|
240 | styles = ( | |
|
241 | req.form.get('style', [None])[0], | |
|
242 | self.config('web', 'style'), | |
|
243 | 'paper', | |
|
244 | ) | |
|
245 | style, mapfile = templater.stylemap(styles, self.templatepath) | |
|
246 | if style == styles[0]: | |
|
243 | 247 | vars['style'] = style |
|
244 | 248 | |
|
245 | 249 | start = req.url[-1] == '?' and '&' or '?' |
|
246 | 250 | sessionvars = webutil.sessionvars(vars, start) |
|
247 | mapfile = templater.stylemap(style, self.templatepath) | |
|
248 | 251 | |
|
249 | 252 | if not self.reponame: |
|
250 | 253 | self.reponame = (self.config("web", "name") |
@@ -315,18 +315,21 b' class hgwebdir(object):' | |||
|
315 | 315 | url += '/' |
|
316 | 316 | |
|
317 | 317 | vars = {} |
|
318 |
style = |
|
|
319 | if 'style' in req.form: | |
|
320 | vars['style'] = style = req.form['style'][0] | |
|
318 | styles = ( | |
|
319 | req.form.get('style', [None])[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 | 327 | start = url[-1] == '?' and '&' or '?' |
|
322 | 328 | sessionvars = webutil.sessionvars(vars, start) |
|
323 | ||
|
324 | 329 | staticurl = config('web', 'staticurl') or url + 'static/' |
|
325 | 330 | if not staticurl.endswith('/'): |
|
326 | 331 | staticurl += '/' |
|
327 | 332 | |
|
328 | style = 'style' in req.form and req.form['style'][0] or self.style | |
|
329 | mapfile = templater.stylemap(style) | |
|
330 | 333 | tmpl = templater.templater(mapfile, |
|
331 | 334 | defaults={"header": header, |
|
332 | 335 | "footer": footer, |
@@ -220,7 +220,7 b' def templatepath(name=None):' | |||
|
220 | 220 | |
|
221 | 221 | return normpaths |
|
222 | 222 | |
|
223 | def stylemap(style, paths=None): | |
|
223 | def stylemap(styles, paths=None): | |
|
224 | 224 | """Return path to mapfile for a given style. |
|
225 | 225 | |
|
226 | 226 | Searches mapfile in the following locations: |
@@ -234,12 +234,20 b' def stylemap(style, paths=None):' | |||
|
234 | 234 | elif isinstance(paths, str): |
|
235 | 235 | paths = [paths] |
|
236 | 236 | |
|
237 | locations = style and [os.path.join(style, "map"), "map-" + style] or [] | |
|
238 | locations.append("map") | |
|
239 | for path in paths: | |
|
240 | for location in locations: | |
|
241 | mapfile = os.path.join(path, location) | |
|
242 | if os.path.isfile(mapfile): | |
|
243 | return mapfile | |
|
237 | if isinstance(styles, str): | |
|
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 | ||
|
247 | for path in paths: | |
|
248 | for location in locations: | |
|
249 | mapfile = os.path.join(path, location) | |
|
250 | if os.path.isfile(mapfile): | |
|
251 | return style, mapfile | |
|
244 | 252 | |
|
245 | 253 | raise RuntimeError("No hgweb templates found in %r" % paths) |
@@ -7,8 +7,10 b' mkdir da' | |||
|
7 | 7 | echo foo > da/foo |
|
8 | 8 | echo foo > foo |
|
9 | 9 | hg ci -Ambase |
|
10 | ||
|
10 | 11 | hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log |
|
11 | 12 | cat hg.pid >> $DAEMON_PIDS |
|
13 | ||
|
12 | 14 | echo % manifest |
|
13 | 15 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/?style=raw') |
|
14 | 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 | 32 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork' |
|
31 | 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 | 38 | echo % stop and restart |
|
34 | 39 | "$TESTDIR/killdaemons.py" |
|
35 | 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 | 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 | 239 | % stop and restart |
|
152 |
|
|
|
240 | 10 log lines written | |
|
153 | 241 | % static file |
|
154 | 242 | 200 Script output follows |
|
155 | 243 |
General Comments 0
You need to be logged in to leave comments.
Login now