1 | # -*- coding: utf-8 -*- |
---|
2 | # |
---|
3 | # Copyright (C) 2013 Yasumichi Akashoshi |
---|
4 | # All rights reserved. |
---|
5 | # |
---|
6 | # This software is licensed as described in the file COPYING, which |
---|
7 | # you should have received as part of this distribution. |
---|
8 | # |
---|
9 | |
---|
10 | from genshi.core import Markup |
---|
11 | from trac.core import * |
---|
12 | from trac.web.chrome import ITemplateProvider, add_stylesheet |
---|
13 | from trac.wiki.macros import WikiMacroBase |
---|
14 | from trac.wiki import Formatter |
---|
15 | import StringIO |
---|
16 | |
---|
17 | class AdmonitionMacro(WikiMacroBase): |
---|
18 | """Admonition""" |
---|
19 | |
---|
20 | implements(ITemplateProvider) |
---|
21 | |
---|
22 | revision = "$Rev$" |
---|
23 | url = "$URL$" |
---|
24 | |
---|
25 | def expand_macro (self, formatter, name, text, args): |
---|
26 | # Make sure data capsule is in place |
---|
27 | if not hasattr(formatter, '_admonition'): |
---|
28 | formatter._admonition = [] |
---|
29 | |
---|
30 | # Chrome |
---|
31 | add_stylesheet(formatter.req, 'admonition/admonition.css') |
---|
32 | |
---|
33 | type = 'note' |
---|
34 | |
---|
35 | # Get type |
---|
36 | if 'type' in args: |
---|
37 | if args['type'].lower() in ['note', 'warning', 'important']: |
---|
38 | type = args['type'].lower() |
---|
39 | |
---|
40 | # Build Markup |
---|
41 | html = '<div class="%s">\n' % type |
---|
42 | html += '<div class="%s-inner">\n' % type |
---|
43 | |
---|
44 | # Convert Wiki markup to HTML, new style |
---|
45 | out = StringIO.StringIO() |
---|
46 | Formatter(self.env, formatter.context).format(text, out); |
---|
47 | |
---|
48 | html += out.getvalue() |
---|
49 | html += '</div>\n' |
---|
50 | html += '</div>\n' |
---|
51 | |
---|
52 | return html |
---|
53 | |
---|
54 | # ITemplateProvider methods |
---|
55 | def get_htdocs_dirs(self): |
---|
56 | from pkg_resources import resource_filename |
---|
57 | return [('admonition', resource_filename(__name__, 'htdocs'))] |
---|
58 | |
---|
59 | def get_templates_dirs(self): |
---|
60 | return [] |
---|