[Checkins] SVN: zc.resourcelibrary/trunk/ Fix generation of dependencies to allow resourceLibrary directives containing only dependencies on other resource libraries (this worked prior to 1.1.0)
Patrick Strawderman
patrick at zope.com
Mon Aug 16 15:46:46 EDT 2010
Log message for revision 115712:
Fix generation of dependencies to allow resourceLibrary directives containing only dependencies on other resource libraries (this worked prior to 1.1.0)
Changed:
U zc.resourcelibrary/trunk/CHANGES.txt
U zc.resourcelibrary/trunk/setup.py
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/configure.zcml
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/ftesting.zcml
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/test_unit.py
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py
U zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py
-=-
Modified: zc.resourcelibrary/trunk/CHANGES.txt
===================================================================
--- zc.resourcelibrary/trunk/CHANGES.txt 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/CHANGES.txt 2010-08-16 19:46:45 UTC (rev 115712)
@@ -5,9 +5,16 @@
1.3.2 (unreleased)
------------------
-- Nothing changed yet.
+- 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.3.1 (2010-03-24)
------------------
@@ -85,7 +92,7 @@
Bugs fixed:
-- Updated the functional-testing zcml file to get rid of a deprication
+- Updated the functional-testing zcml file to get rid of a deprecation
warning.
Modified: zc.resourcelibrary/trunk/setup.py
===================================================================
--- zc.resourcelibrary/trunk/setup.py 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/setup.py 2010-08-16 19:46:45 UTC (rev 115712)
@@ -60,6 +60,7 @@
'zope.testing',
]),
install_requires=['setuptools',
+ 'zope.app.pagetemplate',
'zope.app.publication',
'zope.browserresource',
'zope.component',
Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt 2010-08-16 19:46:45 UTC (rev 115712)
@@ -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/trunk/src/zc/resourcelibrary/configure.zcml
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/configure.zcml 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/configure.zcml 2010-08-16 19:46:45 UTC (rev 115712)
@@ -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/trunk/src/zc/resourcelibrary/publication.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py 2010-08-16 19:46:45 UTC (rev 115712)
@@ -16,8 +16,7 @@
"""
from zope import interface
from zope.app.publication.interfaces import IBrowserRequestFactory
-from zope.browserresource.resource import Resource
-from zope.component import queryMultiAdapter, getMultiAdapter, getSiteManager
+from zope.component import queryMultiAdapter, getMultiAdapter
from zope.publisher.browser import BrowserRequest, BrowserResponse
from zope.publisher.browser import isHTML
from zope.publisher.interfaces.browser import IBrowserPublisher
@@ -51,7 +50,7 @@
False
>>> request.resource_libraries is retry_request.resource_libraries
True
-
+
The assigned libraries are flushed because a new request will define
its own set of required librarires.
@@ -142,7 +141,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:
@@ -177,7 +176,7 @@
'include this file: "%s"' % file_name)
return '\n '.join(html)
-
+
def _addDependencies(self, resource_libraries):
result = []
def add_lib(lib):
@@ -189,7 +188,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/trunk/src/zc/resourcelibrary/tests/ftesting.zcml
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/ftesting.zcml 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/ftesting.zcml 2010-08-16 19:46:45 UTC (rev 115712)
@@ -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>
Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/test_unit.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/test_unit.py 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/test_unit.py 2010-08-16 19:46:45 UTC (rev 115712)
@@ -10,19 +10,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):
@@ -51,6 +57,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/trunk/src/zc/resourcelibrary/tests/tests.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py 2010-08-16 19:46:45 UTC (rev 115712)
@@ -22,7 +22,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
@@ -44,7 +43,7 @@
def __getitem__(self, name):
return lambda: "http://localhost/@@/%s/%s" % (self.name, name)
-
+
def publishTraverse(self, request, name):
return getattr(self, name.replace('.', '_'))
@@ -107,7 +106,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/trunk/src/zc/resourcelibrary/zcml.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py 2010-08-16 18:43:17 UTC (rev 115711)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/zcml.py 2010-08-16 19:46:45 UTC (rev 115712)
@@ -84,7 +84,7 @@
factory, required, provided, adapter_name, info)
-INCLUDABLE_EXTENTIONS = ('.js', '.css', '.kss')
+INCLUDABLE_EXTENSIONS = ('.js', '.css', '.kss')
class ResourceLibrary(object):
@@ -107,7 +107,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