[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser - IconDirective.py:1.2 meta.zcml:1.6
Marius Gedminas
mgedmin@delfi.lt
Tue, 25 Jun 2002 11:26:12 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv1528/lib/python/Zope/App/Publisher/Browser
Modified Files:
IconDirective.py meta.zcml
Log Message:
<browser:icon> now accepts resource as well as file attributes (e.g. you can
refer to a i18n-resource to have internationalized icons).
=== Zope3/lib/python/Zope/App/Publisher/Browser/IconDirective.py 1.1 => 1.2 ===
from Zope.Configuration.Action import Action
from Zope.ComponentArchitecture import getResource
-from Zope.App.Publisher.Browser.metaConfigure import resource
+from Zope.App.Publisher.Browser import metaConfigure
from Zope.App.Traversing.GetResource import getResource
from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.Configuration.Exceptions import ConfigurationError
IName = re.compile('I[A-Z][a-z]')
@@ -51,34 +52,44 @@
def __call__(self, context, request):
return IconView(context, request, self.rname, self.alt)
-def IconDirective(_context, name, for_, file, layer='default',
- alt=None):
+def IconDirective(_context, name, for_, file=None, resource=None,
+ layer='default', alt=None):
for_ = _context.resolve(for_)
iname = for_.__name__
if alt is None:
- alt = iname
+ alt = iname
if IName.match(alt):
alt = alt[1:] # Remove leading 'I'
- rname = '-'.join(for_.__module__.split('.'))
- rname = "%s-%s-%s" % (rname, iname, name)
+ results = []
+ if file is not None and resource is not None:
+ raise ConfigurationError(
+ "Can't use more than one of file, and resource "
+ "attributes for icon directives"
+ )
+ elif file is not None:
+ resource = '-'.join(for_.__module__.split('.'))
+ resource = "%s-%s-%s" % (resource, iname, name)
+ ext = os.path.splitext(file)[1]
+ if ext:
+ resource += ext
+ results = metaConfigure.resource(_context, image=file,
+ name=resource, layer=layer)()
+ elif resource is None:
+ raise ConfigurationError(
+ "At least one of the file, and resource "
+ "attributes for resource directives must be specified"
+ )
- ext = os.path.splitext(file)[1]
- if ext:
- rname += ext
-
- vfactory = IconViewFactory(rname, alt)
+ vfactory = IconViewFactory(resource, alt)
- return resource(_context, image=file, name=rname, layer=layer)() + [
+ return results + [
Action(
discriminator = ('view', name, vfactory, layer),
callable = handler,
args = ('Views', 'provideView',
for_, name, IBrowserPresentation,
- vfactory, layer)),
-
+ vfactory, layer))
]
-
-
=== Zope3/lib/python/Zope/App/Publisher/Browser/meta.zcml 1.5 => 1.6 ===
/>
- <directive name="icon" attributes="name for file image alt layer"
+ <directive name="icon" attributes="name for file resource alt layer"
handler="Zope.App.Publisher.Browser.IconDirective." />
</directives>