Imports initiaux
darcs-hash:20060414194001-d1718-ceecbd9d441a17318a957ec7b4686f85a4aa47b5.gz
This commit is contained in:
parent
1c6255c1d7
commit
8f2f2247d7
18 changed files with 5116 additions and 0 deletions
110
wiki/parser/Box.py
Normal file
110
wiki/parser/Box.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
# -*- 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
|
||||
|
||||
#####################################################################
|
||||
# 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 parseArgs(self, argsString):
|
||||
argList = argsString.split(u',')
|
||||
settings = {}
|
||||
for anArg in argList:
|
||||
anArg = anArg.strip(u' ')
|
||||
if anArg.find(u'color=')!=-1:
|
||||
settings['color'] = anArg.split(u'=')[1]
|
||||
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
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue