scripts/wiki/parser/Box.py
Antoine Durand-Gasselin aeeb314968 [wiki/parser/Box.py] quelques erreurs
darcs-hash:20090615093659-bd074-0f89b2cdaa8621f18c8c2e7b11261d9f7cdc33c3.gz
2009-06-15 11:36:59 +02:00

113 lines
3.6 KiB
Python
Raw Blame History

# -*- coding: iso-8859-1 -*-
"""
..
.... ............ ........
. ....... . .... ..
. ... .. .. .. .. ..... . ..
.. .. ....@@@. .. . ........ .
.. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. ....
.@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... ....
@@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. ..
.@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. .....
...@@@.... @@@ .@@.......... ........ ..... ..
. ..@@@@.. . .@@@@. .. ....... . .............
. .. .... .. .. . ... ....
. . .... ............. .. ...
.. .. ... ........ ... ...
................................
MoinMoin - Box parser
PURPOSE:
une boite jolie
CALLING SEQUENCE:
{{{
#!Box titre
blablabla
tables, images....
}}}
Copyright 2008,2009 Antoine Durand-Gasselin <adg@crans.org>
"""
import os,string,re,StringIO
from MoinMoin import config, wikiutil
from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
Dependencies = []
color_list = ['orange', 'black', 'red', 'green', 'blue', 'gray']
#####################################################################
# Parser : classe principale, c'est elle qui fait tout
#######
class Parser:
parsername = "Box"
Dependencies=Dependencies
def __init__(self, raw, request, **kw):
self.form = request.form
self.request = request
self.raw = raw
self.settings = self.parseArgs(kw["format_args"])
def getRandomColor(self):
nb_of_colors = color_list.__len__()
from random import randint
colorNum = randint(0, nb_of_colors - 1)
return color_list[colorNum]
def parseArgs(self, argsString):
argList = argsString.split(u',')
settings = {}
for anArg in argList:
anArg = anArg.strip(u' ')
if anArg.find(u'color=')!=-1:
theColor = anArg.split(u'=')[1].lower()
if theColor == 'random':
theColor = self.getRandomColor()
settings['color'] = theColor
else:
settings['title'] = anArg
return settings
def format(self, formatter):
# on utilise la classe qui va fabriquer le code html
try: title = self.settings['title']
except: title = ''
try: color = self.settings['color']
except: color=None
content_buf = StringIO.StringIO()
self.request.redirect(content_buf)
WikiParser(self.raw, self.request).format(formatter)
content = content_buf.getvalue()
self.request.redirect()
del content_buf
# On le fout dans une bo<62>te
self.request.write(self.request.formatter.rawHTML(self.crans_box(title, content, formatter, color)))
def crans_box(self, title, body_html, formatter, color=None):
if color==None: css_color_class=u""
else: css_color_class = u" %s_box" % color
html = [
'<div class="sidebox%s">' % css_color_class,
'<div class="boxhead">',
formatter.heading(1,3),
title,
formatter.heading(0,3),
'</div>',
'<div class="boxbody1">',
'<div class="boxbody2">',
body_html,
'</div>',
'</div>',
'</div>',
]
return('\n'.join(html))