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
117
wiki/parser/Portail.py
Normal file
117
wiki/parser/Portail.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
"""
|
||||
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
|
||||
}}}
|
||||
|
||||
CREDIT
|
||||
Le code est derive de celui de Gallery2.
|
||||
|
||||
"""
|
||||
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.strip(),request)
|
||||
wikiizer.format(formatter)
|
||||
result=out.getvalue()
|
||||
request.redirect()
|
||||
del out
|
||||
|
||||
return result.strip()
|
||||
|
||||
#####################################################################
|
||||
# PortailFormatter : creer le code html du portail a l'aide de
|
||||
# de formatter et l'envoie a request
|
||||
#######
|
||||
class PortailFormatter:
|
||||
|
||||
def __init__(self, request, formatter):
|
||||
self.formatter = formatter
|
||||
self.request = request
|
||||
self.counter = 0
|
||||
|
||||
def open(self):
|
||||
self.request.write(self.formatter.table(1,{'style':'width:100%;padding:10px;'}))
|
||||
|
||||
def cell(self, title, description, image):
|
||||
if self.counter==0:
|
||||
self.request.write(self.formatter.table_row(1))
|
||||
self.request.write(self.formatter.table_cell(1,{'style':'width:50%;border:none;padding:20px 20px 20px 50px;background:transparent url(\'' + image.replace("\'","\\\'") + '\') center left no-repeat; vertical-align:center;'}))
|
||||
self.request.write(title)
|
||||
self.request.write(description)
|
||||
self.request.write(self.formatter.table_cell(0))
|
||||
if self.counter==1:
|
||||
self.request.write(self.formatter.table_row(0))
|
||||
self.counter = (self.counter + 1)%2
|
||||
|
||||
def close(self):
|
||||
if self.counter==1:
|
||||
self.request.write(self.formatter.table_cell(1,{'style':'width:50%;border:none;padding:20px 20px 20px 50px;'}))
|
||||
self.request.write(self.formatter.table_cell(0))
|
||||
self.request.write(self.formatter.table_row(0))
|
||||
self.request.write(self.formatter.table(0))
|
||||
|
||||
#####################################################################
|
||||
# Parser : classe principale, c'est elle qui parse
|
||||
#######
|
||||
class Parser:
|
||||
|
||||
def __init__(self, raw, request, **kw):
|
||||
self.request = request
|
||||
self.raw = raw
|
||||
return
|
||||
|
||||
|
||||
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 initialise la classe qui va fabriquer le code html
|
||||
portail = PortailFormatter(self.request, formatter)
|
||||
portail.open()
|
||||
|
||||
# on traite les ligne une à une
|
||||
for line in quotes:
|
||||
line=line.strip()
|
||||
items=line.split('|',2)
|
||||
if items.__len__()<3:
|
||||
self.request.write('<!-- error, wrong number of parameters -->')
|
||||
else:
|
||||
description=items.pop().strip()
|
||||
link=items.pop().strip()
|
||||
image = AttachFile.getAttachUrl(current_pagename, items.pop().strip(), self.request)
|
||||
|
||||
link = to_wikiname(self.request, formatter, link)
|
||||
description = to_wikiname(self.request, formatter, description)
|
||||
portail.cell(link, description, image)
|
||||
portail.close()
|
||||
|
||||
return
|
Loading…
Add table
Add a link
Reference in a new issue