From 0c660ccda963eabc2833ce0502e08e09c18f1a95 Mon Sep 17 00:00:00 2001 From: Antoine Durand-Gasselin Date: Sun, 9 Nov 2008 23:21:27 +0100 Subject: [PATCH] [wiki-lenny/local/parser/Portail.py] Le portail marche darcs-hash:20081109222127-bd074-d3fb053d5bcfad423e5e7bba0837ad5ac2907de6.gz --- wiki-lenny/local/parser/Portail.py | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 wiki-lenny/local/parser/Portail.py diff --git a/wiki-lenny/local/parser/Portail.py b/wiki-lenny/local/parser/Portail.py new file mode 100644 index 00000000..1832fee7 --- /dev/null +++ b/wiki-lenny/local/parser/Portail.py @@ -0,0 +1,88 @@ +# -*- 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 Antoine Durand-Gasselin + +""" +import os,string,re,StringIO +from MoinMoin.action import AttachFile +from MoinMoin.parser.text_moin_wiki import Parser as WikiParser + +##################################################################### +# 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.raw = raw + + def format(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('') + pass + else: + # On récupère l'url de l'image + pic = AttachFile.getAttachUrl(current_pagename, items[0].strip(), self.request).replace('& ','&') + + # On va formatter le titre et la légende + tit_buf = StringIO.StringIO() + bod_buf = StringIO.StringIO() + + self.request.redirect(tit_buf) + WikiParser(items[1], self.request).format(formatter) + title = tit_buf.getvalue() + self.request.redirect() + + self.request.redirect(bod_buf) + WikiParser(items[2], self.request).format(formatter) + body = bod_buf.getvalue() + self.request.redirect() + + del tit_buf + del bod_buf + + # Qu'on rajoute à la liste des entrées + entries += [ (( pic, title, body )) ] + + self.request.write(formatter.crans_portal(entries))