annotate pylons_app/lib/helpers.py @ 282:237470e64bb8

switched filters into webhelpers for easy of usage. Rewrite of html to use predefined templates from branches shortlog tags, for DRY usage. Added info messages about empty branches/tags etc.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 13 Jun 2010 23:56:16 +0200
parents cd2ee462fc2c
children c4caeca9dd66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """Helper functions
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 Consists of functions to typically be used within templates, but also
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 available to Controllers. This module is available to both as 'h'.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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, \
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 from webhelpers.pylonslib import Flash as _Flash
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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, \
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
25 replace_whitespace, urlify, truncate, wrap_paragraphs
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26
98
01d0f363f36d added pygments webhelper
Marcin Kuzminski <marcin@python-works.com>
parents: 97
diff changeset
27
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
28 #Custom helpers here :)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29 class _Link(object):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 '''
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31 Make a url based on label and url with help of url_for
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 @param label:name of link if not defined url is used
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 @param url: the url for link
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 '''
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 0
diff changeset
36 def __call__(self, label='', *url_, **urlargs):
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
37 if label is None or '':
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 label = url
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 0
diff changeset
39 link_fn = link_to(label, url(*url_, **urlargs))
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 return link_fn
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
41
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
42 link = _Link()
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
44 class _GetError(object):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
45
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
46 def __call__(self, field_name, form_errors):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 tmpl = """<span class="error_msg">%s</span>"""
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
48 if form_errors and form_errors.has_key(field_name):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 return literal(tmpl % form_errors.get(field_name))
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
52
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
54 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
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: 278
diff changeset
58
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
59 Examples::
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
diff changeset
62 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
63
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
65 return str
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
66 else:
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
diff changeset
69
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
71
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
73 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
75 text
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
77 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
78
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
diff changeset
81
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
83 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
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: 278
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: 278
diff changeset
88 """
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
89
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
90 js = '''
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
92 function toolTipsId(){
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
93 var ids = [];
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
95
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
diff changeset
98
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
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: 278
diff changeset
101 }
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
103 }
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
104 return ids
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
105 };
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
107 context: toolTipsId(),
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
108 monitorresize:false,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
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: 278
diff changeset
110 autodismissdelay:300000,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
111 hidedelay:5,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
112 showdelay:20,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
113 });
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
114
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
115 //Mouse subscribe optional arguments
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
116 myToolTips.contextMouseOverEvent.subscribe(
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
117 function(type, args) {
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
118 var context = args[0];
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
119 return true;
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
120 });
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
121
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
122 // 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: 278
diff changeset
123 myToolTips.contextTriggerEvent.subscribe(
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
124 function(type, args) {
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
125 var context = args[0];
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
126 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: 278
diff changeset
127 this.cfg.setProperty("text", txt);
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
128 });
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
129 });
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
130 '''
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
131 return literal(js)
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
132
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
133 tooltip = _ToolTip()
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
134
102
2dc0c8e4f384 Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents: 98
diff changeset
135 class _FilesBreadCrumbs(object):
2dc0c8e4f384 Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents: 98
diff changeset
136
2dc0c8e4f384 Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents: 98
diff changeset
137 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
138 url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))]
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
139 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
140
2dc0c8e4f384 Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents: 98
diff changeset
141 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
142 if p != '':
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
143 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
144
102
2dc0c8e4f384 Updated tempaltes, added file browser breadcrumbs, and feed icons
Marcin Kuzminski <marcin@python-works.com>
parents: 98
diff changeset
145 return literal(' / '.join(url_l))
98
01d0f363f36d added pygments webhelper
Marcin Kuzminski <marcin@python-works.com>
parents: 97
diff changeset
146
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
147 files_breadcrumbs = _FilesBreadCrumbs()
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
148
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
149 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
150 """
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
151 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
152 @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
153 """
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
154 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
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_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
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 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
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
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 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 col = color_dict[cs]
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
172 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
173
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
174 def url_func(changeset):
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
175 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: 278
diff changeset
176
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
177 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: 278
diff changeset
178 changeset.date,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
179 tooltip(changeset.message))
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
180 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: 278
diff changeset
181 changeset.raw_id)
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
182 uri = link_to(
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
183 lnk_format,
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
184 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: 278
diff changeset
185 revision=changeset.raw_id),
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
186 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: 278
diff changeset
187 class_='tooltip',
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
188 tooltip_title=tooltip_html
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
189 )
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
190
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
191 uri += '\n'
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
192 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
193 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
194
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
195 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
196 """
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
197 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
198 """
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
199 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
200 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
201 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
202 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
203 return slug
281
cd2ee462fc2c implemented yui tooltip, and added it into annotation and main page.
Marcin Kuzminski <marcin@python-works.com>
parents: 278
diff changeset
204
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
205 flash = _Flash()
282
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
206
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
207
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
208 #===============================================================================
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
209 # MERCURIAL FILTERS available via h.
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
210 #===============================================================================
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
211
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
212
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
213 from mercurial import util
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
214 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: 281
diff changeset
215
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
216 age = lambda x:_age(x)
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
217 capitalize = lambda x: x.capitalize()
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
218 date = lambda x: util.datestr(x)
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
219 email = util.email
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
220 person = lambda x: _person(x)
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
221 hgdate = lambda x: "%d %d" % x
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
222 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: 281
diff changeset
223 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: 281
diff changeset
224 localdate = lambda x: (x[0], util.makedate()[1])
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
225 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: 281
diff changeset
226 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: 281
diff changeset
227 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: 281
diff changeset
228
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
229
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
230
237470e64bb8 switched filters into webhelpers for easy of usage.
Marcin Kuzminski <marcin@python-works.com>
parents: 281
diff changeset
231