Attachment 'HelpTitle.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - HelpTitle macro
4
5 This macro allows you to mouseover arbitrary words and phrases and
6 (depending on your browser support) get tooltip help text.
7
8 Making text with a tooltip:
9
10 [[HelpTitle(this is the text you see, this is the tooltip)]]
11
12 Both parameters are required, or it's kinda pointless. Also, no
13 commas or quotes in either the text or the tooltip. It breaks things.
14
15 @copyright: 2005 by Vito Miliano <vito_moinhelptitle@hirevito.com>
16 @license: GNU GPL v2, see COPYING for details.
17 """
18
19 class HelpTitle:
20 """ Arbitrary text with tooltips """
21
22 arguments = ['text', 'tooltip']
23
24 def __init__(self, macro, args):
25 self.macro = macro
26 self.request = macro.request
27 self.args = self.parseArgs(args)
28
29 def parseArgs(self, string):
30 """ Temporary function until Oliver Graf args parser is finished
31
32 @param string: string from the wiki markup [[NewPage(string)]]
33 @rtype: dict
34 @return: dictionary with macro options
35 """
36 if not string:
37 return {}
38 args = [s.strip() for s in string.split(',')]
39 args = dict(zip(self.arguments, args))
40 return args
41
42 def errors(self):
43 """ Validate arguments and return error message
44
45 @rtype: unicode
46 @return: error message for bad argument, or None if ok.
47 """
48 _ = self.request.getText
49
50 # Both parameters are required
51 if not self.args.get('text') or not self.args.get('tooltip'):
52 error = _('Missing text or tooltip.')
53 # Should use abstract formatter.wikiMarkupError() call,
54 # but there is no such call, so just use html.
55 return u'<span class="error">%s</span>' % error
56
57 return None
58
59 def text(self):
60 """ Return text safe for rendering """
61 text = self.args.get('text', u'')
62 if text:
63 text = self.macro.formatter.text(text)
64 return text
65
66 def tooltip(self):
67 """ Return tooltip safe for rendering """
68 tooltip = self.args.get('tooltip', u'')
69 if tooltip:
70 tooltip = self.macro.formatter.text(tooltip)
71 return tooltip
72
73 def renderInText(self):
74 """ Render macro in paragraph context
75
76 The parser should decide what to do if this macro is placed in a
77 page context.
78
79 @rtype: unicode
80 @return rendered output
81 """
82 _ = self.request.getText
83
84 errors = self.errors()
85 if errors:
86 return errors
87
88 text = self.text()
89 tooltip = self.tooltip()
90
91 out = u'<span style="cursor: help; border-bottom: 1px dashed;" title="%(tooltip)s">%(text)s</span>' % {
92 'text': text,
93 'tooltip': tooltip,
94 }
95 return out
96
97 def execute(macro, args):
98 """ Temporary glue code to use with moin current macro system """
99 return HelpTitle(macro, args).renderInText()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.