[Zope3-checkins] CVS: zopeproducts/zwiki - stx.py:1.1 plaintext.py:1.1 sourcetype.py:1.1
Stephan Richter
srichter@cbu.edu
Tue, 8 Apr 2003 00:13:24 -0400
Update of /cvs-repository/zopeproducts/zwiki
In directory cvs.zope.org:/tmp/cvs-serv5730
Added Files:
stx.py plaintext.py sourcetype.py
Log Message:
Implemented Source Type registry, so that it will be easy to plug in new
rendering engines. Right now there is only support for STX and Plain Text.
=== Added File zopeproducts/zwiki/stx.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Structured Text Renderer Classes
$Id: stx.py,v 1.1 2003/04/08 04:13:19 srichter Exp $
"""
import re
from StructuredText import HTML
from interfaces import IStructuredTextSource
from zope.publisher.browser import BrowserView
class StructuredTextToHTMLRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = IStructuredTextSource
def render(self, context, request):
text = HTML(str(self.context))
# strip html & body added by some zope versions
text = re.sub(
r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1',text)
return text
def createComment(comment, number, request):
pass
=== Added File zopeproducts/zwiki/plaintext.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Plain Text Renderer Classes
$Id: plaintext.py,v 1.1 2003/04/08 04:13:19 srichter Exp $
"""
from interfaces import IPlainTextSource
from zope.publisher.browser import BrowserView
class PlainTextToHTMLRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = IPlainTextSource
def render(self, context, request):
return self.context.replace('\n', '<br/>\n')
def createComment(comment, number, request):
pass
=== Added File zopeproducts/zwiki/sourcetype.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Wiki Source Types Service
Allows us to register source types for wiki page sources.
$Id: sourcetype.py,v 1.1 2003/04/08 04:13:19 srichter Exp $
"""
from zopeproducts.zwiki.interfaces import IGlobalWikiSourceTypeService
class GlobalWikiSourceTypeService:
__doc__ = IGlobalWikiSourceTypeService.__doc__
__implements__ = IGlobalWikiSourceTypeService
def __init__(self):
self.__types = {}
def provide(self, title, iface):
"See zopeproducts.zwiki.interfaces.IGlobalWikiSourceTypeService"
self.__types[title] = iface
def get(self, title, default=None):
"See zopeproducts.zwiki.interfaces.IWikiSourceTypeService"
return self.__types.get(title, default)
def query(self, title):
"See zopeproducts.zwiki.interfaces.IWikiSourceTypeService"
return self.__types[title]
def getAllTitles(self):
"See zopeproducts.zwiki.interfaces.IWikiSourceTypeService"
return self.__types.keys()
def createObject(self, title, source):
"See zopeproducts.zwiki.interfaces.IWikiSourceTypeService"
iface = self.query(title)
class Source(unicode):
__implements__ = iface
return Source(source)
SourceTypes = GlobalWikiSourceTypeService()