Mercurial > public > src > rhodecode
annotate pylons_app/lib/helpers.py @ 292:c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 14 Jun 2010 00:17:08 +0200 |
parents | 237470e64bb8 |
children | 6603c9891b91 |
rev | line source |
---|---|
0 | 1 """Helper functions |
2 | |
3 Consists of functions to typically be used within templates, but also | |
4 available to Controllers. This module is available to both as 'h'. | |
5 """ | |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
6 from pygments.formatters import HtmlFormatter |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
7 from pygments import highlight as code_highlight |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
8 from pylons import url, app_globals as g |
97
be0096a02772
added helper for filesize
Marcin Kuzminski <marcin@python-works.com>
parents:
94
diff
changeset
|
9 from pylons.i18n.translation import _, ungettext |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
10 from vcs.utils.annotate import annotate_highlight |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
11 from webhelpers.html import literal, HTML, escape |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
12 from webhelpers.html.tools import * |
98
01d0f363f36d
added pygments webhelper
Marcin Kuzminski <marcin@python-works.com>
parents:
97
diff
changeset
|
13 from webhelpers.html.builder import make_tag |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
14 from webhelpers.html.tags import auto_discovery_link, checkbox, css_classes, \ |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
15 end_form, file, form, hidden, image, javascript_link, link_to, link_to_if, \ |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
16 link_to_unless, ol, required_legend, select, stylesheet_link, submit, text, \ |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
17 password, textarea, title, ul, xml_declaration, radio |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
18 from webhelpers.html.tools import auto_link, button_to, highlight, js_obfuscate, \ |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
19 mail_to, strip_links, strip_tags, tag_re |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
20 from webhelpers.number import format_byte_size, format_bit_size |
0 | 21 from webhelpers.pylonslib import Flash as _Flash |
22 from webhelpers.pylonslib.secure_form import secure_form | |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
23 from webhelpers.text import chop_at, collapse, convert_accented_entities, \ |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
24 convert_misc_entities, lchop, plural, rchop, remove_formatting, \ |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
25 replace_whitespace, urlify, truncate, wrap_paragraphs |
0 | 26 |
98
01d0f363f36d
added pygments webhelper
Marcin Kuzminski <marcin@python-works.com>
parents:
97
diff
changeset
|
27 |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
28 #Custom helpers here :) |
0 | 29 class _Link(object): |
30 ''' | |
31 Make a url based on label and url with help of url_for | |
32 @param label:name of link if not defined url is used | |
33 @param url: the url for link | |
34 ''' | |
35 | |
43 | 36 def __call__(self, label='', *url_, **urlargs): |
0 | 37 if label is None or '': |
38 label = url | |
43 | 39 link_fn = link_to(label, url(*url_, **urlargs)) |
0 | 40 return link_fn |
41 | |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
42 link = _Link() |
0 | 43 |
44 class _GetError(object): | |
45 | |
46 def __call__(self, field_name, form_errors): | |
47 tmpl = """<span class="error_msg">%s</span>""" | |
48 if form_errors and form_errors.has_key(field_name): | |
49 return literal(tmpl % form_errors.get(field_name)) | |
50 | |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
51 get_error = _GetError() |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
52 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
53 def recursive_replace(str, replace=' '): |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
54 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
55 Recursive replace of given sign to just one instance |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
56 @param str: given string |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
57 @param replace:char to find and replace multiple instances |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
58 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
59 Examples:: |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
60 >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
61 'Mighty-Mighty-Bo-sstones' |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
62 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
63 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
64 if str.find(replace * 2) == -1: |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
65 return str |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
66 else: |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
67 str = str.replace(replace * 2, replace) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
68 return recursive_replace(str, replace) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
69 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
70 class _ToolTip(object): |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
71 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
72 def __call__(self, tooltip_title, trim_at=50): |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
73 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
74 Special function just to wrap our text into nice formatted autowrapped |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
75 text |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
76 @param tooltip_title: |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
77 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
78 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
79 return literal(wrap_paragraphs(tooltip_title, trim_at)\ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
80 .replace('\n', '<br/>')) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
81 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
82 def activate(self): |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
83 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
84 Adds tooltip mechanism to the given Html all tooltips have to have |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
85 set class tooltip and set attribute tooltip_title. |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
86 Then a tooltip will be generated based on that |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
87 All with yui js tooltip |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
88 """ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
89 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
90 js = ''' |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
91 YAHOO.util.Event.onDOMReady(function(){ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
92 function toolTipsId(){ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
93 var ids = []; |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
94 var tts = YAHOO.util.Dom.getElementsByClassName('tooltip'); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
95 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
96 for (var i = 0; i < tts.length; i++) { |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
97 //if element doesn not have and id autgenerate one for tooltip |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
98 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
99 if (!tts[i].id){ |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
100 tts[i].id='tt'+i*100; |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
101 } |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
102 ids.push(tts[i].id); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
103 } |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
104 return ids |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
105 }; |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
106 var myToolTips = new YAHOO.widget.Tooltip("tooltip", { |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
107 context: toolTipsId(), |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
108 monitorresize:false, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
109 xyoffset :[0,0], |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
110 autodismissdelay:300000, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
111 hidedelay:5, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
112 showdelay:20, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
113 }); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
114 |
292
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
115 //Mouse Over event disabled for new repositories since they dont |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
116 //have last commit message |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
117 myToolTips.contextMouseOverEvent.subscribe( |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
118 function(type, args) { |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
119 var context = args[0]; |
292
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
120 var txt = context.getAttribute('tooltip_title'); |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
121 if(txt){ |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
122 return true; |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
123 } |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
124 else{ |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
125 return false; |
c4caeca9dd66
fixed paragraphs wrapping for ultralong commit messages. Disabled tooltips for new repos without a last commit message. ie. when tooltip_title is empty (there is a strange bug on empty tooltip_title)
Marcin Kuzminski <marcin@python-works.com>
parents:
289
diff
changeset
|
126 } |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
127 }); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
128 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
129 // Set the text for the tooltip just before we display it. Lazy method |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
130 myToolTips.contextTriggerEvent.subscribe( |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
131 function(type, args) { |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
132 var context = args[0]; |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
133 var txt = context.getAttribute('tooltip_title'); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
134 this.cfg.setProperty("text", txt); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
135 }); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
136 }); |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
137 ''' |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
138 return literal(js) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
139 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
140 tooltip = _ToolTip() |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
141 |
102
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
142 class _FilesBreadCrumbs(object): |
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
143 |
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
144 def __call__(self, repo_name, rev, paths): |
104
4cea52709743
fixed file browser breadcrumbs with revision
Marcin Kuzminski <marcin@python-works.com>
parents:
102
diff
changeset
|
145 url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))] |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
146 paths_l = paths.split(' / ') |
102
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
147 |
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
148 for cnt, p in enumerate(paths_l, 1): |
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
149 if p != '': |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
150 url_l.append(link_to(p, url('files_home', repo_name=repo_name, revision=rev, f_path=' / '.join(paths_l[:cnt])))) |
97
be0096a02772
added helper for filesize
Marcin Kuzminski <marcin@python-works.com>
parents:
94
diff
changeset
|
151 |
102
2dc0c8e4f384
Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents:
98
diff
changeset
|
152 return literal(' / '.join(url_l)) |
98
01d0f363f36d
added pygments webhelper
Marcin Kuzminski <marcin@python-works.com>
parents:
97
diff
changeset
|
153 |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
154 files_breadcrumbs = _FilesBreadCrumbs() |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
155 |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
156 def pygmentize(filenode, **kwargs): |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
157 """ |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
158 pygmentize function using pygments |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
159 @param filenode: |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
160 """ |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
161 return literal(code_highlight(filenode.content, filenode.lexer, HtmlFormatter(**kwargs))) |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
162 |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
163 def pygmentize_annotation(filenode, **kwargs): |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
164 """ |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
165 pygmentize function for annotation |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
166 @param filenode: |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
167 """ |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
168 |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
169 color_dict = g.changeset_annotation_colors |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
170 def gen_color(): |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
171 import random |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
172 return [str(random.randrange(10, 235)) for _ in xrange(3)] |
165
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
173 def get_color_string(cs): |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
174 if color_dict.has_key(cs): |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
175 col = color_dict[cs] |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
176 else: |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
177 color_dict[cs] = gen_color() |
ea893ffb7f00
implemented pygmentize codes into webhelpers. Together with color_dict caching into pylons globals
Marcin Kuzminski <marcin@python-works.com>
parents:
104
diff
changeset
|
178 col = color_dict[cs] |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
179 return "color: rgb(%s) ! important;" % (', '.join(col)) |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
180 |
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
181 def url_func(changeset): |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
182 tooltip_html = "<div style='font-size:0.8em'><b>Author:</b> %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
183 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
184 tooltip_html = tooltip_html % (changeset.author, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
185 changeset.date, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
186 tooltip(changeset.message)) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
187 lnk_format = 'r%s:%s' % (changeset.revision, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
188 changeset.raw_id) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
189 uri = link_to( |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
190 lnk_format, |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
191 url('changeset_home', repo_name='test', |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
192 revision=changeset.raw_id), |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
193 style=get_color_string(changeset.raw_id), |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
194 class_='tooltip', |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
195 tooltip_title=tooltip_html |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
196 ) |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
197 |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
198 uri += '\n' |
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
199 return uri |
250
be4621c6de58
Pygments code coloring rewrite, annotation was moved to vcs whitch had much better lib for that. Fixed code recognition based on mimetypes of filenodes, for better coloring.
Marcin Kuzminski <marcin@python-works.com>
parents:
165
diff
changeset
|
200 return literal(annotate_highlight(filenode, url_func, **kwargs)) |
260
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
201 |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
202 def repo_name_slug(value): |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
203 """ |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
204 Return slug of name of repository |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
205 """ |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
206 slug = urlify(value) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
207 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|:""": |
260
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
208 slug = slug.replace(c, '-') |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
209 slug = recursive_replace(slug, '-') |
6ada8c223374
made global funcion to clean repo names, and remove all special chars from the name.
Marcin Kuzminski <marcin@python-works.com>
parents:
250
diff
changeset
|
210 return slug |
288
cd2ee462fc2c
implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents:
284
diff
changeset
|
211 |
0 | 212 flash = _Flash() |
289
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
213 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
214 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
215 #=============================================================================== |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
216 # MERCURIAL FILTERS available via h. |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
217 #=============================================================================== |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
218 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
219 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
220 from mercurial import util |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
221 from mercurial.templatefilters import age as _age, person as _person |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
222 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
223 age = lambda x:_age(x) |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
224 capitalize = lambda x: x.capitalize() |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
225 date = lambda x: util.datestr(x) |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
226 email = util.email |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
227 person = lambda x: _person(x) |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
228 hgdate = lambda x: "%d %d" % x |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
229 isodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2') |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
230 isodatesec = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2') |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
231 localdate = lambda x: (x[0], util.makedate()[1]) |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
232 rfc822date = lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2") |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
233 rfc3339date = lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2") |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
234 time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2") |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
235 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
236 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
237 |
237470e64bb8
switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents:
288
diff
changeset
|
238 |