Mercurial > public > mercurial-scm > hg
comparison mercurial/templater.py @ 7966:aa983c3d94a9
templater: move stylemap function from hgweb to templater
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 04 Apr 2009 17:46:11 +0200 |
parents | cf7741aa1e96 |
children | b5db7dcc1497 |
comparison
equal
deleted
inserted
replaced
7965:8503adbd9d49 | 7966:aa983c3d94a9 |
---|---|
181 elif os.path.isdir(p): | 181 elif os.path.isdir(p): |
182 normpaths.append(os.path.normpath(p)) | 182 normpaths.append(os.path.normpath(p)) |
183 | 183 |
184 return normpaths | 184 return normpaths |
185 | 185 |
186 def stylemap(style, paths=None): | |
187 """Return path to mapfile for a given style. | |
188 | |
189 Searches mapfile in the following locations: | |
190 1. templatepath/style/map | |
191 2. templatepath/map-style | |
192 3. templatepath/map | |
193 """ | |
194 | |
195 if paths is None: | |
196 paths = templatepath() | |
197 elif isinstance(paths, str): | |
198 paths = [templatepath] | |
199 | |
200 locations = style and [os.path.join(style, "map"), "map-" + style] or [] | |
201 locations.append("map") | |
202 for path in paths: | |
203 for location in locations: | |
204 mapfile = os.path.join(path, location) | |
205 if os.path.isfile(mapfile): | |
206 return mapfile | |
207 | |
208 raise RuntimeError("No hgweb templates found in %r" % paths) | |
209 | |
186 def stringify(thing): | 210 def stringify(thing): |
187 '''turn nested template iterator into string.''' | 211 '''turn nested template iterator into string.''' |
188 if hasattr(thing, '__iter__'): | 212 if hasattr(thing, '__iter__'): |
189 return "".join([stringify(t) for t in thing if t is not None]) | 213 return "".join([stringify(t) for t in thing if t is not None]) |
190 return str(thing) | 214 return str(thing) |
191 |