Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Backport 1.3.2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kilink committed Aug 16, 2010
1 parent 0d37b42 commit 30c5306
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 21 deletions.
15 changes: 15 additions & 0 deletions CHANGES.txt
Expand Up @@ -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)
------------------

Expand Down
5 changes: 5 additions & 0 deletions buildout.cfg
Expand Up @@ -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
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -22,7 +22,7 @@ def read(*rnames):
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@zope.org',
description='Post-rendering Resource Inclusion',
Expand Down Expand Up @@ -60,6 +60,7 @@ def read(*rnames):
'zope.testing',
]),
install_requires=['setuptools',
'zope.app.pagetemplate',
'zope.app.publication',
'zope.app.publisher',
'zope.component',
Expand Down
33 changes: 31 additions & 2 deletions src/zc/resourcelibrary/README.txt
Expand Up @@ -288,6 +288,35 @@ appear before the dependent library in the page
>>> 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
----------------

Expand Down Expand Up @@ -327,7 +356,7 @@ occurrence of "<head>" has the script tag inserted...

Error during publishing
-----------------------

Note that in case an exception is raised during publishing, the
resource library is disabled.

Expand Down Expand Up @@ -396,7 +425,7 @@ A reference to the JavaScript is inserted into the HTML.
<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>
Expand Down
4 changes: 4 additions & 0 deletions src/zc/resourcelibrary/configure.zcml
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/zc/resourcelibrary/publication.py
Expand Up @@ -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
Expand Down Expand Up @@ -105,7 +104,7 @@ def _generateIncludes(self, libraries):
site = getSite()
if site is None:
return

# look up resources view factory
factory = getSiteManager().adapters.lookup(
(ISite, interface.providedBy(self._request)),
Expand All @@ -120,7 +119,7 @@ def _generateIncludes(self, libraries):
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:
Expand Down Expand Up @@ -155,7 +154,7 @@ def _generateIncludes(self, libraries):
'include this file: "%s"' % file_name)

return '\n '.join(html)

def _addDependencies(self, resource_libraries):
result = []
def add_lib(lib):
Expand All @@ -167,7 +166,8 @@ def add_lib(lib):
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
7 changes: 7 additions & 0 deletions src/zc/resourcelibrary/tests/ftesting.zcml
Expand Up @@ -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>
6 changes: 6 additions & 0 deletions src/zc/resourcelibrary/tests/test_template_7.pt
@@ -0,0 +1,6 @@
<html>
<head></head>
<body>
<tal:block replace="structure resource_library:only_require"/>
</body>
</html>
28 changes: 20 additions & 8 deletions src/zc/resourcelibrary/tests/test_unit.py
Expand Up @@ -11,19 +11,25 @@ def setUp(test):
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):
Expand Down Expand Up @@ -52,6 +58,12 @@ def doctest_dependency_resolution():
>>> 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'])
Expand Down
5 changes: 2 additions & 3 deletions src/zc/resourcelibrary/tests/tests.py
Expand Up @@ -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
Expand All @@ -45,7 +44,7 @@ def __call__(self, request):

def __getitem__(self, name):
return lambda: "http://localhost/@@/%s/%s" % (self.name, name)

def publishTraverse(self, request, name):
return getattr(self, name.replace('.', '_'))

Expand Down Expand Up @@ -108,7 +107,7 @@ def test_empty_body():
"""
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('')
Expand Down
4 changes: 2 additions & 2 deletions src/zc/resourcelibrary/zcml.py
Expand Up @@ -81,7 +81,7 @@ def handler(name, dependencies, required, provided, adapter_name, factory, info=
factory, required, provided, adapter_name, info)


INCLUDABLE_EXTENTIONS = ('.js', '.css', '.kss')
INCLUDABLE_EXTENSIONS = ('.js', '.css', '.kss')

class ResourceLibrary(object):

Expand All @@ -104,7 +104,7 @@ def directory(self, _context, source, include=(), factory=None):

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)
Expand Down

0 comments on commit 30c5306

Please sign in to comment.