comparison pylons_app/lib/helpers.py @ 491:c3236d7febad

fixed, empty cs bug. Implemented as webhlepers function
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 03 Sep 2010 09:55:48 +0200
parents 4679105ef03e
children 4187d93c7c04
comparison
equal deleted inserted replaced
489:ac21f018f6be 491:c3236d7febad
217 def pygmentize(filenode, **kwargs): 217 def pygmentize(filenode, **kwargs):
218 """ 218 """
219 pygmentize function using pygments 219 pygmentize function using pygments
220 @param filenode: 220 @param filenode:
221 """ 221 """
222 return literal(code_highlight(filenode.content, 222 return literal(code_highlight(filenode.content,
223 filenode.lexer, HtmlFormatter(**kwargs))) 223 filenode.lexer, HtmlFormatter(**kwargs)))
224 224
225 def pygmentize_annotation(filenode, **kwargs): 225 def pygmentize_annotation(filenode, **kwargs):
226 """ 226 """
227 pygmentize function for annotation 227 pygmentize function for annotation
237 n = 10000 237 n = 10000
238 golden_ratio = 0.618033988749895 238 golden_ratio = 0.618033988749895
239 h = 0.22717784590367374 239 h = 0.22717784590367374
240 #generate 10k nice web friendly colors in the same order 240 #generate 10k nice web friendly colors in the same order
241 for c in xrange(n): 241 for c in xrange(n):
242 h +=golden_ratio 242 h += golden_ratio
243 h %= 1 243 h %= 1
244 HSV_tuple = [h, 0.95, 0.95] 244 HSV_tuple = [h, 0.95, 0.95]
245 RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple) 245 RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple)
246 yield map(lambda x:str(int(x*256)),RGB_tuple) 246 yield map(lambda x:str(int(x * 256)), RGB_tuple)
247 247
248 cgenerator = gen_color() 248 cgenerator = gen_color()
249 249
250 def get_color_string(cs): 250 def get_color_string(cs):
251 if color_dict.has_key(cs): 251 if color_dict.has_key(cs):
253 else: 253 else:
254 col = color_dict[cs] = cgenerator.next() 254 col = color_dict[cs] = cgenerator.next()
255 return "color: rgb(%s)! important;" % (', '.join(col)) 255 return "color: rgb(%s)! important;" % (', '.join(col))
256 256
257 def url_func(changeset): 257 def url_func(changeset):
258 tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>"+\ 258 tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>" + \
259 " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" 259 " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>"
260 260
261 tooltip_html = tooltip_html % (changeset.author, 261 tooltip_html = tooltip_html % (changeset.author,
262 changeset.date, 262 changeset.date,
263 tooltip(changeset.message)) 263 tooltip(changeset.message))
284 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|:""": 284 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|:""":
285 slug = slug.replace(c, '-') 285 slug = slug.replace(c, '-')
286 slug = recursive_replace(slug, '-') 286 slug = recursive_replace(slug, '-')
287 return slug 287 return slug
288 288
289 def get_changeset_safe(repo, rev):
290 from vcs.backends.base import BaseRepository
291 from vcs.exceptions import RepositoryError
292 if not isinstance(repo, BaseRepository):
293 raise Exception('You must pass an Repository '
294 'object as first argument got %s', type(repo))
295
296 try:
297 cs = repo.get_changeset(rev)
298 except RepositoryError:
299 from pylons_app.lib.utils import EmptyChangeset
300 cs = EmptyChangeset()
301 return cs
302
303
289 flash = _Flash() 304 flash = _Flash()
290 305
291 306
292 #=============================================================================== 307 #===============================================================================
293 # MERCURIAL FILTERS available via h. 308 # MERCURIAL FILTERS available via h.