[Checkins] SVN: z3c.zrtresource/trunk/ Register ZRTFileResourceFactory class as a named IResourceFactoryFactory utility, so ZRT resources will be automatically created for *.zrt files.
Dan Korostelev
nadako at gmail.com
Thu Aug 27 12:19:24 EDT 2009
Log message for revision 103302:
Register ZRTFileResourceFactory class as a named IResourceFactoryFactory utility, so ZRT resources will be automatically created for *.zrt files.
Changed:
U z3c.zrtresource/trunk/CHANGES.txt
A z3c.zrtresource/trunk/src/z3c/zrtresource/configure.zcml
U z3c.zrtresource/trunk/src/z3c/zrtresource/zcml.txt
-=-
Modified: z3c.zrtresource/trunk/CHANGES.txt
===================================================================
--- z3c.zrtresource/trunk/CHANGES.txt 2009-08-27 16:16:26 UTC (rev 103301)
+++ z3c.zrtresource/trunk/CHANGES.txt 2009-08-27 16:19:24 UTC (rev 103302)
@@ -8,6 +8,11 @@
- Use new ``zope.browserresource`` package instead of ``zope.app.publisher``,
as the resources mechanism was moved there to reduce dependencies.
+- Register ZRTFileResourceFactory as a resource factory with name "zrt" in
+ package's configure.zcml. This makes ZRT resources created automatically
+ when using ``browser:resource`` directive for files with "zrt" extensions.
+ It will also make *.zrt files inside resourse directories a ZRTFileResource.
+
- Get rid of ``zope.app.testing`` test dependency.
- Remove unused SETUP.CFG and z3c.zrtresource-meta.zcml files.
Added: z3c.zrtresource/trunk/src/z3c/zrtresource/configure.zcml
===================================================================
--- z3c.zrtresource/trunk/src/z3c/zrtresource/configure.zcml (rev 0)
+++ z3c.zrtresource/trunk/src/z3c/zrtresource/configure.zcml 2009-08-27 16:19:24 UTC (rev 103302)
@@ -0,0 +1,9 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <utility
+ name="zrt"
+ component=".zrtresource.ZRTFileResourceFactory"
+ provides="zope.browserresource.interfaces.IResourceFactoryFactory"
+ />
+
+</configure>
Property changes on: z3c.zrtresource/trunk/src/z3c/zrtresource/configure.zcml
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: z3c.zrtresource/trunk/src/z3c/zrtresource/zcml.txt
===================================================================
--- z3c.zrtresource/trunk/src/z3c/zrtresource/zcml.txt 2009-08-27 16:16:26 UTC (rev 103301)
+++ z3c.zrtresource/trunk/src/z3c/zrtresource/zcml.txt 2009-08-27 16:19:24 UTC (rev 103302)
@@ -47,3 +47,54 @@
color: red;
background: url('++resource++/img/mybackground.gif');
}
+
+We can also register a ZRT resource using standard ``browser:resource`` directive.
+The ``configure.zcml`` file in this package registers a ZRT resource factory for
+files with "zrt" extension, so any file with "zrt" extension will be a ZRT
+resource.
+
+First, let's include the ``browser:resource`` directive and the resource factory
+registration:
+
+ >>> context = xmlconfig.string('''
+ ... <configure i18n_domain="zope">
+ ... <include package="zope.browserresource" file="meta.zcml" />
+ ... <include package="zope.component" file="meta.zcml" />
+ ... <include package="z3c.zrtresource" />
+ ... </configure>
+ ... ''')
+
+Now we need to create a file with "zrt" extension:
+
+ >>> fn = tempfile.mktemp('.zrt')
+ >>> open(fn, 'w').write('''\
+ ... /* zrt-replace: "../img1" "++resource++/img" */
+ ... h1 {
+ ... color: red;
+ ... background: url('../img1/mybackground.gif');
+ ... }
+ ... ''')
+
+And register it as a resource using browser:resource directive.
+
+ >>> context = xmlconfig.string('''
+ ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope">
+ ... <resource
+ ... name="test2.css"
+ ... file="%s" />
+ ... </configure>
+ ... ''' %fn, context=context)
+
+Let's see whether the adapter has been registered:
+
+ >>> resource2 = zope.component.getAdapter(
+ ... TestRequest(), zope.interface.Interface, name='test2.css')
+
+Now, let's render it and check if ZRT mechanism works for it.
+
+ >>> print resource2.GET()
+ h1 {
+ color: red;
+ background: url('++resource++/img/mybackground.gif');
+ }
+
\ No newline at end of file
More information about the Checkins
mailing list