[Checkins] SVN: z3c.resourcecollector/trunk/ initial import
Zoltan Szabo
zoltan.szabo at informmedia.ro
Wed Jan 23 16:41:29 EST 2008
Log message for revision 83126:
initial import
Changed:
A z3c.resourcecollector/trunk/
A z3c.resourcecollector/trunk/bootstrap.py
A z3c.resourcecollector/trunk/buildout.cfg
A z3c.resourcecollector/trunk/setup.py
A z3c.resourcecollector/trunk/src/
A z3c.resourcecollector/trunk/src/z3c/
A z3c.resourcecollector/trunk/src/z3c/__init__.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/CHANGES.txt
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/__init__.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/browser.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/interfaces.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/meta.zcml
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/tests.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/testview.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/utility.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/z3c.resourcecollector-meta.zcml
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.py
A z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.txt
-=-
Added: z3c.resourcecollector/trunk/bootstrap.py
===================================================================
--- z3c.resourcecollector/trunk/bootstrap.py (rev 0)
+++ z3c.resourcecollector/trunk/bootstrap.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -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: bootstrap.py 73461 2007-03-22 16:02:08Z batlogg $
+"""
+
+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)
Added: z3c.resourcecollector/trunk/buildout.cfg
===================================================================
--- z3c.resourcecollector/trunk/buildout.cfg (rev 0)
+++ z3c.resourcecollector/trunk/buildout.cfg 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,7 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.resourcecollector [test]
\ No newline at end of file
Added: z3c.resourcecollector/trunk/setup.py
===================================================================
--- z3c.resourcecollector/trunk/setup.py (rev 0)
+++ z3c.resourcecollector/trunk/setup.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,35 @@
+import os
+
+from setuptools import setup, find_packages, Extension
+
+setup(name='z3c.resourcecollector',
+ version='1.0.0',
+ url='https://svn.lovelysystems.com/repos/dev/package/z3c.resourcecollector',
+ license='ZPL',
+ description='',
+ author='Zoltan Szabo',
+ author_email='zoltan.szabo at informmedia.ro',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ namespace_packages=['z3c'],
+ extras_require=dict(test=['zope.app.testing',
+ 'zope.testing',
+ 'z3c.testing',
+ 'zope.testbrowser'
+ ]),
+ install_requires=['setuptools',
+ 'zope.configuration',
+ 'zope.interface',
+ 'zope.component',
+ 'zope.app.component',
+ 'zope.app.appsetup',
+ 'zope.app.wsgi',
+ 'zope.cachedescriptors',
+ 'zope.publisher',
+ 'zope.schema',
+ 'zope.security',
+ 'zope.viewlet',
+ ],
+ include_package_data = True,
+ zip_safe = False,
+ )
Added: z3c.resourcecollector/trunk/src/z3c/__init__.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/__init__.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/__init__.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,4 @@
+try:
+ __import__('pkg.resources').declare_namespace(__name__)
+except ImportError:
+ pass
\ No newline at end of file
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/CHANGES.txt
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/CHANGES.txt (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/CHANGES.txt 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,11 @@
+1.0.0
+-----
+
+Initial release
+
+Create zcml directives for creating a custom resource.
+It collects javascripts and css files and merges them into a single resource.
+It behaves exactly as a normal resource.
+Also provides 2 viewlets JSCollectorViewlet, and CSSCollectorViewlet.
+These viewlets are returning the html element what can reach the collector resource.
+Also adds a hash in the end of the resource for versionning.
\ No newline at end of file
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/__init__.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/__init__.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/__init__.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,13 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/browser.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/browser.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/browser.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+import time
+
+from zope.app.publisher.browser.fileresource import FileResource
+from zope.viewlet import viewlet
+
+import zope.component
+
+from interfaces import ICollectorUtility
+
+
+class CollectorResource(FileResource):
+
+ def __init__(self, request):
+ self.request = request
+
+ def GET(self):
+ rs = zope.component.getUtility(ICollectorUtility, self.__name__)
+
+ resources = rs.getResources(self.request)
+ self.request.response.setHeader('Content-Type', rs.content_type)
+ secs = 31536000
+ self.request.response.setHeader('Cache-Control', 'public,max-age=%s' % secs)
+ t = time.time() + secs
+ self.request.response.setHeader('Expires',
+ time.strftime("%a, %d %b %Y %H:%M:%S GMT",
+ time.gmtime(t)))
+ return resources
+
+
+class JSCollectorViewlet(viewlet.ViewletBase):
+ template = """<script src="%s?hash=%s"
+ type="text/javascript">
+ </script>"""
+
+ @property
+ def collector(self):
+ return self.__name__
+
+ def render(self):
+ originalHeader = self.request.response.getHeader('Content-Type')
+ if originalHeader is None:
+ originalHeader = "text/html"
+ rs = zope.component.getUtility(ICollectorUtility, self.collector)
+ versionedresource = rs.getUrl(self.context,self.request)
+ view=zope.component.getAdapter(self.request,name=self.collector)
+ url = view()
+ script = self.template %(url, versionedresource)
+ self.request.response.setHeader('Content-Type',originalHeader)
+ return script
+
+class CSSCollectorViewlet(JSCollectorViewlet):
+ template = """<link rel="stylesheet" type="text/css" href="%s?hash=%s" />"""
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/interfaces.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/interfaces.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/interfaces.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+from zope import interface
+
+class ICollectorUtility(interface.Interface):
+ """interface class"""
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/meta.zcml
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/meta.zcml (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/meta.zcml 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,21 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/browser">
+
+ <meta:directive
+ name="collector"
+ schema=".zcml.ICollectorDirective"
+ handler=".zcml.handleCollector"
+ />
+
+ <meta:directive
+ name="collectorItem"
+ schema=".zcml.ICollectorItemDirective"
+ handler=".zcml.handleCollectorItem"
+ />
+
+ </meta:directives>
+
+</configure>
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/tests.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/tests.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/tests.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,22 @@
+__docformat__ = "reStructuredText"
+
+import doctest
+import unittest
+from zope.testing import doctest
+
+from zope.testing.doctestunit import DocFileSuite, DocTestSuite
+import os
+
+here = os.path.dirname(__file__)
+
+def test_suite():
+ return unittest.TestSuite(
+ (
+ DocFileSuite('zcml.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/testview.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/testview.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/testview.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,12 @@
+
+class res1(object):
+ def __call__(self):
+ return "test resource #1"
+
+class res2(object):
+ def __call__(self):
+ return "test resource #2"
+
+class res3(object):
+ def __call__(self):
+ return "test resource #3"
\ No newline at end of file
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/utility.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/utility.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/utility.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+
+import sha
+import zope.component
+
+from zope import interface
+
+from interfaces import ICollectorUtility
+
+class Content(object):
+ interface.implements(interface.Interface)
+ pass
+
+class CollectorUtility(object):
+ """utility"""
+ interface.implements(ICollectorUtility)
+
+ def __init__(self,content_type):
+ self.resources = {}
+ self.content_type = content_type
+
+ def getUrl(self,context,request):
+ filetoreturn = self.getResources(request)
+ x = sha.new()
+ x.update(filetoreturn)
+ return x.hexdigest()
+
+ def getResources(self, request):
+ filetoreturn = ""
+ reducedrs = self.resources.values()
+ orderedrs = sorted(reducedrs, cmp=lambda a,b: cmp (a['weight'],b['weight']))
+ for resource in orderedrs:
+ res = zope.component.getAdapter(request,name=resource['resource'])
+ res.__name__ = resource['resource']
+ filetoreturn += res.browserDefault(request)[0]() + "\n"
+ return filetoreturn
+
+
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/z3c.resourcecollector-meta.zcml
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/z3c.resourcecollector-meta.zcml (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/z3c.resourcecollector-meta.zcml 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1 @@
+<include package="z3c.resourcecollector" file="meta.zcml"/>
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.py
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.py (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.py 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+
+import zope.interface
+import zope.configuration.fields
+import zope.component
+import zope.schema
+
+from zope.app import zapi
+from zope.app.publisher.browser import metaconfigure
+
+from interfaces import ICollectorUtility
+from browser import CollectorResource
+from utility import CollectorUtility
+
+
+class ICollectorDirective(zope.interface.Interface):
+
+ name = zope.schema.TextLine(
+ title=u"The name of the resource library",
+ description=u"""\
+ This is the name used to disambiguate resource libraries. No two
+ libraries can be active with the same name.""",
+ required=True,
+ )
+
+ type = zope.configuration.fields.GlobalInterface(
+ title=u"Request type",
+ required=True
+ )
+
+ content_type = zope.schema.TextLine(
+ title=u"Content type",
+ required=False
+ )
+
+
+def handleCollector(_context, name, type, content_type = None):
+
+ zapi.getGlobalSiteManager().registerUtility(CollectorUtility(content_type),name=name)
+ class_=CollectorResource
+ for_ = (zope.interface.Interface,)
+ provides = zope.interface.Interface
+
+ metaconfigure.resource(_context, name, layer=type, factory=class_,)
+
+
+class ICollectorItemDirective(zope.interface.Interface):
+ collector = zope.schema.TextLine(
+ title=u"The name of the resource library",
+ description=u"""\
+ The name of the resourcelibrary where we want to add our resources""",
+ required=True,
+ )
+
+ item = zope.schema.TextLine(
+ title=u"The resource to add to the resource library",
+ description=u"""\
+ The resource""",
+ required=True,
+ )
+
+ weight = zope.schema.Int(
+ title=u"The position of the resource in the library",
+ description=u"""\
+ The position of the resource in the library""",
+ required=True,
+ )
+
+def handleCollectorItem(_context, collector, item, weight):
+
+ rs = zope.component.getUtility(ICollectorUtility, collector)
+ resource = {}
+ resource['weight']=weight
+ resource['resource']=item
+ rs.resources[item]=resource
Added: z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.txt
===================================================================
--- z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.txt (rev 0)
+++ z3c.resourcecollector/trunk/src/z3c/resourcecollector/zcml.txt 2008-01-23 21:41:28 UTC (rev 83126)
@@ -0,0 +1,152 @@
+===================================
+``z3c.resourcecollector`` Directive
+===================================
+
+This package provides a new directive to use the special resource
+directive. You can merge with it more .js or .css files into one.
+Beware, you have to check before if your files are compatible.
+There are 2 zcml directives: collector and collectorItem.
+Also 2 viewlets are defined what returns the html code for inserting
+the js resource or the css resource: JSCollectorViewlet, CSSCollectorViewlet.
+For versioning the urls for the resources also contains a hash code
+calculated from the files. This helps at caching the resources.
+
+First we need to define a fake absolute URL for testing:
+
+ >>> from zope.configuration import xmlconfig
+ >>> context = xmlconfig.string('''
+ ... <configure i18n_domain="zope">
+ ... <include package="z3c.resourcecollector" file="meta.zcml" />
+ ... </configure>
+ ... ''')
+
+ >>> from zope.traversing.browser.interfaces import IAbsoluteURL
+ >>> from zope import interface, component
+ >>> from zope.publisher.interfaces.browser import IBrowserRequest
+ >>> class FakeAbsoluteURL(object):
+ ... interface.implements(IAbsoluteURL)
+ ... component.adapts(interface.Interface, IBrowserRequest)
+ ... def __init__ (self, context, request):
+ ... pass
+ ... def __str__ (self):
+ ... return 'homeofsite'
+ >>> component.provideAdapter(FakeAbsoluteURL)
+
+Now in the zcml we can define a collector. We will add our files to this
+collector.
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns="http://namespaces.zope.org/browser">
+ ... <include package="z3c.resourcecollector" file="meta.zcml" />
+ ... <collector
+ ... name="test.js"
+ ... type="zope.publisher.interfaces.browser.IBrowserRequest"
+ ... />
+ ... </configure>''')
+
+Using getUtility we check if the collectorUtility was created:
+
+ >>> import zope.component
+ >>> from z3c.resourcecollector.interfaces import ICollectorUtility
+ >>> rs = zope.component.getUtility(ICollectorUtility, "test.js")
+ >>> rs
+ <z3c.resourcecollector.utility.CollectorUtility ...>
+
+With getAdapter, we check if the collector was registered.
+
+ >>> from zope import interface
+ >>> class Content(object):
+ ... interface.implements(interface.Interface)
+ ... pass
+ >>> content = Content()
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> jsview = zope.component.getAdapter(request,name="test.js")
+ >>> jsview.__name__ = 'test.js'
+ >>> jsview
+ <z3c.resourcecollector.browser.CollectorResource object at ...>
+
+For testing we define a fake resource type, then we create 3 fake resources.
+
+ >>> from zope.publisher.interfaces.browser import IBrowserRequest
+ >>> class FakeResource(object):
+ ... interface.implements(interface.Interface)
+ ... def browserDefault(self, request):
+ ... return getattr(self, '__call__'), ()
+ ... def __init__(self, request):
+ ... pass
+ ... def __call__(self):
+ ... return self.__name__
+ >>> zope.component.provideAdapter(FakeResource,(IBrowserRequest,),name="res_test1.js")
+ >>> zope.component.provideAdapter(FakeResource,(IBrowserRequest,),name="res_test2.js")
+ >>> zope.component.provideAdapter(FakeResource,(IBrowserRequest,),name="res_test3.js")
+
+ >>> firstresource = zope.component.getAdapter(request,name="res_test1.js")
+ >>> firstresource.__name__ = "res_test1.js"
+ >>> secondresource = zope.component.getAdapter(request,name="res_test2.js")
+ >>> secondresource.__name__ = "res_test2.js"
+ >>> thirdresource = zope.component.getAdapter(request,name="res_test1.js")
+ >>> thirdresource.__name__ = "res_test3.js"
+ >>> firstresource()
+ 'res_test1.js'
+
+Using the collectorItem directive we add 2 resources to a collector
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns="http://namespaces.zope.org/browser">
+ ... <include package="z3c.resourcecollector" file="meta.zcml" />
+ ... <collectorItem
+ ... collector="test.js"
+ ... item="res_test1.js"
+ ... weight="1"
+ ... />
+ ... <collectorItem
+ ... collector="test.js"
+ ... item="res_test2.js"
+ ... weight="2"
+ ... />
+ ... </configure>''')
+
+With getAdapter we find our collector, and check if it returns the merged resources
+
+ >>> resourcecollector = zope.component.getAdapter(request,name="test.js")
+ >>> resourcecollector.__name__ = "test.js"
+ >>> resourcecollector.GET()
+ u'res_test1.js\nres_test2.js\n'
+
+Check if I can add my resourcecollector to another collector.
+First create a new collector:
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns="http://namespaces.zope.org/browser">
+ ... <include package="z3c.resourcecollector" file="meta.zcml" />
+ ... <collector
+ ... name="bigtest.js"
+ ... type="zope.publisher.interfaces.browser.IBrowserRequest"
+ ... />
+ ... </configure>''')
+
+Add to this collector our previous collector, and another resource:
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns="http://namespaces.zope.org/browser">
+ ... <include package="z3c.resourcecollector" file="meta.zcml" />
+ ... <collectorItem
+ ... collector="bigtest.js"
+ ... item="test.js"
+ ... weight="2"
+ ... />
+ ... <collectorItem
+ ... collector="bigtest.js"
+ ... item="res_test3.js"
+ ... weight="1"
+ ... />
+ ... </configure>''')
+
+With getAdapter we find our new resource collector and check if it contains all
+the resources what we added to it.
+
+ >>> resourcecollector2 = zope.component.getAdapter(request,name="bigtest.js")
+ >>> resourcecollector2.__name__ = "bigtest.js"
+ >>> resourcecollector2.GET()
+ u'res_test3.js\nres_test1.js\nres_test2.js\n\n'
\ No newline at end of file
More information about the Checkins
mailing list