[Checkins] SVN: Sandbox/cklinger/megrok.resource/trunk/ all kind of deps work
Christian Klinger
cklinger at novareto.de
Fri Oct 30 06:57:24 EDT 2009
Log message for revision 105386:
all kind of deps work
Changed:
U Sandbox/cklinger/megrok.resource/trunk/buildout.cfg
U Sandbox/cklinger/megrok.resource/trunk/setup.py
U Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/components.py
U Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/event.py
A Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_depends.py
-=-
Modified: Sandbox/cklinger/megrok.resource/trunk/buildout.cfg
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/buildout.cfg 2009-10-30 09:16:44 UTC (rev 105385)
+++ Sandbox/cklinger/megrok.resource/trunk/buildout.cfg 2009-10-30 10:57:23 UTC (rev 105386)
@@ -7,7 +7,7 @@
[test]
recipe = zc.recipe.testrunner
-eggs = megrok.resource
+eggs = megrok.resource [test]
defaults = ['--tests-pattern', '^f?tests$', '-v', '-c']
[omelette]
Modified: Sandbox/cklinger/megrok.resource/trunk/setup.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/setup.py 2009-10-30 09:16:44 UTC (rev 105385)
+++ Sandbox/cklinger/megrok.resource/trunk/setup.py 2009-10-30 10:57:23 UTC (rev 105386)
@@ -3,6 +3,8 @@
version = '0.1'
+
+
setup(name='megrok.resource',
version=version,
description="Grok Resources based on hurry.resource",
@@ -30,6 +32,7 @@
'hurry.zoperesource',
# -*- Extra requirements: -*-
],
+ extras_require={'test': ['hurry.jquery',],},
entry_points="""
# -*- Entry points: -*-
""",
Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/components.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/components.py 2009-10-30 09:16:44 UTC (rev 105385)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/components.py 2009-10-30 10:57:23 UTC (rev 105386)
@@ -34,6 +34,9 @@
@classmethod
def get_resources(cls, name=None):
+ """ cls._resources is a dict with the name of the inclusion as key
+ and the instance of a ResourceInclusion as value
+ """
if cls._resources == None:
cls._ri_keys, values = inclusions(cls)
cls._resources = dict(zip(cls._ri_keys, values))
@@ -41,6 +44,9 @@
return [cls._resources[name],]
return [cls._resources[name] for name in cls._ri_keys]
+ @classmethod
+ def get(cls, value):
+ return cls.get_resources(value)[0]
@grok.adapter(Library)
@grok.implementer(ILibraryUrl)
Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/event.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/event.py 2009-10-30 09:16:44 UTC (rev 105385)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/event.py 2009-10-30 10:57:23 UTC (rev 105386)
@@ -7,6 +7,7 @@
from zope.app.publication.interfaces import IBeforeTraverseEvent
from zope.security.proxy import removeSecurityProxy
from megrok.resource import include
+from hurry.resource import ResourceInclusion
@grok.subscribe(view.View, IBeforeTraverseEvent)
@@ -18,9 +19,12 @@
if bottom:
with_bottom=True
- resources = lib.get_resources(name=name)
- for resource in resources:
- resource.need()
+ if isinstance(lib, ResourceInclusion):
+ lib.need()
+ else:
+ resources = lib.get_resources(name=name)
+ for resource in resources:
+ resource.need()
if with_bottom:
hurry.resource.bottom()
Copied: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_depends.py (from rev 105385, Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_inclusion.py)
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_depends.py (rev 0)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_depends.py 2009-10-30 10:57:23 UTC (rev 105386)
@@ -0,0 +1,134 @@
+"""
+megrok.resource
+===============
+
+Setup
+-----
+
+ >>> from zope.app.testing.functional import getRootFolder
+ >>> from zope.app.container import btree
+ >>> from zope.app.component.site import LocalSiteManager
+ >>> from zope.app.component.hooks import setSite
+
+ >>> root = getRootFolder()
+ >>> root['newapp'] = Application()
+
+Our application has to be a Site to access the right url for the inclusions
+
+ >>> root['newapp'].setSiteManager(LocalSiteManager(root['newapp']))
+ >>> setSite(root['newapp'])
+ >>> root['newapp']
+ <megrok.resource.ftests.test_depends.Application object at ...>
+
+
+Inclusion with dependency from a megrok.resource Library
+--------------------------------------------------------
+
+Now let's look if we can include the a.js File in a
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open('http://localhost/newapp/depends')
+ >>> print browser.contents
+ <html>
+ <head>
+ <script type="text/javascript" src="http://localhost/newapp/@@/basestyles/a.js"></script>
+ <script type="text/javascript" src="http://localhost/newapp/@@/newstyles/b.js"></script>
+ </head>
+ <body>
+ <h1> HI GROK </h1>
+ </body>
+ </html>
+
+
+Inclusion with a dependency from a hurry.core package
+here we use hurry.jquery
+
+ >>> browser.open('http://localhost/newapp/withjquery')
+ >>> print browser.contents
+ <html>
+ <head>
+ <script type="text/javascript" src="http://localhost/newapp/@@/jquery/jquery-1.3.2.js"></script>
+ <script type="text/javascript" src="http://localhost/newapp/@@/newstyles/b.js"></script>
+ </head>
+ <body>
+ <h1> HI GROK </h1>
+ </body>
+ </html>
+
+Here we include only hurry.jquery with no inclusion from megrok.resource.
+
+ >>> browser.open('http://localhost/newapp/onlyjquery')
+ >>> print browser.contents
+ <html>
+ <head>
+ <script type="text/javascript" src="http://localhost/newapp/@@/jquery/jquery-1.3.2.js"></script>
+ </head>
+ <body>
+ <h1> HI GROK </h1>
+ </body>
+ </html>
+"""
+
+
+import grokcore.component as grok
+import grokcore.view as view
+
+from zope.interface import Interface
+from megrok.resource import Library, include, inclusion
+from hurry.resource import ResourceInclusion
+
+from zope.app.container import btree
+
+from zope.app.component.site import SiteManagerContainer
+from hurry.jquery import jquery
+
+
+class Application(SiteManagerContainer):
+ """ Sample Application """
+
+
+class BaseStyles(Library):
+ view.path('css')
+ grok.name('basestyles')
+
+ inclusion(name='JSBase', file='a.js')
+
+
+class NewStyles(Library):
+ view.path('css')
+ grok.name('newstyles')
+
+ inclusion(name='JSMore', file='b.js', depends=[BaseStyles.get('JSBase'),])
+ inclusion(name='With_hurryjquery', file='b.js', depends=[jquery,])
+
+
+class Depends(view.View):
+ grok.context(Interface)
+ include(NewStyles, 'JSMore')
+ template = view.PageTemplateFile('templates/myview.pt')
+
+
+class WithJquery(view.View):
+ grok.context(Interface)
+ include(NewStyles, 'With_hurryjquery')
+ template = view.PageTemplateFile('templates/myview.pt')
+
+
+class OnlyJquery(view.View):
+ grok.context(Interface)
+ include(jquery)
+ template = view.PageTemplateFile('templates/myview.pt')
+
+
+###TestSetup
+def test_suite():
+ from zope.testing import doctest
+ from megrok.resource.ftests import FunctionalLayer
+ suite = doctest.DocTestSuite(
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
+ )
+ suite.layer = FunctionalLayer
+ return suite
+
More information about the checkins
mailing list