[wiki-lenny/local/] Ajout du parser pour interpréter les {{{!#Box [...] }}}
darcs-hash:20081109155140-bd074-7d80266881555bd3549f742ffca0592489bda0aa.gz
This commit is contained in:
parent
cd5d080e49
commit
8c6f950e0a
1 changed files with 76 additions and 0 deletions
76
wiki-lenny/local/parser/Box.py
Normal file
76
wiki-lenny/local/parser/Box.py
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
"""
|
||||||
|
MoinMoin - Portail parser
|
||||||
|
|
||||||
|
PURPOSE:
|
||||||
|
une boite jolie
|
||||||
|
|
||||||
|
CALLING SEQUENCE:
|
||||||
|
{{{
|
||||||
|
#!Box titre
|
||||||
|
blablabla
|
||||||
|
|
||||||
|
tables, images....
|
||||||
|
}}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from MoinMoin import config, wikiutil
|
||||||
|
from MoinMoin.macro import Macro
|
||||||
|
from MoinMoin.parser.text_creole import Emitter
|
||||||
|
from MoinMoin.parser._creole import Parser as CreoleParser
|
||||||
|
import os,string,re,StringIO
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# On crée l'arbre de syntaxe
|
||||||
|
content_tree = CreoleParser(self.raw).parse()
|
||||||
|
|
||||||
|
# On le formatte
|
||||||
|
fmt_content = Emitter(content_tree, formatter, self.request, Macro(self)).emit()
|
||||||
|
|
||||||
|
# On le fout dans une boîte
|
||||||
|
self.request.write(formatter.crans_box(title, fmt_content, color))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue