| 1 | # $Id$ |
|---|
| 2 | """\file |
|---|
| 3 | A wiki-processor for encapsulating wiki text inside a box. |
|---|
| 4 | The box will have a legend and a modifiable color. |
|---|
| 5 | |
|---|
| 6 | Example: |
|---|
| 7 | {{{ |
|---|
| 8 | #!LegendBox |
|---|
| 9 | #!color: blue |
|---|
| 10 | #!legend: My Title |
|---|
| 11 | Here comes the actual text that comes inside the box. |
|---|
| 12 | You can even use wiki-formatting in here. |
|---|
| 13 | }}} |
|---|
| 14 | |
|---|
| 15 | You can modify the default COLOR, LEGEND and the STYLE in this plugin file. |
|---|
| 16 | """ |
|---|
| 17 | from trac.wiki import format_to_html, format_to_oneliner |
|---|
| 18 | |
|---|
| 19 | STYLE = 'margin-top: 2px; color:black; background-color:%s; '\ |
|---|
| 20 | 'border: solid black 1px' |
|---|
| 21 | COLOR = 'white' |
|---|
| 22 | LEGEND = 'Items' |
|---|
| 23 | |
|---|
| 24 | from genshi.builder import tag |
|---|
| 25 | from trac.wiki.macros import WikiMacroBase |
|---|
| 26 | |
|---|
| 27 | class LegendBoxMacro(WikiMacroBase): |
|---|
| 28 | |
|---|
| 29 | def expand_macro(self, formatter, name, content): |
|---|
| 30 | lines = content.split('\n') |
|---|
| 31 | color = COLOR |
|---|
| 32 | legend = LEGEND |
|---|
| 33 | offset = 0 |
|---|
| 34 | for l in lines[:2]: |
|---|
| 35 | if l.startswith('#!color'): |
|---|
| 36 | color = l.split(':',1)[-1] |
|---|
| 37 | offset += 1 |
|---|
| 38 | elif l.startswith('#!legend'): |
|---|
| 39 | legend = l.split(':',1)[-1] |
|---|
| 40 | offset += 1 |
|---|
| 41 | content = '\n'.join(lines[offset:]) |
|---|
| 42 | style = STYLE % color |
|---|
| 43 | return tag.fieldset( |
|---|
| 44 | tag.legend(format_to_oneliner(self.env, formatter.context, |
|---|
| 45 | legend), style=style), |
|---|
| 46 | format_to_html(self.env, formatter.context, content), |
|---|
| 47 | style=style) |
|---|