Skip to content

Commit

Permalink
- Moved z3c.pt include to extras_require chameleon. This makes the pa…
Browse files Browse the repository at this point in the history
…ckage

  independent from chameleon and friends and allows to include this
  dependencies in your own project.

- Upgrade to chameleon 2.0 template engine and use the newest z3c.pt and
  z3c.ptcompat packages adjusted to work with chameleon 2.0.
  
  See the notes from the z3c.ptcompat package:

  Update z3c.ptcompat implementation to use component-based template engine
  configuration, plugging directly into the Zope Toolkit framework.

  The z3c.ptcompat package no longer provides template classes, or ZCML
  directives; you should import directly from the ZTK codebase.

  Note that the ``PREFER_Z3C_PT`` environment option has been
  rendered obsolete; instead, this is now managed via component
  configuration.
  
  Also note that the chameleon CHAMELEON_CACHE environment value changed from
  True/False to a path. Skip this property if you don't like to use a cache.
  None or False defined in buildout environment section doesn't work. At least
  with chameleon <= 2.5.4
  
  Attention: You need to include the configure.zcml file from z3c.ptcompat
  for enable the z3c.pt template engine. The configure.zcml will plugin the 
  template engine. Also remove any custom built hooks which will import
  z3c.ptcompat in your tests or other places.
  • Loading branch information
projekt01 committed Oct 29, 2011
1 parent 0b5f9e1 commit bdfdb90
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 117 deletions.
31 changes: 29 additions & 2 deletions CHANGES.txt
Expand Up @@ -2,10 +2,37 @@
CHANGES
=======

1.3.1 (unreleased)
1.4.0 (2011-10-29)
------------------

- Nothing changed yet.
- Moved z3c.pt include to extras_require chameleon. This makes the package
independent from chameleon and friends and allows to include this
dependencies in your own project.

- Upgrade to chameleon 2.0 template engine and use the newest z3c.pt and
z3c.ptcompat packages adjusted to work with chameleon 2.0.

See the notes from the z3c.ptcompat package:

Update z3c.ptcompat implementation to use component-based template engine
configuration, plugging directly into the Zope Toolkit framework.

The z3c.ptcompat package no longer provides template classes, or ZCML
directives; you should import directly from the ZTK codebase.

Note that the ``PREFER_Z3C_PT`` environment option has been
rendered obsolete; instead, this is now managed via component
configuration.

Also note that the chameleon CHAMELEON_CACHE environment value changed from
True/False to a path. Skip this property if you don't like to use a cache.
None or False defined in buildout environment section doesn't work. At least
with chameleon <= 2.5.4

Attention: You need to include the configure.zcml file from z3c.ptcompat
for enable the z3c.pt template engine. The configure.zcml will plugin the
template engine. Also remove any custom built hooks which will import
z3c.ptcompat in your tests or other places.


1.3.0 (2010-07-05)
Expand Down
26 changes: 20 additions & 6 deletions buildout.cfg
@@ -1,17 +1,31 @@
[buildout]
develop = .
parts = test
parts = test coverage-test coverage-report
versions = versions

[versions]
z3c.pt = 1.2.1
Chameleon = 1.2.13
lxml = 2.3 # no windows release for 3.2.1


[test-environment]
CHAMELEON_DEBUG = False


[test]
recipe = zc.recipe.testrunner
eggs = z3c.macro [test]
environment = test-environment

[test-environment]
CHAMELEON_DEBUG = False
CHAMELEON_CACHE = False

[coverage-test]
recipe = zc.recipe.testrunner
eggs = z3c.macro [test]
defaults = ['--coverage', '../../coverage']
environment = test-environment


[coverage-report]
recipe = zc.recipe.egg
eggs = z3c.coverage
scripts = coveragereport
arguments = ('parts/coverage', 'parts/coverage/report')
163 changes: 84 additions & 79 deletions setup.py
@@ -1,79 +1,84 @@
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Setup
$Id$
"""
import os
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

setup(
name='z3c.macro',
version='1.3.1dev',
author = "Roger Ineichen and the Zope Community",
author_email = "zope-dev@zope.org",
description = "Simpler definition of ZPT macros.",
long_description=(
read('README.txt')
+ '\n\n' +
'Detailed Documentation\n'
'======================\n'
+ '\n\n' +
read('src', 'z3c', 'macro', 'README.txt')
+ '\n\n' +
read('src', 'z3c', 'macro', 'zcml.txt')
+ '\n\n' +
read('CHANGES.txt')
),
license = "ZPL 2.1",
keywords = "zope3 macro pagetemplate zpt",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
url = 'http://pypi.python.org/pypi/z3c.macro',
packages = find_packages('src'),
package_dir = {'':'src'},
namespace_packages = ['z3c'],
extras_require = dict(
test = ['z3c.template',
'z3c.pt>=1.0b4',
'lxml>=2.1.1',
'zope.browserpage>=3.12',
'zope.app.testing',
'zope.testing'],
),
install_requires = [
'setuptools',
'zope.component',
'zope.configuration',
'zope.interface',
'zope.pagetemplate',
'zope.publisher',
'zope.schema',
'zope.tales',
'z3c.ptcompat[zpt]',
],
include_package_data = True,
zip_safe = False,
)
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Setup
$Id$
"""
import os
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

setup(
name='z3c.macro',
version='1.4.0',
author = "Roger Ineichen and the Zope Community",
author_email = "zope-dev@zope.org",
description = "Simpler definition of ZPT macros.",
long_description=(
read('README.txt')
+ '\n\n' +
'Detailed Documentation\n'
'======================\n'
+ '\n\n' +
read('src', 'z3c', 'macro', 'README.txt')
+ '\n\n' +
read('src', 'z3c', 'macro', 'zcml.txt')
+ '\n\n' +
read('CHANGES.txt')
),
license = "ZPL 2.1",
keywords = "zope3 macro pagetemplate zpt",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
url = 'http://pypi.python.org/pypi/z3c.macro',
packages = find_packages('src'),
package_dir = {'':'src'},
namespace_packages = ['z3c'],
extras_require = dict(
test = [
'z3c.pt >= 2.1',
'z3c.ptcompat>=1.0',
'z3c.template',
'zope.app.testing',
'zope.browserpage>=3.12',
'zope.testing',
],
chameleon = [
'z3c.pt >= 2.1',
'z3c.ptcompat>=1.0',
],
),
install_requires = [
'setuptools',
'zope.component',
'zope.configuration',
'zope.interface',
'zope.pagetemplate >= 3.6.2'
'zope.publisher',
'zope.schema',
'zope.tales',
],
include_package_data = True,
zip_safe = False,
)
2 changes: 1 addition & 1 deletion src/z3c/macro/README.txt
Expand Up @@ -90,7 +90,7 @@ Let's now create a view using this page template:
... def __call__(self, **kwargs):
... return self.index(**kwargs)

>>> from z3c.ptcompat import ViewPageTemplateFile
>>> from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
>>> def SimpleViewClass(path, name=u''):
... return type(
... "SimpleViewClass", (simple,),
Expand Down
12 changes: 12 additions & 0 deletions src/z3c/macro/__init__.py
Expand Up @@ -14,3 +14,15 @@
"""
$Id$
"""

try:
# register chameleon ``macro`` tales expression for BaseTemplate
# there is not adapter or other registration support built in in
# z3c.pt and apply our tales expression to any page template or
# offer a custom PageTemplate is no option
from z3c.macro import tales
import z3c.pt.pagetemplate
z3c.pt.pagetemplate.BaseTemplate.expression_types['macro'] = tales.MacroExpr
except ImportError:
# we do not support z3c.pt
pass
2 changes: 2 additions & 0 deletions src/z3c/macro/configure.zcml
Expand Up @@ -11,11 +11,13 @@
handler=".tales.MacroExpression"
/>

<!--
<configure zcml:condition="installed chameleon.zpt">
<utility
name="macro"
component=".tales.z3cpt_macro_expression"
/>
</configure>
-->

</configure>
43 changes: 26 additions & 17 deletions src/z3c/macro/tales.py
Expand Up @@ -42,26 +42,35 @@ def __call__(self, econtext):
return get_macro_template(context, view, request, name)

try:
from chameleon.zpt.expressions import ExpressionTranslator
from chameleon.core import types

class Z3CPTMacroExpression(ExpressionTranslator):
"""Collect named IMacroTemplate via a TAL namespace called ``macro``."""
# define chameleon ``macro`` expression

from chameleon.tales import StringExpr
from chameleon.astutil import Static
from chameleon.astutil import Symbol
from chameleon.codegen import template

macro_regex = re.compile(r'^[A-Za-z][A-Za-z0-9_-]*$')
symbol = '_get_macro_template'

def validate(self, string):
if self.macro_regex.match(string) is None:
raise SyntaxError("%s is not a valid macro name." % string)
class MacroGetter(object):
"""Collect named IMacroTemplate via a TAL namespace called ``macro``."""

def translate(self, string, escape=None):
value = types.value("%s(context, view, request, '%s')" % \
(self.symbol, string))
value.symbol_mapping[self.symbol] = get_macro_template
return value
def __call__(self, context, request, view, name):
return zope.component.getMultiAdapter(
(context, view, request), interface=interfaces.IMacroTemplate,
name=name)

z3cpt_macro_expression = Z3CPTMacroExpression()
class MacroExpr(StringExpr):
traverser = Static(
template("cls()", cls=Symbol(MacroGetter), mode="eval")
)

def __call__(self, target, engine):
assignment = super(MacroExpr, self).__call__(target, engine)

return assignment + \
template(
"target = traverse(context, request, view, target.strip())",
target=target,
traverse=self.traverser,
)

except ImportError:
pass
34 changes: 26 additions & 8 deletions src/z3c/macro/tests.py
Expand Up @@ -26,30 +26,47 @@
import z3c.pt
import z3c.ptcompat

import z3c.macro.tales
import z3c.macro.zcml

# default template class
_templateViewClass = z3c.macro.zcml.ViewPageTemplateFile


def setUp(test):
root = setup.placefulSetUp(site=True)
test.globs['root'] = root


def setUpZPT(test):
z3c.ptcompat.config.disable()
setUp(test)

from zope.browserpage import metaconfigure
from z3c.macro import tales
metaconfigure.registerType('macro', tales.MacroExpression)
metaconfigure.registerType('macro', z3c.macro.tales.MacroExpression)

# apply correct template classes
global _templateViewClass
_templateViewClass = z3c.macro.zcml.ViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
z3c.macro.zcml.ViewPageTemplateFile = ViewPageTemplateFile


def setUpZ3CPT(suite):
z3c.ptcompat.config.enable()
setUp(suite)
xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
xmlconfig.XMLConfig('configure.zcml', z3c.ptcompat)()

# apply correct template classes
global _templateViewClass
_templateViewClass = z3c.macro.zcml.ViewPageTemplateFile
from z3c.pt.pagetemplate import ViewPageTemplateFile
z3c.macro.zcml.ViewPageTemplateFile = ViewPageTemplateFile

from z3c.macro import tales
component.provideUtility(
tales.z3cpt_macro_expression, name='macro')

def tearDown(test):
setup.placefulTearDown()
global _templateViewClass
z3c.macro.zcml.ViewPageTemplateFile = _templateViewClass


def test_suite():
tests = ((
Expand All @@ -63,5 +80,6 @@ def test_suite():

return unittest.TestSuite(itertools.chain(*tests))


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

0 comments on commit bdfdb90

Please sign in to comment.