| 1 | ''' |
|---|
| 2 | A wiki-processor for encapsulating wiki text inside a box. |
|---|
| 3 | The box will have a legend and a modifiable color. |
|---|
| 4 | |
|---|
| 5 | Example: |
|---|
| 6 | |
|---|
| 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 | ''' |
|---|
| 18 | |
|---|
| 19 | from trac.wiki import wiki_to_html |
|---|
| 20 | |
|---|
| 21 | STYLE = 'margin-top: 2px; color:black; background-color:%s; '\ |
|---|
| 22 | 'border: solid black 1px' |
|---|
| 23 | COLOR = 'white' |
|---|
| 24 | LEGEND = 'Items' |
|---|
| 25 | |
|---|
| 26 | def execute(hdf, txt, env): |
|---|
| 27 | lines = txt.split('\n') |
|---|
| 28 | color = COLOR |
|---|
| 29 | legend = LEGEND |
|---|
| 30 | offset = 0 |
|---|
| 31 | for l in lines[:2]: |
|---|
| 32 | if l.startswith('#!color'): |
|---|
| 33 | color = l.split(':',1)[-1] |
|---|
| 34 | offset += 1 |
|---|
| 35 | elif l.startswith('#!legend'): |
|---|
| 36 | legend = l.split(':',1)[-1] |
|---|
| 37 | offset += 1 |
|---|
| 38 | |
|---|
| 39 | return _build_field_set(hdf, '\n'.join(lines[offset:]), env, legend, color) |
|---|
| 40 | |
|---|
| 41 | def _build_field_set(hdf, txt, env, legend, color): |
|---|
| 42 | style = STYLE % color |
|---|
| 43 | html = '<fieldset style="%s"><legend style="%s">'\ |
|---|
| 44 | '%s</legend>%s</fieldset>' % (style, style, legend, wiki_to_html(txt, env, hdf, env.get_db_cnx())) |
|---|
| 45 | return html |
|---|