[parser/] ajout de box et de portail comme plugins
Ignore-this: 795d4f28affe989c46f3573c6576985c * moinmoin 1.7,1.8 compliant * pour dépackager moinmoin darcs-hash:20090614234623-bd074-107936160340bd233f2e8bc378acf0f669236b21.gz
This commit is contained in:
parent
f224c4f8ae
commit
694285a3d4
2 changed files with 263 additions and 0 deletions
113
wiki/parser/Box.py
Normal file
113
wiki/parser/Box.py
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
# -*- 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îte
|
||||||
|
self.request.write(self.request.formatter.rawHTML(self.crans_box(title, content, color)))
|
||||||
|
|
||||||
|
def crans_box(self, title, body_html, 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">',
|
||||||
|
self.heading(1,3),
|
||||||
|
title,
|
||||||
|
self.heading(0,3),
|
||||||
|
'</div>',
|
||||||
|
'<div class="boxbody1">',
|
||||||
|
'<div class="boxbody2">',
|
||||||
|
body_html,
|
||||||
|
'</div>',
|
||||||
|
'</div>',
|
||||||
|
'</div>',
|
||||||
|
]
|
||||||
|
return('\n'.join(html))
|
||||||
|
|
150
wiki/parser/Portail.py
Normal file
150
wiki/parser/Portail.py
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
..
|
||||||
|
.... ............ ........
|
||||||
|
. ....... . .... ..
|
||||||
|
. ... .. .. .. .. ..... . ..
|
||||||
|
.. .. ....@@@. .. . ........ .
|
||||||
|
.. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. ....
|
||||||
|
.@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... ....
|
||||||
|
@@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. ..
|
||||||
|
.@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. .....
|
||||||
|
...@@@.... @@@ .@@.......... ........ ..... ..
|
||||||
|
. ..@@@@.. . .@@@@. .. ....... . .............
|
||||||
|
. .. .... .. .. . ... ....
|
||||||
|
. . .... ............. .. ...
|
||||||
|
.. .. ... ........ ... ...
|
||||||
|
................................
|
||||||
|
|
||||||
|
MoinMoin - Portail parser
|
||||||
|
|
||||||
|
PURPOSE:
|
||||||
|
Pour afficher un portail a la wikipedia.
|
||||||
|
|
||||||
|
CALLING SEQUENCE:
|
||||||
|
{{{
|
||||||
|
#!Portail
|
||||||
|
image1.png @@ title1 @@ description 1
|
||||||
|
image2.png @@ title2 @@ description 2
|
||||||
|
image3.png @@ title3 @@ description 3
|
||||||
|
}}}
|
||||||
|
|
||||||
|
Copyright 2008,2009 Antoine Durand-Gasselin <adg@crans.org>
|
||||||
|
|
||||||
|
"""
|
||||||
|
import os,string,re,StringIO,urllib
|
||||||
|
from MoinMoin import wikiutil
|
||||||
|
from MoinMoin.action import AttachFile
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# Parser : classe principale, c'est elle qui fait tout
|
||||||
|
#######
|
||||||
|
class Parser:
|
||||||
|
def __init__(self, raw, request, **kw):
|
||||||
|
self.request = request
|
||||||
|
self.form = request.form
|
||||||
|
self.parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", request.page.pi['format'])
|
||||||
|
self.raw = raw
|
||||||
|
|
||||||
|
def format(self, formatter):
|
||||||
|
entries = self.parse(formatter)
|
||||||
|
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()
|
||||||
|
items=line.split('@@',2)
|
||||||
|
if len(items)<3:
|
||||||
|
# Voir ce qu'on fait
|
||||||
|
## self.request.write('<!-- error, wrong number of parameters -->')
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# On récupère le nom de l'image
|
||||||
|
pic = items[0].strip()
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
def crans_portal(self, entries):
|
||||||
|
html = [ '\n\n<div class="portal" style="padding: 0 0 2em 0;">' ]
|
||||||
|
|
||||||
|
format_pe = '''
|
||||||
|
<div style="background:transparent url('%s') center left no-repeat;
|
||||||
|
width: 38%%; height: 5em; padding: 1.5em 20px 0 60px; float:left;">
|
||||||
|
<ul style="list-style: none; margin: 0; padding: 0;">
|
||||||
|
<li>%s</li>
|
||||||
|
<li>%s</li>
|
||||||
|
</ul>
|
||||||
|
</div>'''
|
||||||
|
|
||||||
|
format_pne = '''
|
||||||
|
<div style="width: 38%%; height: 5em; padding: 10px 20px 0 0px; float:left;">
|
||||||
|
<div style="float: left; padding-top: 1.5em; width: 20%%;">
|
||||||
|
<a href="%s" style="font-size: 5pt" alt="envoyer l'image">envoyer<br>%s</a>
|
||||||
|
</div>
|
||||||
|
<div style="float: left; width: 75%%; padding: 0; margin: 0;">
|
||||||
|
<ul style="list-style: none; margin: 0; padding: 0;">
|
||||||
|
<li>%s</li>
|
||||||
|
<li>%s</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>'''
|
||||||
|
|
||||||
|
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() }}}
|
||||||
|
|
||||||
|
html += [ '\n</div>\n<hr style="visibility:hidden; clear: both">\n\n' ]
|
||||||
|
return('\n'.join(html))
|
Loading…
Add table
Add a link
Reference in a new issue