[Zope3-checkins] CVS: zopeproducts/zwiki/renderer - __init__.py:1.1 configure.zcml:1.1 plaintext.py:1.1 stx.py:1.1
Stephan Richter
srichter@cbu.edu
Tue, 8 Apr 2003 22:49:12 -0400
Update of /cvs-repository/zopeproducts/zwiki/renderer
In directory cvs.zope.org:/tmp/cvs-serv9806/renderer
Added Files:
__init__.py configure.zcml plaintext.py stx.py
Log Message:
- Moved renderers to own sub-module.
- Implemented comments via renderers
- Updated to latest version of StructuredText (now Zope 2 HEAD version)
=== Added File zopeproducts/zwiki/renderer/__init__.py ===
=== Added File zopeproducts/zwiki/renderer/configure.zcml ===
<zopeConfigure
xmlns="http://namespaces.zope.org/zope"
xmlns:wiki="http://namespaces.zope.org/wiki">
<wiki:sourcetype
title="Plain Text"
interface="zopeproducts.zwiki.interfaces.IPlainTextSource">
<wiki:renderer
for="zope.publisher.interfaces.browser.IBrowserPresentation"
factory=".plaintext.PlainTextToHTMLRenderer" />
</wiki:sourcetype>
<wiki:sourcetype
title="Structured Text"
interface="zopeproducts.zwiki.interfaces.IStructuredTextSource">
<wiki:renderer
for="zope.publisher.interfaces.browser.IBrowserPresentation"
factory=".stx.StructuredTextToHTMLRenderer" />
</wiki:sourcetype>
</zopeConfigure>
=== Added File zopeproducts/zwiki/renderer/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/09 02:49:11 srichter Exp $
"""
from datetime import datetime
from zopeproducts.zwiki.interfaces import IPlainTextSource
from zope.publisher.browser import BrowserView
class PlainTextToHTMLRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = IPlainTextSource
def render(self, context):
html = self.context.replace('\n', '<br/>\n')
html = html.replace('----------',
'<hr class="comments" size="1" NOSHADE>')
return html
def createComment(self, comment, number):
date = self.request.locale.getDateTimeFormatter('medium').format(
datetime.now())
user = self.request.user.getLogin()
if number == 1:
return first_comment_template %(number, user, date, comment)
else:
return comment_template %(number, user, date, comment)
comment_template = '''
Comment #%i by %s (%s)
%s'''
first_comment_template = '''
----------
Comment #%i by %s (%s)
%s'''
=== Added File zopeproducts/zwiki/renderer/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/09 02:49:11 srichter Exp $
"""
import re
from datetime import datetime
from zope.publisher.browser import BrowserView
from zopeproducts.zwiki.interfaces import IStructuredTextSource
from StructuredText import HTML
class StructuredTextToHTMLRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = IStructuredTextSource
def render(self, context):
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(self, comment, number):
date = self.request.locale.getDateTimeFormatter('medium').format(
datetime.now())
user = self.request.user.getLogin()
if number == 1:
return first_comment_template %(number, user, date, comment)
else:
return comment_template %(number, user, date, comment)
comment_template = '''
Comment #%i by **%s** (%s)
%s'''
first_comment_template = '''
----------
Comment #%i by **%s** (%s)
%s'''