Author: jmorliaguet Date: Sun May 14 20:15:30 2006 New Revision: 3132 Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt cpsskins/branches/paris-sprint-2006/setup/manager.py
Log: - resource URIs can be now also resolved Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt ============================================================================== --- cpsskins/branches/paris-sprint-2006/setup/README.txt (original) +++ cpsskins/branches/paris-sprint-2006/setup/README.txt Sun May 14 20:15:30 2006 @@ -456,32 +456,28 @@ >>> from cpsskins.relations.interfaces import IRelatable >>> from cpsskins.elements.interfaces import IElement - >>> class Relatable(object): - ... def __init__(self, element): - ... self.element = element - ... def __str__(self): - ... return '12345' - >>> gsm = zapi.getGlobalSiteManager() - >>> gsm.registerAdapter(Relatable, (IElement,), IRelatable) >>> resource = Style() - >>> unicode(IRelatable(resource)) - u'12345' + >>> root[u'style-1'] = resource + >>> unicode(IRelatable(resource)) == unicode(resource.identifier) + True For instance a portlet will be uniformally identified as: >>> resource = Actions() + >>> root[u'action-1'] = resource - >>> IIdentifiable(resource).getURI() - u'cpsskins://canvas-portlet-standard.actions:12345' + >>> print IIdentifiable(resource).getURI() + cpsskins://canvas-portlet-standard.actions:... If the resource type is the same as the content type, the name is written only once: >>> resource = Style() - >>> IIdentifiable(resource).getURI() - u'cpsskins://format-style:12345' + >>> root[u'style-2'] = resource + >>> print IIdentifiable(resource).getURI() + cpsskins://format-style:... Export of resources @@ -527,11 +523,11 @@ >>> print toXML(resource, u'styles') <?xml version="1.0" encoding="utf-8"?> <styles> - <style id="12345"> - <selector value="div.body"> + <style id="..."> + <rule selector="div.body"> <property name="color" value="red"/> <property name="border" value="none"/> - </selector> + </rule> </style> </styles> <BLANKLINE> @@ -550,7 +546,7 @@ <?xml version="1.0" encoding="utf-8"?> <relations> <monad predicate="_ A"> - <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> </monad> </relations> <BLANKLINE> @@ -569,8 +565,8 @@ <?xml version="1.0" encoding="utf-8"?> <relations> <dyad predicate="_ B _"> - <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/> - <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> + <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> </dyad> </relations> <BLANKLINE> @@ -590,8 +586,8 @@ <?xml version="1.0" encoding="utf-8"?> <relations> <triad predicate="_ C _ D _"> - <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/> - <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> + <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> <relate uri="cpsskins://canvas-slot:slotA"/> </triad> </relations> @@ -621,11 +617,11 @@ ... (u'slot',)) <?xml version="1.0" encoding="utf-8"?> <elements> - <pageblock id="12345" title="Some page block"> - <cell id="12345" title="Some cell 1"> + <pageblock id="..." title="Some page block"> + <cell id="..." title="Some cell 1"> <slot description="" id="slot1" title="Some slot"/> </cell> - <cell id="12345" title="Some cell 2"/> + <cell id="..." title="Some cell 2"/> </pageblock> </elements> <BLANKLINE> @@ -641,10 +637,10 @@ >>> print toXML(theme, u'themes', (u'title', ), (u'slot',)) <?xml version="1.0" encoding="utf-8"?> <themes> - <theme id="12345" title="A theme"> - <themepage id="12345" title="A page"> - <pageblock id="12345" title="A page block"> - <cell id="12345" title="A cell"/> + <theme id="..." title="A theme"> + <themepage id="..." title="A page"> + <pageblock id="..." title="A page block"> + <cell id="..." title="A cell"/> </pageblock> </themepage> </theme> @@ -659,7 +655,7 @@ >>> print toXML(portlet, u'portlets', (u'title', )) <?xml version="1.0" encoding="utf-8"?> <portlets> - <portlet id="12345" title="Action portlet" type="standard.actions"> + <portlet id="..." title="Action portlet" type="standard.actions"> <category value="zmi_views"/> </portlet> </portlets> @@ -674,7 +670,7 @@ >>> print toXML(area, u'displays') <?xml version="1.0" encoding="utf-8"?> <displays> - <area id="12345"/> + <area id="..."/> </displays> <BLANKLINE> @@ -687,7 +683,7 @@ >>> print toXML(effect, u'formats') <?xml version="1.0" encoding="utf-8"?> <formats> - <effect id="12345"> + <effect id="..."> <types value=""/> <format value="PNG"/> <width value="100"/> @@ -719,22 +715,24 @@ >>> print toXML(portlet, u'portlets', archive=archive) <?xml version="1.0" encoding="utf-8"?> <portlets> - <portlet id="12345" type="standard.image"> + <portlet id="..." type="standard.image"> <title value="Image portlet"/> <link value=""/> - <data value="12345_data_120x120.png"/> + <data value="..._data_120x120.png"/> <contentType value="image/png"/> </portlet> </portlets> <BLANKLINE> - >>> archive[u'12345_data_120x120.png'] == portlet.data + >>> archive == portlet.data True Resolving URIs ============== +Settings +-------- Resources can be accessed by using the name of the setting under which the resource has been registered (cpsskins://[EMAIL PROTECTED]). @@ -759,7 +757,7 @@ #ff0000 -This makes it possible to refer to resources in text. +This makes it possible to refer to settings in plain text. >>> style = Style() >>> root[u'style'] = style @@ -767,8 +765,34 @@ >>> from cpsskins.standard.filters.style import ICSSRenderer >>> ICSSRenderer(style)() - u'div.body.style12345 {color:#ff0000}' + u'div.body.style... {color:#ff0000}' + + +Resources +--------- +Resources that are not registered as settings can also be resolved: + + >>> uri = IIdentifiable(color).getURI() + >>> print uri + cpsskins://field-color:... + + >>> res = resources.resolve(uri, context=root) + >>> res is color + True + +A type check is performed: + + >>> wrong_type_uri = u'cpsskins://format-style:%s' % color.identifier + >>> resources.resolve(wrong_type_uri, context=root) + Traceback (most recent call last): + ... + TypeError: type mismatch: expected 'field-color' got 'format-style'. + + +Teardown: + >>> for k in root: + ... del root[k] Appendix ======== Modified: cpsskins/branches/paris-sprint-2006/setup/manager.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/setup/manager.py (original) +++ cpsskins/branches/paris-sprint-2006/setup/manager.py Sun May 14 20:15:30 2006 @@ -23,7 +23,7 @@ from zope.interface import implements from zope.component import getGlobalSiteManager -from cpsskins.setup.interfaces import IIdentifiable +from cpsskins.setup.interfaces import IIdentifiable, IType from cpsskins.setup.interfaces import IResourceManager, IResource from cpsskins.setup.interfaces import ISetting, IGlobalSetting, ILocalSetting from cpsskins.setup.setting import GlobalSetting, LocalSetting @@ -131,7 +131,15 @@ elif ':' in location: type_name, resource_id = location.split(':') type = getContentType(type_name) - # TODO + try: + obj = getThemeManager(context).getElementById(resource_id) + except KeyError: + raise KeyError("no such identifier: %s" % resource_id) + obj_type = IType(obj).getTypeName() + if type_name != obj_type: + raise TypeError("type mismatch: expected '%s' got '%s'." % \ + (obj_type, type_name)) + return obj else: raise ValueError("'%s' has no name or identifier." % uri) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins