[Checkins] SVN: zc.resourcelibrary/branches/1.2/ Backport 1.3.2 fixes
Patrick Strawderman
patrick at zope.com
Mon Aug 16 16:20:51 EDT 2010
Log message for revision 115718:
Backport 1.3.2 fixes
Changed:
U zc.resourcelibrary/branches/1.2/CHANGES.txt
U zc.resourcelibrary/branches/1.2/buildout.cfg
U zc.resourcelibrary/branches/1.2/setup.py
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/README.txt
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/configure.zcml
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/publication.py
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/ftesting.zcml
A zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_template_7.pt
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_unit.py
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/tests.py
U zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/zcml.py
-=-
Modified: zc.resourcelibrary/branches/1.2/CHANGES.txt
===================================================================
--- zc.resourcelibrary/branches/1.2/CHANGES.txt 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/CHANGES.txt 2010-08-16 20:20:50 UTC (rev 115718)
@@ -2,6 +2,21 @@
CHANGES
=======
+1.2.1 (2010-08-16)
+------------------
+
+The following changes were backported from the 1.3.2:
+
+- Response._addDependencies will only include a ResourceLibrary in the
+ list of dependencies if the ResourceLibrary actually has included
+ resources.
+
+ This makes directives that simply declare dependencies on other
+ libraries work again.
+
+- Add missing depedency on zope.app.pagetemplate, clean up unused
+ imports and whitespace.
+
1.2.0 (2009-06-04)
------------------
Modified: zc.resourcelibrary/branches/1.2/buildout.cfg
===================================================================
--- zc.resourcelibrary/branches/1.2/buildout.cfg 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/buildout.cfg 2010-08-16 20:20:50 UTC (rev 115718)
@@ -2,6 +2,11 @@
develop = .
parts = test
+versions = versions
+
[test]
recipe = zc.recipe.testrunner
eggs = zc.resourcelibrary [test]
+
+[versions]
+zope.app.securitypolicy = 3.5.1
Modified: zc.resourcelibrary/branches/1.2/setup.py
===================================================================
--- zc.resourcelibrary/branches/1.2/setup.py 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/setup.py 2010-08-16 20:20:50 UTC (rev 115718)
@@ -22,7 +22,7 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='zc.resourcelibrary',
- version = '1.2.0',
+ version = '1.2.1dev',
author='Zope Corporation and Contributors',
author_email='zope-dev at zope.org',
description='Post-rendering Resource Inclusion',
@@ -60,6 +60,7 @@
'zope.testing',
]),
install_requires=['setuptools',
+ 'zope.app.pagetemplate',
'zope.app.publication',
'zope.app.publisher',
'zope.component',
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/README.txt
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/README.txt 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/README.txt 2010-08-16 20:20:50 UTC (rev 115718)
@@ -288,6 +288,35 @@
>>> print browser.contents.strip()
<html>...dependency/2.css...dependent/1.js...</html>
+It is possible for a resource library to only register a list of dependencies
+and not specify any resources.
+
+When such a library is used in a resource_library statement in a template,
+only its dependencies are referenced in the final rendered page.
+
+ >>> zcml("""
+ ... <configure
+ ... xmlns="http://namespaces.zope.org/zope"
+ ... package="zc.resourcelibrary">
+ ...
+ ... <resourceLibrary name="only_require" require="my-lib dependent"/>
+ ...
+ ... </configure>
+ ... """)
+ >>> zpt('<tal:block replace="resource_library:only_require"/>')
+ >>> browser.open('http://localhost/zc.resourcelibrary.test_template_7')
+ >>> '/@@/my-lib/included.js' in browser.contents
+ True
+ >>> '/@@/my-lib/included.css' in browser.contents
+ True
+ >>> '/@@/dependent/1.js' in browser.contents
+ True
+ >>> '/@@/dependency/2.css' in browser.contents
+ True
+ >>> '/@@/only_require' in browser.contents
+ False
+
+
Error Conditions
----------------
@@ -327,7 +356,7 @@
Error during publishing
-----------------------
-
+
Note that in case an exception is raised during publishing, the
resource library is disabled.
@@ -396,7 +425,7 @@
<title>Marker test</title>
<BLANKLINE>
<!-- Libraries will be included below -->
- <script src="http://localhost/@@/my-lib/foo.js"
+ <script src="http://localhost/@@/my-lib/foo.js"
type="text/javascript">
</script>
</head>
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/configure.zcml
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/configure.zcml 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/configure.zcml 2010-08-16 20:20:50 UTC (rev 115718)
@@ -4,6 +4,10 @@
i18n_domain="zc.resourcelibrary"
>
+ <include package="zope.component" file="meta.zcml"/>
+ <include package="zope.security" file="meta.zcml"/>
+ <include package="zope.app.pagetemplate" file="meta.zcml"/>
+
<tales:expressiontype
name="resource_library"
handler=".tal.ResourceLibraryExpression"
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/publication.py
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/publication.py 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/publication.py 2010-08-16 20:20:50 UTC (rev 115718)
@@ -16,7 +16,6 @@
"""
from zope import interface
from zope.app.publication.interfaces import IBrowserRequestFactory
-from zope.app.publisher.browser.resource import Resource
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.browser import BrowserRequest, BrowserResponse
from zope.publisher.browser import isHTML
@@ -105,7 +104,7 @@
site = getSite()
if site is None:
return
-
+
# look up resources view factory
factory = getSiteManager().adapters.lookup(
(ISite, interface.providedBy(self._request)),
@@ -120,7 +119,7 @@
resources = None
base = queryMultiAdapter(
(site, self._request), IAbsoluteURL, name="resource")
- if base is None:
+ if base is None:
baseURL = str(getMultiAdapter(
(site, self._request), IAbsoluteURL))
else:
@@ -155,7 +154,7 @@
'include this file: "%s"' % file_name)
return '\n '.join(html)
-
+
def _addDependencies(self, resource_libraries):
result = []
def add_lib(lib):
@@ -167,7 +166,8 @@
raise RuntimeError('Unknown resource library: "%s"' % lib)
for other in required:
add_lib(other)
- result.append(lib)
+ if zc.resourcelibrary.getIncluded(lib):
+ result.append(lib)
for lib in resource_libraries:
add_lib(lib)
return result
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/ftesting.zcml
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/ftesting.zcml 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/ftesting.zcml 2010-08-16 20:20:50 UTC (rev 115718)
@@ -77,4 +77,11 @@
template="test_template_6.pt"
/>
+ <browser:page
+ for="zope.app.folder.interfaces.IFolder"
+ name="zc.resourcelibrary.test_template_7"
+ permission="zope.View"
+ template="test_template_7.pt"
+ />
+
</configure>
Added: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_template_7.pt
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_template_7.pt (rev 0)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_template_7.pt 2010-08-16 20:20:50 UTC (rev 115718)
@@ -0,0 +1,6 @@
+<html>
+ <head></head>
+ <body>
+ <tal:block replace="structure resource_library:only_require"/>
+ </body>
+</html>
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_unit.py
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_unit.py 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/test_unit.py 2010-08-16 20:20:50 UTC (rev 115718)
@@ -11,19 +11,25 @@
resourcelibrary.library_info = library_info = {}
# Dependencies:
#
+ # libE
+ # /
# libA libD
# \ /
# libB /
# \/
# libC
- #
- library_info['libA'] = LibraryInfo()
- library_info['libA'].required.append('libB')
- library_info['libB'] = LibraryInfo()
- library_info['libB'].required.append('libC')
- library_info['libC'] = LibraryInfo()
- library_info['libD'] = LibraryInfo()
- library_info['libD'].required.append('libC')
+ def lib_info(included=None, required=None):
+ res = LibraryInfo()
+ if included:
+ res.included.append(included)
+ if required:
+ res.required.append(required)
+ return res
+ library_info['libA'] = lib_info('foo.js', 'libB')
+ library_info['libB'] = lib_info('bar.js', 'libC')
+ library_info['libC'] = lib_info('baz.js')
+ library_info['libD'] = lib_info('foo.css', 'libC')
+ library_info['libE'] = lib_info(required='libD')
def tearDown(test):
@@ -52,6 +58,12 @@
>>> r._addDependencies(['libC', 'libA', 'libD', 'libA'])
['libC', 'libB', 'libA', 'libD']
+ If a library doesn't contain any included resources, only its
+ required libraries will be included in its list of dependencies.
+
+ >>> r._addDependencies(['libE'])
+ ['libC', 'libD']
+
Unknown library names cause errors
>>> r._addDependencies(['libA', 'libZ'])
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/tests.py
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/tests.py 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/tests/tests.py 2010-08-16 20:20:50 UTC (rev 115718)
@@ -24,7 +24,6 @@
import zope.interface
from zope.pagetemplate import pagetemplate
import zope.publisher.interfaces.browser
-from zope.testing import doctest
import doctest
import os
import unittest
@@ -45,7 +44,7 @@
def __getitem__(self, name):
return lambda: "http://localhost/@@/%s/%s" % (self.name, name)
-
+
def publishTraverse(self, request, name):
return getattr(self, name.replace('.', '_'))
@@ -108,7 +107,7 @@
"""
If a response body is not html, guess that it is text/plain. This
follows the behavior of zope.publication's trunk as of this writing.
-
+
>>> import zc.resourcelibrary.publication
>>> response = zc.resourcelibrary.publication.Response()
>>> response.setResult('')
Modified: zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/zcml.py
===================================================================
--- zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/zcml.py 2010-08-16 20:19:40 UTC (rev 115717)
+++ zc.resourcelibrary/branches/1.2/src/zc/resourcelibrary/zcml.py 2010-08-16 20:20:50 UTC (rev 115718)
@@ -81,7 +81,7 @@
factory, required, provided, adapter_name, info)
-INCLUDABLE_EXTENTIONS = ('.js', '.css', '.kss')
+INCLUDABLE_EXTENSIONS = ('.js', '.css', '.kss')
class ResourceLibrary(object):
@@ -104,7 +104,7 @@
for file_name in include:
ext = os.path.splitext(file_name)[1]
- if ext not in INCLUDABLE_EXTENTIONS:
+ if ext not in INCLUDABLE_EXTENSIONS:
raise ConfigurationError(
'Resource library doesn\'t know how to include this '
'file: "%s".' % file_name)
More information about the checkins
mailing list