Author: jmorliaguet
Date: Wed Apr 26 11:20:17 2006
New Revision: 2966

Modified:
   cpsskins/branches/paris-sprint-2006/__init__.py
   cpsskins/branches/paris-sprint-2006/configuration/fields/metaconfigure.py
   cpsskins/branches/paris-sprint-2006/configuration/portlets/metaconfigure.py
   cpsskins/branches/paris-sprint-2006/elements/configure.zcml
   cpsskins/branches/paris-sprint-2006/elements/interfaces.py
   cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/manager.py
   cpsskins/branches/paris-sprint-2006/setup/utils.py
   cpsskins/branches/paris-sprint-2006/standard/filters/style/__init__.py
Log:

- using the CA to register interface names.

- added getType(name) to get the type signature from the name

  and getTypeName(name) to get the name of a type signature

- resources can be looked up through, e.g.

   cpsskins://field-color:red



Modified: cpsskins/branches/paris-sprint-2006/__init__.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/__init__.py     (original)
+++ cpsskins/branches/paris-sprint-2006/__init__.py     Wed Apr 26 11:20:17 2006
@@ -19,8 +19,6 @@
 
 from cpsskins.elements.portlet import Portlet
 
-from cpsskins.setup.utils import resource
-
 # load profiles
 from cpsskins.profiles import default
 

Modified: 
cpsskins/branches/paris-sprint-2006/configuration/fields/metaconfigure.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/configuration/fields/metaconfigure.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/configuration/fields/metaconfigure.py   
Wed Apr 26 11:20:17 2006
@@ -20,10 +20,12 @@
 from zope.app.content.interfaces import IContentType
 from zope.configuration.exceptions import ConfigurationError
 from zope.component import queryUtility
+from zope.component.interface import provideInterface
 from zope.interface import alsoProvides
 
 from cpsskins import configuration
-from cpsskins.setup.interfaces import IResourceType
+from cpsskins.elements.interfaces import ITypeable
+from cpsskins.setup.interfaces import IResourceType, INameType
 
 def field(_context, name=u'', schema=None, factory=None):
 
@@ -45,5 +47,7 @@
     alsoProvides(schema, IResourceType)
     alsoProvides(schema, IContentType)
 
+    provideInterface(name, schema, INameType)
+
     schema.setTaggedValue('name', name)
 

Modified: 
cpsskins/branches/paris-sprint-2006/configuration/portlets/metaconfigure.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/configuration/portlets/metaconfigure.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/configuration/portlets/metaconfigure.py 
Wed Apr 26 11:20:17 2006
@@ -26,11 +26,13 @@
 from zope.app.publisher.browser.menumeta import addMenuItem
 from zope.app.publisher.browser.resourcemeta import resource
 from zope.app.content.interfaces import IContentType
+from zope.component.interface import provideInterface
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface import Interface, alsoProvides
 
 from cpsskins import ui
 from cpsskins.browser.rendering.interfaces import IUpdateData
+from cpsskins.setup.interfaces import INameType
 
 ui_path = os.path.dirname(ui.__file__)
 
@@ -92,3 +94,6 @@
     # set up interface types
     alsoProvides(schema, IContentType)
     schema.setTaggedValue('name', name)
+
+    provideInterface(name, schema, INameType)
+

Modified: cpsskins/branches/paris-sprint-2006/elements/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/elements/configure.zcml (original)
+++ cpsskins/branches/paris-sprint-2006/elements/configure.zcml Wed Apr 26 
11:20:17 2006
@@ -72,6 +72,12 @@
       type=".interfaces.IElementType"
   />
 
+  <interface
+      name="display"
+      interface=".interfaces.IDisplay"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <!-- the same adapter with traversal support -->
 
   <adapter
@@ -104,6 +110,12 @@
       type=".interfaces.IElementType"
   />
 
+  <interface
+      name="format"
+      interface=".interfaces.IFormat"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <!-- Fields -->
 
   <interface
@@ -111,6 +123,12 @@
       type=".interfaces.IElementType"
   />
 
+  <interface
+      name="field"
+      interface=".interfaces.IField"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <!-- this adapter makes elements presentable -->
 
   <adapter
@@ -134,6 +152,13 @@
       type=".interfaces.IElementType"
   />
 
+  <interface
+      name="canvas"
+      interface=".interfaces.ICanvas"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
+  <!-- this adapter makes elements presentable -->
 
   <!-- Theme -->
 
@@ -147,6 +172,12 @@
       type="zope.app.content.interfaces.IContentType"
   />
 
+  <interface
+      name="theme"
+      interface=".interfaces.ITheme"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <class class=".theme.Theme">
 
     <implements
@@ -181,6 +212,12 @@
       type="zope.app.content.interfaces.IContentType"
   />
 
+  <interface
+      name="themepage"
+      interface=".interfaces.IThemePage"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <class class=".themepage.ThemePage">
 
     <implements
@@ -238,6 +275,12 @@
       type="zope.app.content.interfaces.IContentType"
   />
 
+  <interface
+      name="pageblock"
+      interface=".interfaces.IPageBlock"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <class class=".pageblock.PageBlock">
 
     <implements
@@ -296,6 +339,12 @@
       type="zope.app.content.interfaces.IContentType"
   />
 
+  <interface
+      name="cell"
+      interface=".interfaces.ICell"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <class class=".cell.Cell">
 
     <implements
@@ -360,6 +409,12 @@
       type="zope.app.content.interfaces.IContentType"
   />
 
+  <interface
+      name="slot"
+      interface=".interfaces.ISlot"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <class class=".slot.Slot">
 
     <implements
@@ -421,6 +476,12 @@
       type="cpsskins.setup.interfaces.IResourceType"
   />
 
+  <interface
+      name="portlet"
+      interface=".interfaces.IPortlet"
+      type="cpsskins.setup.interfaces.INameType"
+  />
+
   <cpsskins:presentation
       for=".interfaces.IPortlet">
 

Modified: cpsskins/branches/paris-sprint-2006/elements/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/elements/interfaces.py  (original)
+++ cpsskins/branches/paris-sprint-2006/elements/interfaces.py  Wed Apr 26 
11:20:17 2006
@@ -26,6 +26,8 @@
 from zope.interface.interfaces import IInterface
 from zope.schema import TextLine
 
+from cpsskins.setup.interfaces import INameType
+
 _ = MessageFactory("cpsskins")
 
 # Elements
@@ -192,6 +194,7 @@
     """A base portlet interface implemented by all portlets (global or local)
     """
 
+
     title = TextLine(
         title=_(u"Portlet's title"),
         required=False)

Modified: cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py (original)
+++ cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py Wed Apr 26 
11:20:17 2006
@@ -34,6 +34,7 @@
 from cpsskins.setup.test.dummy import IDummyResource, DummyResourceImporter
 from cpsskins.setup.test.dummy import DummyFactory
 
+import cpsskins.elements.interfaces
 
 def setUp(test):
     # export adapters

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        Wed Apr 26 
11:20:17 2006
@@ -101,14 +101,19 @@
     >>> resources.register(name=u'resource2', title=u'Resource 2',
     ...                    resource=resource2)
 
-and look it up in the registry:
+and look it up in the registry, either by specifying its name:
 
     >>> resources.lookup(u'resource2')
     <Dummy resource: resource2>
 
-or we find it by listing all registered resources:
+or by also specifying an interface that it implements to avoid conflict names:
 
-    >>> resources.list(type=IDummyResource)
+    >>> resources.lookup(u'resource2', IDummyResource)
+    <Dummy resource: resource2>
+
+We can also list all registered resources by type:
+
+    >>> resources.list(IDummyResource)
     [<Dummy resource: resource1>, <Dummy resource: resource2>]
 
 
@@ -419,11 +424,24 @@
      <InterfaceClass cpsskins.elements.interfaces.IPortlet>,
      <InterfaceClass cpsskins.standard.portlets.actions.portlet.IActions>]
 
-or as a string:
+or as a string that can be passed in a URL or be written in JSON, XML.
 
     >>> ITypeable(resource).getTypeName()
     u'canvas-portlet-standard.actions'
 
+Note that there is a one-to-one relation between type signatures and type
+signature names:
+
+    >>> from cpsskins.setup.utils import getType, getTypeName
+
+    >>> portlet_type = getType(u'canvas-portlet-standard.actions')
+    >>> pprint(portlet_type)
+    [<InterfaceClass cpsskins.elements.interfaces.ICanvas>,
+     <InterfaceClass cpsskins.elements.interfaces.IPortlet>,
+     <InterfaceClass cpsskins.standard.portlets.actions.portlet.IActions>]
+
+    >>> getTypeName(portlet_type)
+    u'canvas-portlet-standard.actions'
 
 URI
 ---
@@ -561,10 +579,9 @@
 Refering to resources
 =====================
 
-Resources can be accessed using the name of the setting under which the
+Resources can be accessed by using the name of the setting under which the
 resource has been registered.
 
-    >>> from cpsskins import resource
     >>> from cpsskins.standard.fields.color import Color
 
     >>> color = Color(r=255, g=0, b=0)
@@ -574,17 +591,23 @@
 
     >>> resources.register(name=u'red', title=u'Color red', resource=color)
 
-    >>> print resource(root, u'red')
-    #ff0000
+    >>> ITypeable(color).getTypeName()
+    u'field-color'
+
+    >>> res = resources.find(u'cpsskins://field-color:red', context=root)
 
+    >>> res is color
+    True
+
+    >>> print res
+    #ff0000
 
-This makes it possible to embed references to resources inside objects:
 
-# TODO: to be rewritten
+This makes it possible to refer to resources using a string notation.
 
     >>> style = Style()
     >>> root[u'style'] = style
-    >>> style[u'div.body'] = {'color': resource(root, u'red')}
+    >>> style[u'div.body'] = {'color': u'cpsskins://field-color:red'}
 
     >>> from cpsskins.standard.filters.style import ICSSRenderer
     >>> ICSSRenderer(style)()

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        Wed Apr 26 
11:20:17 2006
@@ -27,6 +27,7 @@
 from cpsskins.setup.interfaces import IResourceManager, IResource
 from cpsskins.setup.interfaces import ISetting, IGlobalSetting, ILocalSetting
 from cpsskins.setup.setting import GlobalSetting, LocalSetting
+from cpsskins.setup.utils import getType, getTypeName, getContentType
 from cpsskins.utils import getThemeManager
 
 class ResourceManager(object):
@@ -83,7 +84,7 @@
     # Finding resources
     ###################################################################
 
-    def lookup(self, name=u'', context=None, default=None):
+    def lookup(self, name=u'', type=None, context=None, default=None):
         if not name:
             raise KeyError("Must specify a resource name.")
 
@@ -101,7 +102,10 @@
 
         resource_getter = IResource(setting, None)
         if resource_getter is not None:
-            return resource_getter.getResource()
+            resource = resource_getter.getResource()
+            if type and not type in list(providedBy(resource)):
+                return default
+            return resource
         return default
 
     def list(self, type=None, context=None):
@@ -123,6 +127,15 @@
             items[name] = resource
         return items.values()
 
+    def find(self, name, context=None):
+        parts = name.split('cpsskins://')
+        if len(parts) != 2:
+            return None
+        name = parts[1]
+        type_name, resource_id = name.split(':')
+        type = getContentType(type_name)
+        return self.lookup(name=resource_id, type=type, context=context)
+
     ###################################################################
     # Customization
     ###################################################################

Modified: cpsskins/branches/paris-sprint-2006/setup/utils.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/utils.py  (original)
+++ cpsskins/branches/paris-sprint-2006/setup/utils.py  Wed Apr 26 11:20:17 2006
@@ -24,21 +24,48 @@
 from tarfile import TarFile
 from tarfile import TarInfo
 
-from zope.component import getUtility, createObject
+from zope.component import createObject
+from zope.component import getUtility, queryUtility, getUtilitiesFor
+from zope.component.interface import getInterface
 from zope.interface import implements
 from zope.schema import getFieldNamesInOrder
 
 from cpsskins.elements.interfaces import IIdentifiable, IType
 from cpsskins.setup.interfaces import IDataExporter, IDataImporter
-from cpsskins.setup.interfaces import IResourceManager
+from cpsskins.setup.interfaces import IResourceManager, INameType
 from cpsskins.utils import getThemeManager
 
+from  cpsskins.elements import interfaces
+
 logger = logging.getLogger("cpsskins")
 
-def resource(context, name):
-    mgr = getThemeManager(context)
-    resources = getUtility(IResourceManager)
-    return resources.lookup(name, context=mgr)
+def getType(name):
+    """Return the type signature from the type signature's name.
+    """
+    if '-' not in name:
+        raise TypeError("Invalid type name: %s" % name)
+
+    type = []
+    for type_name in name.split('-'):
+        iface = queryUtility(INameType, type_name, None)
+        if iface is None:
+            continue
+        type.append(iface)
+    return type
+
+def getContentType(name):
+    return getType(name)[-1]
+
+def getTypeName(type):
+    """Return the type signature's name from the type signature.
+    """
+    # TODO: could be cached
+    names = []
+    name_types = list(getUtilitiesFor(INameType))
+    for iface in type:
+        name = [k for k, v in list(name_types) if v is iface][0]
+        names.append(name)
+    return '-'.join(names)
 
 class TarArchive:
 

Modified: cpsskins/branches/paris-sprint-2006/standard/filters/style/__init__.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/style/__init__.py      
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/style/__init__.py      
Wed Apr 26 11:20:17 2006
@@ -20,12 +20,14 @@
 import re
 
 from zope.interface import implements, Interface
-from zope.component import adapts
+from zope.component import adapts, getUtility
 
 from cpsskins.standard.formats.style import IStyle
 from cpsskins.browser.rendering.interfaces import IFilterView
 from cpsskins.elements.interfaces import IIdentifiable
 from cpsskins.relations.interfaces import IRelatable
+from cpsskins.setup.interfaces import IResourceManager
+
 
 startTag = re.compile('<.*?>')
 classAttr = re.compile(' class="(.*?)"')
@@ -136,14 +138,23 @@
     def __call__(self):
         """Render the style in CSS"""
         style = self.style
+        context = style
         style_id = str(self)
         rendered = []
+
+        resources = getUtility(IResourceManager)
+
         for k, v in style.items():
             s = k.split(' ')
             sel = ' '.join(s[1:])
             if not v:
                 continue
-            props = ';'.join(['%s:%s' % (p, r) for p, r in v.items()])
-            rendered.append('%s.%s %s {%s}' % (s[0], style_id, sel, props))
+            props = []
+            for p, r in v.items():
+                if r.startswith('cpsskins://'):
+                    r = resources.find(r, context)
+                props.append('%s:%s' % (p, r))
+            rendered.append('%s.%s %s {%s}' % (s[0], style_id, sel,
+                                              ';'.join(props)))
         return '\n'.join(rendered)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to