[Zope3-checkins] CVS: Zope3/src/zope/app/publisher - pagetemplateresource.py:1.1

Philipp von Weitershausen philikon at philikon.de
Mon Aug 11 11:58:09 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher
In directory cvs.zope.org:/tmp/cvs-serv28048

Added Files:
	pagetemplateresource.py 
Log Message:
Added implementations and tests for

a) PageTemplateResource

  This allows resources to be page templates. They will not have any context,
  container nor view variable in their namespace. My current and only use
  case for them right now is to provide i18n'd, markup-based resources.
  You may add one using::

  <browser:resource name="foobar.html" template="foobar.pt" />

b) DirectoryResource

  This is a browser resource that represents a file system directory. It
  uses a simple mapping based on file extensions to delegate to either
  FileResourceFactory, ImageResourceFactory or PageTemplateResourceFactory.
  You may add one using::

  <browser:resourceDirectory name="myresdir" directory="myresdir" />


=== Added File Zope3/src/zope/app/publisher/pagetemplateresource.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.
#
##############################################################################
"""Page Template Resource

$Id: pagetemplateresource.py,v 1.1 2003/08/11 14:58:05 philikon Exp $
"""

from zope.pagetemplate.pagetemplatefile import PageTemplateFile
from zope.app.pagetemplate.engine import AppPT

class PageTemplate(AppPT, PageTemplateFile):
    """
    Resource that is a page template
    """

    def __init__(self, filename, _prefix=None, content_type=None):
        _prefix = self.get_path_from_prefix(_prefix)
        super(PageTemplate, self).__init__(filename, _prefix)
        if content_type is not None:
            self.content_type = content_type

    def pt_getContext(self, request, **kw):
        namespace = super(PageTemplate, self).pt_getContext(**kw)
        namespace['context'] = None
        namespace['request'] = request
        return namespace

    def __call__(self, request, **keywords):
        namespace = self.pt_getContext(
            request=request,
            options=keywords
            )
        return self.pt_render(namespace)




More information about the Zope3-Checkins mailing list