diff --git a/wiki/parser/Box.py b/wiki/parser/Box.py
index 549e1283..72666247 100644
--- a/wiki/parser/Box.py
+++ b/wiki/parser/Box.py
@@ -33,9 +33,8 @@
"""
-import os,string,re,StringIO
+import random
from MoinMoin import config, wikiutil
-from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
Dependencies = []
color_list = ['orange', 'black', 'red', 'green', 'blue', 'gray']
@@ -48,66 +47,38 @@ class Parser:
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]
+ self.parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", request.page.pi['format'])
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()
+ theColor = anArg.split(u'=')[1].lower().strip()
if theColor == 'random':
- theColor = self.getRandomColor()
+ theColor = random.choice(color_list)
settings['color'] = theColor
else:
- settings['title'] = anArg
+ settings['title'] = anArg.strip()
return settings
def format(self, formatter):
+ content = wikiutil.renderText(self.request, self.parser, self.raw)
- # 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
+ title = self.settings.get('title', '')
+ color = self.settings.get('color', 'gray')
+ if color==None: kw = {}
+ else: kw = {'class' : '%s_bg' % color }
- 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î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 = [
- '
' % css_color_class,
- '
',
- formatter.heading(1,3),
- title,
- formatter.heading(0,3),
- '
',
- '
',
- '
',
- body_html,
- '
',
- '
',
- '
',
- ]
- return('\n'.join(html))
+ formatter.rawHTML(''),
+ formatter.heading(1,3, **kw), title, formatter.heading(0,3),
+ formatter.rawHTML('
'), content, formatter.rawHTML('
\n'* 2)
+ ]
+
+ self.request.write('\n'.join(html))
+
diff --git a/wiki/parser/Portail.py b/wiki/parser/Portail.py
index d8021650..ebcf1983 100644
--- a/wiki/parser/Portail.py
+++ b/wiki/parser/Portail.py
@@ -32,7 +32,7 @@ MoinMoin - Portail parser
Copyright 2008,2009 Antoine Durand-Gasselin
"""
-import os,string,re,StringIO,urllib
+import urllib
from MoinMoin import wikiutil
from MoinMoin.action import AttachFile
@@ -51,100 +51,31 @@ class Parser:
self.request.write(self.request.formatter.rawHTML(self.crans_portal(entries)))
def parse(self, formatter):
- # on divise le textes en lignes (1 ligne = une entree dans le portail)
- quotes = self.raw.split('\n')
-
- # on récupere le chemin des fichiers attaches pour les images
- current_pagename=formatter.page.page_name
- attachment_path = AttachFile.getAttachDir(self.request, current_pagename, create=1)
- # on traite les ligne une à une
- entries = []
- for line in quotes:
- line=line.strip()
+ for line in self.raw.split('\n'):
items=line.split('@@',2)
- if len(items)<3:
- # Voir ce qu'on fait
- ## self.request.write('')
- pass
- else:
- # On récupère le nom de l'image
+ if len(items) >2:
pic = items[0].strip()
+ title = wikiutil.renderText(self.request, self.parser, items[1])
+ body = wikiutil.renderText(self.request, self.parser, items[2])
- # On va formatter le titre et la légende
- tit_buf = StringIO.StringIO()
- bod_buf = StringIO.StringIO()
-
- self.request.redirect(tit_buf)
- self.parser(items[1], self.request).format(formatter)
- title = tit_buf.getvalue()
- self.request.redirect()
-
- self.request.redirect(bod_buf)
- self.parser(items[2], self.request).format(formatter)
- body = bod_buf.getvalue()
- self.request.redirect()
-
- # Qu'on rajoute à la liste des entrées
- entries += [ (( pic, title, body )) ]
-
- return entries
+ yield (( pic, title, body ))
def crans_portal(self, entries):
html = [ '\n\n' ]
- format_pe = '''
-
'''
-
format_pne = '''
-
-
'''
+'''
- pn = self.request.formatter.page.page_name
-
- while len(entries) != 0:
- pic0, tit0, bod0 = entries[0]
-
- fname = urllib.url2pathname(pic0)
- if AttachFile.exists(self.request, pn, fname):
- pic0 = AttachFile.getAttachUrl(pn, pic0, self.request)
- pic0 = wikiutil.escape(pic0)
- html += [ format_pe % (pic0, tit0, bod0) ]
- else:
- pic0 = AttachFile.getAttachUrl(pn, pic0, self.request, upload=True)
- pic0 = wikiutil.escape(pic0)
- html += [ format_pne % (pic0, fname, tit0, bod0) ]
-
- if len(entries) >= 2:
- pic1, tit1, bod1 = entries[1]
- entries = entries[2:]
-
- fname = urllib.url2pathname(pic1)
- if AttachFile.exists(self.request, pn, fname):
- pic1 = AttachFile.getAttachUrl(pn, pic1, self.request)
- pic1 = wikiutil.escape(pic1)
- html += [ format_pe % (pic1, tit1, bod1) ]
- else:
- pic1 = AttachFile.getAttachUrl(pn, pic1, self.request, upload=True)
- pic1 = wikiutil.escape(pic1)
- html += [ format_pne % (pic1, fname, tit1, bod1) ]
-
- else:
- entries = [] # plus propre que {{{ break() }}}
+ for pic0, tit0, bod0 in entries:
+ pic = wikiutil.renderText(self.request, self.parser, '{{attachment:%s}}' % pic0)
+ html += [ format_pne % (pic, tit0, bod0) ]
html += [ '\n
\n
\n\n' ]
return('\n'.join(html))