[Zope3-checkins] CVS: Zope3/src/zope/products/zptpage -
__init__.py:1.1.2.1 browser.py:1.1.2.1 configure.zcml:1.1.2.1
fssync.py:1.1.2.1 inlinecode.pt:1.1.2.1 interfaces.py:1.1.2.1
zpt.gif:1.1.2.1 zptpage.py:1.1.2.1
Philipp von Weitershausen
philikon at philikon.de
Wed Feb 11 11:29:28 EST 2004
Update of /cvs-repository/Zope3/src/zope/products/zptpage
In directory cvs.zope.org:/tmp/cvs-serv21715/zptpage
Added Files:
Tag: philikon-movecontent-branch
__init__.py browser.py configure.zcml fssync.py inlinecode.pt
interfaces.py zpt.gif zptpage.py
Log Message:
Get rid of zope.products.content and zope.products.codecontent and move
content components in their own packages at zope.products.
See the package geddon proposal: http://dev.zope.org/Zope3/PackageGeddon
=== Added File Zope3/src/zope/products/zptpage/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/products/zptpage/browser.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""Define view component for ZPT page eval results.
$Id: browser.py,v 1.1.2.1 2004/02/11 16:29:26 philikon Exp $
"""
class ZPTPageEval:
def index(self, **kw):
"""Call a Page Template"""
template = self.context
request = self.request
request.response.setHeader('content-type',
template.content_type)
return template.render(request, **kw)
=== Added File Zope3/src/zope/products/zptpage/configure.zcml ===
<configure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'
xmlns:fssync='http://namespaces.zope.org/fssync'
i18n_domain='zope'
>
<interface
interface=".interfaces.IZPTPage"
type="zope.app.interfaces.content.IContentType"
/>
<content class=".zptpage.ZPTPage">
<factory
id="ZPTPage"
permission="zope.ManageContent"
title="ZPT Page"
description="A simple, content-based Page Template"
/>
<require
permission="zope.View"
attributes="__call__ macros"
/>
<require
permission="zope.ManageContent"
interface=".interfaces.IZPTPage"
set_attributes="source expand evaluateInlineCode"
/>
<require
permission="zope.View"
interface=".interfaces.IRenderZPTPage"
/>
<implements
interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
/>
</content>
<adapter
for="zope.app.interfaces.folder.IFolder"
provides="zope.app.interfaces.file.IFileFactory"
name=".pt"
factory=".zptpage.ZPTFactory"
permission="zope.ManageContent"
/>
<adapter
for=".interfaces.IZPTPage"
provides="zope.app.interfaces.file.IReadFile"
factory=".zptpage.ZPTReadFile"
permission="zope.ManageContent"
/>
<adapter
for=".interfaces.IZPTPage"
provides="zope.app.interfaces.file.IWriteFile"
factory=".zptpage.ZPTWriteFile"
permission="zope.ManageContent"
/>
<adapter
for=".interfaces.IZPTPage"
provides="zope.app.interfaces.index.text.ISearchableText"
factory=".zptpage.SearchableText"
/>
<adapter
for=".interfaces.IZPTPage"
provides="zope.app.interfaces.size.ISized"
factory=".zptpage.Sized"
/>
<fssync:adapter
class=".zptpage.ZPTPage"
factory=".fssync.ZPTPageAdapter"
/>
<!-- browser directives -->
<!-- ZPT Page View Directives -->
<browser:page
name="index.html"
for=".interfaces.IZPTPage"
class=".browser.ZPTPageEval"
attribute="index"
permission="zope.View"
/>
<browser:page
name="source.html"
for=".interfaces.IZPTPage"
class=".zptpage.ZPTSourceView"
attribute="__call__"
permission="zope.ManageContent"
/>
<browser:addMenuItem
class=".zptpage.ZPTPage"
title="Templated Page"
permission="zope.ManageContent"
view="zope.products.zptpage.ZPTPage"
/>
<browser:addform
schema=".interfaces.IZPTPage"
label="Add a ZPT Page"
content_factory=".zptpage.ZPTPage"
name="zope.products.zptpage.ZPTPage"
permission="zope.ManageContent"
/>
<browser:editform
for=".interfaces.IZPTPage"
schema=".interfaces.IZPTPage"
name="edit.html"
label="Edit a ZPT page"
fields="source expand"
permission="zope.ManageContent"
menu="zmi_views" title="Edit"
/>
<browser:editform
for=".interfaces.IZPTPage"
schema=".interfaces.IZPTPage"
name="inlineCode.html"
label="Inline Code"
fields="evaluateInlineCode"
template="inlinecode.pt"
permission="zope.ManageContent"
menu="zmi_views" title="Inline Code"
/>
<!--browser:page
for=".interfaces.IZPTPage"
name="preview.html"
menu="zmi_views" title="Preview"
template="preview.pt"
permission="zope.ManageContent"
/-->
<browser:icon
name="zmi_icon"
for=".interfaces.IZPTPage"
file="zpt.gif"
/>
</configure>
=== Added File Zope3/src/zope/products/zptpage/fssync.py ===
##############################################################################
#
# Copyright (c) 2004 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.
#
##############################################################################
"""Filesystem synchronization support.
$Id: fssync.py,v 1.1.2.1 2004/02/11 16:29:26 philikon Exp $
"""
from zope.interface import implements
from zope.fssync.server.entryadapter import ObjectEntryAdapter
from zope.fssync.server.interfaces import IObjectFile
class ZPTPageAdapter(ObjectEntryAdapter):
"""ObjectFile adapter for ZPT page objects.
"""
implements(IObjectFile)
def getBody(self):
return self.context.getSource()
def setBody(self, data):
# Convert the data to Unicode, since that's what ZPTPage wants;
# it's normally read from a file so it'll be bytes.
# XXX This will die if it's not ASCII. Guess encoding???
self.context.setSource(unicode(data))
=== Added File Zope3/src/zope/products/zptpage/inlinecode.pt ===
<tal:tag condition="view/update"
/><html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">
<div metal:define-macro="body">
<form action="." tal:attributes="action request/URL" method="POST"
enctype="multipart/form-data">
<div metal:define-macro="formbody">
<h3 tal:condition="view/label"
tal:content="view/label"
metal:define-slot="heading"
>Edit something</h3>
<div style="color:red; font-weight: bold">
<p i18n:translate="">
This screen allows you to activate Inline Code Evaluation. This
means that you can say
<span i18n:name="code-example-1"><pre>
<script type="text/server-python"><br/>
print "Hello World!"<br/>
</script>
</pre></span>
or
<span i18n:name="code-example-2"><pre>
<p tal:script="text/server-python"><br/>
print "Hello World!"<br/>
</p>
</pre></span>
</p>
<p i18n:translate="">
Many Zope 3 developers consider inline code blocks something
very bad, since it does not follow the design of Page Templates
or Zope 3 in general. However, application and application server
developers are not the only audience for Zope 3. Scripters are
used to inline code from other technologies like PHP and it fits
their brain, which is very important.
</p>
</div>
<p tal:define="status view/update"
tal:condition="status"
tal:content="status" />
<p tal:condition="view/errors" i18n:translate="">
There are <strong tal:content="python:len(view.errors)"
i18n:name="num_errors">6</strong> input errors.
</p>
<tal:block repeat="error view/errors">
<div class="error" tal:content="error">error</div>
</tal:block>
<div class="row"
metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
tal:content="structure widget/row">
<div class="label">Name</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
</div>
<div class="row">
<div class="controls">
<input type="submit" value="Refresh"
i18n:attributes="value refresh-button" />
<input type="submit" name="UPDATE_SUBMIT" value="Submit"
i18n:attributes="value submit-button"/>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zptpage/interfaces.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""Templated Page Content Component Interfaces
$Id: interfaces.py,v 1.1.2.1 2004/02/11 16:29:26 philikon Exp $
"""
from zope.schema import SourceText, Bool
from zope.interface import Interface, Attribute
from zope.app.i18n import ZopeMessageIDFactory as _
class IZPTPage(Interface):
"""ZPT Pages are a persistent implementation of Page Templates."""
def setSource(text, content_type='text/html'):
"""Save the source of the page template.
'text' must be Unicode.
"""
def getSource():
"""Get the source of the page template."""
source = SourceText(
title=_("Source"),
description=_("The source of the page template."),
required=True)
expand = Bool(
title=_("Expand macros"),
description=_("Expand Macros so that they all are shown in the "
"code."),
default=False,
required=True)
evaluateInlineCode = Bool(
title=_("Evaluate Inline Code"),
description=_("Evaluate code snippets in TAL. We usually discourage "
"people from using this feature."),
default=False,
required=True)
class IRenderZPTPage(Interface):
content_type = Attribute('Content type of generated output')
def render(request, *args, **kw):
"""Render the page template.
The first argument is bound to the top-level 'request'
variable. The positional arguments are bound to the 'args'
variable and the keyword arguments are bound to the 'options'
variable.
"""
=== Added File Zope3/src/zope/products/zptpage/zpt.gif ===
<Binary-ish file>
=== Added File Zope3/src/zope/products/zptpage/zptpage.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""
$Id: zptpage.py,v 1.1.2.1 2004/02/11 16:29:26 philikon Exp $
"""
import re
from persistence import Persistent
from zope.proxy import removeAllProxies
from zope.security.proxy import ProxyFactory
from zope.interface import implements
from zope.pagetemplate.pagetemplate import PageTemplate
from zope.app.pagetemplate.engine import AppPT
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.index.text import ISearchableText
from zope.app.interfaces.size import ISized
from zope.app.interfaces.file import IReadFile, IWriteFile, IFileFactory
from zope.app.container.contained import Contained
from interfaces import IZPTPage, IRenderZPTPage
__metaclass__ = type
class ZPTPage(AppPT, PageTemplate, Persistent, Contained):
implements(IZPTPage, IRenderZPTPage)
# See zope.app.interfaces.content.zpt.IZPTPage
expand = False
# See zope.app.interfaces.content.zpt.IZPTPage
evaluateInlineCode = False
def getSource(self):
'''See zope.app.interfaces.content.zpt.IZPTPage'''
return self.read()
def setSource(self, text, content_type='text/html'):
'''See zope.app.interfaces.content.zpt.IZPTPage'''
if not isinstance(text, unicode):
raise TypeError("source text must be Unicode" , text)
self.pt_edit(text.encode('utf-8'), content_type)
# See zope.app.interfaces.content.zpt.IZPTPage
source = property(getSource, setSource, None,
"""Source of the Page Template.""")
def pt_getEngineContext(self, namespace):
context = self.pt_getEngine().getContext(namespace)
context.evaluateInlineCode = self.evaluateInlineCode
return context
def pt_getContext(self, instance, request, **_kw):
# instance is a View component
self = removeAllProxies(self)
namespace = super(ZPTPage, self).pt_getContext(**_kw)
namespace['template'] = self
namespace['request'] = request
namespace['container'] = namespace['context'] = instance
return namespace
def render(self, request, *args, **keywords):
instance = self.__parent__
request = ProxyFactory(request)
instance = ProxyFactory(instance)
if args: args = ProxyFactory(args)
kw = ProxyFactory(keywords)
namespace = self.pt_getContext(instance, request,
args=args, options=kw)
return self.pt_render(namespace)
source = property(getSource, setSource, None,
"""Source of the Page Template.""")
class SearchableText:
__used_for__ = IZPTPage
implements(ISearchableText)
def __init__(self, page):
self.page = page
def getSearchableText(self):
text = self.page.getSource()
if isinstance(text, str):
text = unicode(self.page.source, 'utf-8')
# else:
# text was already Unicode, which happens, but unclear how it
# gets converted to Unicode since the ZPTPage stores UTF-8 as
# an 8-bit string.
if self.page.content_type.startswith('text/html'):
tag = re.compile(r"<[^>]+>")
text = tag.sub('', text)
return [text]
class Sized:
implements(ISized)
def __init__(self, page):
self.num_lines = len(page.getSource().splitlines())
def sizeForSorting(self):
'See ISized'
return ('line', self.num_lines)
def sizeForDisplay(self):
'See ISized'
if self.num_lines == 1:
return _('1 line')
lines = _('${lines} lines')
lines.mapping = {'lines': str(self.num_lines)}
return lines
# File-system access adapters
class ZPTReadFile:
implements(IReadFile)
def __init__(self, context):
self.context = context
def read(self):
return self.context.getSource()
def size(self):
return len(self.read())
class ZPTWriteFile:
implements(IWriteFile)
def __init__(self, context):
self.context = context
def write(self, data):
# XXX Hm, how does one figure out an ftp encoding. Waaa.
self.context.setSource(unicode(data), None)
class ZPTFactory:
implements(IFileFactory)
def __init__(self, context):
self.context = context
def __call__(self, name, content_type, data):
r = ZPTPage()
# XXX Hm, how does one figure out an ftp encoding. Waaa.
r.setSource(unicode(data), content_type or 'text/html')
return r
class ZPTSourceView:
def __init__(self, context, request):
self.context = context
self.request = request
def __str__(self):
return self.context.getSource()
__call__ = __str__
More information about the Zope3-Checkins
mailing list