120 lines
3.8 KiB
Python
120 lines
3.8 KiB
Python
# -*- coding: iso-8859-1 -*-
|
|
"""
|
|
MoinMoin - Portail parser
|
|
|
|
PURPOSE:
|
|
une boite jolie
|
|
|
|
CALLING SEQUENCE:
|
|
{{{
|
|
#!Box titre
|
|
blablabla
|
|
|
|
tables, images....
|
|
}}}
|
|
|
|
"""
|
|
from MoinMoin.parser import wiki
|
|
import os,string,re,StringIO
|
|
from MoinMoin.action import AttachFile
|
|
|
|
color_list = ['orange', 'black', 'red', 'green', 'blue', 'gray']
|
|
|
|
|
|
#####################################################################
|
|
# Fonctions #
|
|
#####################################################################
|
|
# to_wikiname : transfome la chaine text avec le parser wiki
|
|
# classique et le formateur formatter
|
|
# (je sais pas a quoi sert request, mais faut pas
|
|
# l'enlever !)
|
|
#######
|
|
|
|
def to_wikiname(request,formatter,text):
|
|
##taken from MiniPage
|
|
out=StringIO.StringIO()
|
|
request.redirect(out)
|
|
wikiizer = wiki.Parser(text,request)
|
|
wikiizer.format(formatter)
|
|
result=out.getvalue()
|
|
request.redirect()
|
|
del out
|
|
|
|
return result.strip()
|
|
|
|
#####################################################################
|
|
# BoxFormatter : creer le code html
|
|
#######
|
|
class BoxFormatter:
|
|
|
|
def __init__(self, request, formatter):
|
|
self.formatter = formatter
|
|
self.request = request
|
|
self.counter = 0
|
|
|
|
def make(self, title, body_html, color=None):
|
|
if color==None:
|
|
css_color_class=u""
|
|
else:
|
|
css_color_class = u" %s_box" % color
|
|
html = [
|
|
self.formatter.rawHTML(u'<div class="sidebox%s">' % css_color_class),
|
|
self.formatter.rawHTML(u'<div class="boxhead">'),
|
|
self.formatter.heading(1,3),
|
|
title,
|
|
self.formatter.heading(0,3),
|
|
self.formatter.rawHTML(u'</div>'),
|
|
self.formatter.rawHTML(u'<div class="boxbody1">'),
|
|
self.formatter.rawHTML(u'<div class="boxbody2">'),
|
|
body_html,
|
|
self.formatter.rawHTML(u'</div>'),
|
|
self.formatter.rawHTML(u'</div>'),
|
|
self.formatter.rawHTML(u'</div>'),
|
|
]
|
|
self.request.write(u'\n'.join(html))
|
|
|
|
#####################################################################
|
|
# Parser : classe principale, c'est elle qui parse
|
|
#######
|
|
class Parser:
|
|
|
|
def __init__(self, raw, request, **kw):
|
|
self.request = request
|
|
self.raw = raw
|
|
self.settings={'title': u'|'.join([u" ".join(kw.keys()), u" ".join(kw.values())])}
|
|
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):
|
|
quotes = self.raw
|
|
|
|
# on utilise la classe qui va fabriquer le code html
|
|
boite = BoxFormatter(self.request, formatter)
|
|
title = self.settings['title']
|
|
content = to_wikiname(self.request, formatter, quotes)
|
|
try:
|
|
color = self.settings['color']
|
|
except:
|
|
color=None
|
|
boite.make(title, content, color)
|
|
return
|
|
|