source: projects/admonitionmacro/trunk/admonitionmacro/macro.py @ 7430

Revision 7430, 1.6 KB checked in by yasumichi, 11 years ago (diff)

initial import

Line 
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
10from genshi.core import Markup
11from trac.core import *
12from trac.web.chrome import ITemplateProvider, add_stylesheet
13from trac.wiki.macros import WikiMacroBase
14from trac.wiki import Formatter
15import StringIO
16
17class 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 []
Note: See TracBrowser for help on using the repository browser.