[Checkins] SVN: z3ext.skintool/ initial import
Nikolay Kim
fafhrd at datacom.kz
Fri Mar 28 06:00:36 EDT 2008
Log message for revision 84982:
initial import
Changed:
A z3ext.skintool/
A z3ext.skintool/branches/
A z3ext.skintool/tags/
A z3ext.skintool/trunk/
A z3ext.skintool/trunk/AUTHOR.txt
A z3ext.skintool/trunk/CHANGES.txt
A z3ext.skintool/trunk/LICENSE.txt
A z3ext.skintool/trunk/bootstrap.py
A z3ext.skintool/trunk/buildout.cfg
A z3ext.skintool/trunk/setup.py
A z3ext.skintool/trunk/src/
A z3ext.skintool/trunk/src/z3ext/
A z3ext.skintool/trunk/src/z3ext/__init__.py
A z3ext.skintool/trunk/src/z3ext/skintool/
A z3ext.skintool/trunk/src/z3ext/skintool/README.txt
A z3ext.skintool/trunk/src/z3ext/skintool/__init__.py
A z3ext.skintool/trunk/src/z3ext/skintool/configure.zcml
A z3ext.skintool/trunk/src/z3ext/skintool/interfaces.py
A z3ext.skintool/trunk/src/z3ext/skintool/meta.zcml
A z3ext.skintool/trunk/src/z3ext/skintool/subscribers.py
A z3ext.skintool/trunk/src/z3ext/skintool/tests.py
A z3ext.skintool/trunk/src/z3ext/skintool/tool.py
A z3ext.skintool/trunk/src/z3ext/skintool/vocabulary.py
A z3ext.skintool/trunk/src/z3ext/skintool/zcml.py
-=-
Property changes on: z3ext.skintool/trunk
___________________________________________________________________
Name: svn:ignore
+ bin
develop-eggs
eggs
parts
coverage
.installed.cfg
Added: z3ext.skintool/trunk/AUTHOR.txt
===================================================================
--- z3ext.skintool/trunk/AUTHOR.txt (rev 0)
+++ z3ext.skintool/trunk/AUTHOR.txt 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1 @@
+Nikolay Kim (fafhrd91 <at> gmail <dot> com)
Added: z3ext.skintool/trunk/CHANGES.txt
===================================================================
--- z3ext.skintool/trunk/CHANGES.txt (rev 0)
+++ z3ext.skintool/trunk/CHANGES.txt 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,39 @@
+=======
+CHANGES
+=======
+
+1.0.0 (2008-03-28)
+------------------
+
+- Code cleanup
+
+- Added tests
+
+- Code moved to svn.zope.org
+
+
+0.13 (2008-02-28)
+----------------
+
+- Use z3c.autoinclude
+
+- Do not generate InterfaceClass object, just apply list of layers
+
+
+0.12 (2008-02-08)
+-----------------
+
+- Code cleanup
+
+
+0.11 (2008-02-06)
+------------------
+
+- Added ISkinable marker interface.
+ Now object should implement ISkinable implicitly to support skintool
+
+
+0.10 (2008-02-01)
+------------------
+
+- Initial release.
Added: z3ext.skintool/trunk/LICENSE.txt
===================================================================
--- z3ext.skintool/trunk/LICENSE.txt (rev 0)
+++ z3ext.skintool/trunk/LICENSE.txt 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+ accompanying copyright notice, this list of conditions,
+ and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+ copyright notice, this list of conditions, and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+ endorse or promote products derived from this software
+ without prior written permission from the copyright
+ holders.
+
+4. The right to distribute this software or to use it for
+ any purpose does not give you the right to use
+ Servicemarks (sm) or Trademarks (tm) of the copyright
+ holders. Use of them is covered by separate agreement
+ with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+ files to carry prominent notices stating that you changed
+ the files and the date of any change.
+
+Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+ AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
Added: z3ext.skintool/trunk/bootstrap.py
===================================================================
--- z3ext.skintool/trunk/bootstrap.py (rev 0)
+++ z3ext.skintool/trunk/bootstrap.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: z3ext.skintool/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/buildout.cfg
===================================================================
--- z3ext.skintool/trunk/buildout.cfg (rev 0)
+++ z3ext.skintool/trunk/buildout.cfg 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,20 @@
+[buildout]
+develop = .
+parts = test coverage-test coverage-report
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.skintool [test]
+
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.skintool [test]
+defaults = ['--coverage', '../../coverage']
+
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')
Added: z3ext.skintool/trunk/setup.py
===================================================================
--- z3ext.skintool/trunk/setup.py (rev 0)
+++ z3ext.skintool/trunk/setup.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,74 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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 for z3ext.skintool package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version = '1.0.0dev'
+
+
+setup(name='z3ext.skintool',
+ version=version,
+ description="Tool for merging skin layers at runtime",
+ long_description=(
+ 'Detailed Documentation\n' +
+ '======================\n'
+ + '\n\n' +
+ read('src', 'z3ext', 'skintool', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ 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'],
+ author='Nikolay Kim',
+ author_email='fafhrd91 at gmail.com',
+ url='http://z3ext.net/',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ namespace_packages=['z3ext'],
+ install_requires = ['setuptools',
+ 'zope.schema',
+ 'zope.proxy',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.i18nmessageid',
+ 'zope.lifecycleevent',
+ 'zope.security',
+ 'zope.configuration',
+ 'zope.app.component',
+ 'zope.app.publication',
+ 'z3c.autoinclude',
+ 'z3ext.controlpanel',
+ ],
+ extras_require = dict(test=['zope.app.testing',
+ 'zope.testing',
+ ]),
+ include_package_data = True,
+ zip_safe = False
+ )
Property changes on: z3ext.skintool/trunk/setup.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/__init__.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/__init__.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/__init__.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Property changes on: z3ext.skintool/trunk/src/z3ext/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/README.txt
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/README.txt (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/README.txt 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,166 @@
+=========
+Skin tool
+=========
+
+Skin tool allow configure skin at runtime for each ISite object.
+
+ >>> from z3ext.skintool import interfaces, zcml
+ >>> from z3ext.skintool.tool import skinToolModified
+
+ >>> from zope import interface, component, schema
+
+We need site object and request
+
+ >>> from zope.app.component.hooks import getSite
+ >>> site = getSite()
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+
+Now let's define layer
+
+ >>> from zope import interface
+ >>> class IMyLayer(interface.Interface):
+ ... pass
+
+Before we can use IMyLayer we should register it in local registry
+
+ >>> zcml.layerDirective(IMyLayer, u'mylayer', u'My layer', '', ())
+
+Now layer should be listed in vocabulary.
+
+ >>> from z3ext.skintool.vocabulary import LayersVocabulary
+ >>> voc = LayersVocabulary()(site)
+ >>> term = voc.getTerm(IMyLayer)
+ >>> term.value == u'mylayer'
+ True
+ >>> term.title == 'My layer'
+ True
+ >>> term.token == u'mylayer'
+ True
+
+All layers applied in IBeforeTraverseEvent event for ISite object. We will
+use handler directly.
+
+ >>> from z3ext.skintool.subscribers import threadServiceSubscriber
+ >>> from zope.app.publication.interfaces import BeforeTraverseEvent
+
+Let's check layer for our request.
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+
+ >>> IMyLayer.providedBy(request)
+ False
+
+This is because we should configure skin tool to use our layer and
+site object should implement ISkinable interface.
+
+ >>> interface.directlyProvides(site, interfaces.ISkinable)
+
+Let's configure skin tool
+
+ >>> tool = component.getUtility(interfaces.ISkinTool)
+ >>> tool.user_layers = [u'mylayer']
+ >>> skinToolModified()
+
+Let's try again
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer.providedBy(request)
+ True
+
+Change layers config
+
+ >>> tool.user_layers = []
+ >>> skinToolModified()
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer.providedBy(request)
+ False
+
+
+Some layers can depends on other layers
+
+ >>> class IMyLayer2(interface.Interface):
+ ... pass
+
+ >>> zcml.layerDirective(IMyLayer2, u'mylayer2', u'My layer2', '', (IMyLayer,))
+ >>> tool.user_layers = [u'mylayer2']
+ >>> skinToolModified()
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer2.providedBy(request)
+ True
+ >>> IMyLayer.providedBy(request)
+ True
+
+We can define default layer, that will added automaticly
+
+ >>> class IDefaultLayer(interface.Interface):
+ ... pass
+
+We have to register utility IDefaultLayer
+
+ >>> component.provideUtility(IDefaultLayer, interfaces.IDefaultLayer, 'default')
+ >>> tool.user_layers = [u'mylayer']
+ >>> skinToolModified()
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer.providedBy(request)
+ True
+ >>> IDefaultLayer.providedBy(request)
+ True
+
+
+z3ext:layer directive
+---------------------
+
+We can do same with z3ext:layer directive. We need load zcml file:
+
+ >>> import z3ext.skintool
+ >>> from zope.configuration import xmlconfig
+ >>> context = xmlconfig.file('meta.zcml', z3ext.skintool)
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... xmlns="http://namespaces.zope.org/zope" i18n_domain="z3ext">
+ ... <z3ext:layer
+ ... name="mylayer3"
+ ... layer="z3ext.skintool.README.IMyLayer"
+ ... title="My zcml layer" />
+ ... </configure>""", context)
+
+ >>> voc = LayersVocabulary()(site)
+ >>> term = voc.getTerm(IMyLayer)
+ >>> term.value == u'mylayer3'
+ True
+ >>> term.title == 'My zcml layer'
+ True
+ >>> term.token == u'mylayer3'
+ True
+
+ >>> tool.user_layers = ['mylayer3']
+ >>> skinToolModified()
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer.providedBy(request)
+ True
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... xmlns="http://namespaces.zope.org/zope" i18n_domain="z3ext">
+ ... <z3ext:layer
+ ... name="mylayer4"
+ ... layer="z3ext.skintool.README.IMyLayer2"
+ ... title="My zcml layer4"
+ ... require="z3ext.skintool.README.IMyLayer" />
+ ... </configure>""", context)
+
+ >>> tool.user_layers = [u'mylayer2']
+ >>> skinToolModified()
+
+ >>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
+ >>> IMyLayer2.providedBy(request)
+ True
+ >>> IMyLayer.providedBy(request)
+ True
Added: z3ext.skintool/trunk/src/z3ext/skintool/__init__.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/__init__.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/__init__.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1 @@
+# This file is necessary to make this directory a package.
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/configure.zcml
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/configure.zcml (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/configure.zcml 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,25 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ i18n_domain="z3ext">
+
+ <autoinclude package="z3ext.skintool" />
+
+ <!-- set default skin -->
+ <subscriber handler=".subscribers.threadServiceSubscriber" />
+
+ <!-- layers changed -->
+ <subscriber handler=".tool.skinToolModified" />
+
+ <utility
+ name="z3ext skin layers"
+ factory=".vocabulary.LayersVocabulary" />
+
+ <z3ext:configlet
+ name="ui.portalskin"
+ title="Portal skin"
+ description="Portal skin configuration."
+ class=".tool.SkinTool"
+ schema=".interfaces.ISkinTool" />
+
+</configure>
Added: z3ext.skintool/trunk/src/z3ext/skintool/interfaces.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/interfaces.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/interfaces.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,49 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+""" z3ext.skintool interfaces
+
+$Id$
+"""
+from zope import schema, interface
+from zope.i18nmessageid import MessageFactory
+
+_ = MessageFactory('z3ext')
+
+
+class ISkinable(interface.Interface):
+ """ marker interface for skinable objects """
+
+
+class IDefaultLayer(interface.interfaces.IInterface):
+ """ default layer (automaticlly added to skin) """
+
+
+class IDefaultLayers(interface.Interface):
+ """ adapter that provide default layers """
+
+ layers = interface.Attribute('tuple of ILayer interfaces')
+
+
+class ISkinTool(interface.Interface):
+ """ skin tool, allow generate skin on the fly """
+
+ user_layers = schema.List(
+ title = _(u'Layers'),
+ description = _(u'Select skin layers.'),
+ value_type = schema.Choice(vocabulary = "z3ext skin layers"),
+ default = [],
+ required = False)
+
+ def generate():
+ """ generate skin interface """
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/meta.zcml
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/meta.zcml (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/meta.zcml 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,14 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/z3ext">
+
+ <meta:directive
+ name="layer"
+ schema=".zcml.ILayerDirective"
+ handler=".zcml.layerDirectiveHandler" />
+
+ </meta:directives>
+
+</configure>
Added: z3ext.skintool/trunk/src/z3ext/skintool/subscribers.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/subscribers.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/subscribers.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,44 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import component
+from zope.proxy import removeAllProxies
+from zope.component import getUtility
+from zope.interface import directlyProvides
+from zope.app.component.interfaces import ISite
+from zope.app.publication.interfaces import IBeforeTraverseEvent
+
+from interfaces import ISkinTool, ISkinable
+
+
+ at component.adapter(ISite, IBeforeTraverseEvent)
+def threadServiceSubscriber(site, event,
+ ISkinable = ISkinable,
+ removeAllProxies=removeAllProxies,
+ directlyProvides=directlyProvides):
+ site = removeAllProxies(site)
+
+ if not ISkinable.providedBy(site):
+ return
+
+ skin = getattr(site, '_v_skin', None)
+ if skin is None:
+ skin = getUtility(ISkinTool).generate()
+ site._v_skin = skin
+
+ if skin:
+ directlyProvides(event.request, *skin)
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/subscribers.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/tests.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/tests.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/tests.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import unittest, doctest
+from zope import interface, component
+from zope.app.testing import setup
+
+from tool import SkinTool
+
+
+def setUp(test):
+ setup.placefulSetUp(site=True)
+ setup.setUpTestAsModule(test, 'z3ext.skintool.README')
+
+ # register utility
+ tool = SkinTool()
+ component.provideUtility(tool)
+
+
+def tearDown(test):
+ setup.placefulTearDown()
+ setup.tearDownTestAsModule(test)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUp, tearDown=tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
+ ))
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/tool.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/tool.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/tool.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,85 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+""" skintool implementation
+
+$Id$
+"""
+from zope import interface, component
+from zope.component import getSiteManager, getAdapters, getUtilitiesFor
+from zope.security.proxy import removeSecurityProxy
+from zope.lifecycleevent.interfaces import IObjectModifiedEvent
+from zope.publisher.interfaces.browser import \
+ IDefaultSkin, IBrowserRequest, IDefaultBrowserLayer
+from zope.app.component.hooks import getSite
+
+from interfaces import IDefaultLayer, IDefaultLayers, ISkinTool
+
+layers_byname = {}
+layers_registry = {}
+
+
+class SkinTool(object):
+ interface.implements(ISkinTool)
+
+ def generate(self):
+ layers = tuple(self.user_layers)
+
+ bases = self._get_default()
+
+ for name in layers:
+ layer = layers_byname.get(name)
+ if layer is not None:
+ self._get_layers(layer, bases)
+
+ # get base skin
+ adapters = getSiteManager().adapters
+ skin = adapters.lookup((IBrowserRequest,), IDefaultSkin, name='')
+ if skin is not None:
+ bases.insert(0, skin)
+ else:
+ bases.insert(0, IDefaultBrowserLayer)
+
+ bases.reverse()
+ return bases
+
+ def _get_default(self):
+ layers = []
+ for name, adapter in getAdapters((getSite(),), IDefaultLayers):
+ for layer in adapter.layers:
+ self._get_layers(layer, layers)
+
+ for name, layer in getUtilitiesFor(IDefaultLayer):
+ self._get_layers(layer, layers)
+
+ return layers
+
+ def _get_layers(self, layer, layers):
+ if layer in layers:
+ return
+
+ info = layers_registry.get(layer)
+
+ if info is not None:
+ for l in info[4]:
+ self._get_layers(l, layers)
+
+ layers.append(layer)
+
+
+ at component.adapter(ISkinTool, IObjectModifiedEvent)
+def skinToolModified(*args):
+ try:
+ del removeSecurityProxy(getSite())._v_skin
+ except:
+ pass
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/tool.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/vocabulary.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/vocabulary.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/vocabulary.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,44 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import interface
+from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+
+from tool import layers_registry
+
+
+class Vocabulary(SimpleVocabulary):
+
+ def getTerm(self, value):
+ try:
+ return self.by_value[value]
+ except KeyError:
+ return self.by_value[self.by_value.keys()[0]]
+
+
+class LayersVocabulary(object):
+ interface.implements(IVocabularyFactory)
+
+ def __call__(self, context):
+ terms = []
+ for layer, info in layers_registry.items():
+ terms.append((info[2], info[1]))
+
+ terms.sort()
+ return Vocabulary([SimpleTerm(name,name,title)
+ for title, name in terms])
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/vocabulary.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.skintool/trunk/src/z3ext/skintool/zcml.py
===================================================================
--- z3ext.skintool/trunk/src/z3ext/skintool/zcml.py (rev 0)
+++ z3ext.skintool/trunk/src/z3ext/skintool/zcml.py 2008-03-28 10:00:35 UTC (rev 84982)
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+""" z3ext:layer directive
+
+$Id$
+"""
+from zope import schema, interface, component
+from zope.configuration.fields import Tokens, GlobalInterface, PythonIdentifier
+
+from z3ext.skintool.tool import layers_byname, layers_registry
+
+
+class ILayerDirective(interface.Interface):
+
+ layer = GlobalInterface(
+ title = u'Layer',
+ description = u'Skin layer.',
+ required = True)
+
+ name = PythonIdentifier(
+ title = u'Name',
+ description = u'Content name.',
+ required = True)
+
+ title = schema.TextLine(
+ title = u'Title',
+ description = u'Content title.',
+ required = True)
+
+ description = schema.TextLine(
+ title = u'Description',
+ description = u'Content description.',
+ required = False)
+
+ require = Tokens(
+ title = u'Require',
+ description = u'Interface of other layers that are '\
+ u'required by this layer.',
+ required = False,
+ value_type = GlobalInterface())
+
+
+def layerDirectiveHandler(_context, layer, name, title,
+ description='', require=[]):
+ _context.action(
+ discriminator = ('z3ext.skintool-layer', layer, name),
+ callable = layerDirective,
+ args = (layer, name, title, description, require))
+
+
+def layerDirective(layer, name, title, description, require):
+ sitemanager = component.getGlobalSiteManager()
+
+ layers_byname[name] = layer
+ layers_registry[layer] = (layer, name, title, description, require)
Property changes on: z3ext.skintool/trunk/src/z3ext/skintool/zcml.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list