Author: jmorliaguet Date: Fri Apr 7 16:35:23 2006 New Revision: 2784 Added: cpsskins/branches/jmo-perspectives/setup/utils.py (contents, props changed) Modified: cpsskins/branches/jmo-perspectives/__init__.py cpsskins/branches/jmo-perspectives/setup/README.txt cpsskins/branches/jmo-perspectives/setup/setting.py cpsskins/branches/jmo-perspectives/standard/filters/style/__init__.py cpsskins/branches/jmo-perspectives/standard/formats/configure.zcml cpsskins/branches/jmo-perspectives/utils.py Log:
- made it possible to refer to resources, so that we can write: style['color'] = resource(u'red') instead of: style['color'] = u'#ff0000' Modified: cpsskins/branches/jmo-perspectives/__init__.py ============================================================================== --- cpsskins/branches/jmo-perspectives/__init__.py (original) +++ cpsskins/branches/jmo-perspectives/__init__.py Fri Apr 7 16:35:23 2006 @@ -19,6 +19,8 @@ from cpsskins.elements.portlet import Portlet +from cpsskins.setup.utils import resource + # load profiles from cpsskins.profiles import default Modified: cpsskins/branches/jmo-perspectives/setup/README.txt ============================================================================== --- cpsskins/branches/jmo-perspectives/setup/README.txt (original) +++ cpsskins/branches/jmo-perspectives/setup/README.txt Fri Apr 7 16:35:23 2006 @@ -277,12 +277,9 @@ settings were last loaded. -=============== IMPORT / EXPORT =============== -This package contains XML exporters and importers. - To be exported and imported, resources must be uniformally identifiable. Their name is obtained by combining element type, resource type and content @@ -484,13 +481,21 @@ Export of elements ------------------ + >>> from cpsskins.elements.pageblock import PageBlock + >>> pageblock = PageBlock(u'Some page block') + + >>> root['pageblock'] = pageblock + >>> from cpsskins.elements.cell import Cell - >>> resource = Cell(u'Some cell') + >>> cell = Cell(u'Some cell') - >>> exporter = getMultiAdapter((resource, request), IDataExporter) + >>> pageblock[u'cell'] = cell + + >>> exporter = getMultiAdapter((pageblock, request), IDataExporter) >>> print exporter() <?xml version="1.0"?> - <element uri="canvas-cell-12345" title="Some cell"/> + <element uri="canvas-pageblock-12345" + title="Some page block"/> <BLANKLINE> @@ -506,11 +511,13 @@ to finish -Accessing resources -=================== +Refering to resources +===================== -Resources can be used instead of setting +Resources can be accessed 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) @@ -518,8 +525,20 @@ >>> print color #ff0000 - >>> IIdentifiable(color).getURI() + >>> resources.register(name=u'red', title=u'Color red', resource=color) + + >>> print resource(u'red') + #ff0000 + + +This makes it possible to embed references to resources inside objects: + + >>> style = Style() + >>> root[u'style'] = style + >>> style[u'div.body'] = {'color': resource(u'red')} + + >>> from cpsskins.standard.filters.style import ICSSRenderer + >>> ICSSRenderer(style)() + u'div.body.style12345 {color:#ff0000}' - >>> resource = Style() - >>> resource[u'div.body'] = {'color': u'resource://color-red'} Modified: cpsskins/branches/jmo-perspectives/setup/setting.py ============================================================================== --- cpsskins/branches/jmo-perspectives/setup/setting.py (original) +++ cpsskins/branches/jmo-perspectives/setup/setting.py Fri Apr 7 16:35:23 2006 @@ -33,6 +33,9 @@ self.resource.__parent__ = self self.resource.__name__ = name + def __call__(self): + return self.resource + def isGlobal(self): return IGlobalSetting.providedBy(self) Added: cpsskins/branches/jmo-perspectives/setup/utils.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/setup/utils.py Fri Apr 7 16:35:23 2006 @@ -0,0 +1,29 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from zope.component import queryUtility, getUtility + +from cpsskins.utils import getThemeManager +from cpsskins.setup.interfaces import IResourceManager + +def resource(name): + mgr = getThemeManager() + resources = getUtility(IResourceManager) + return resources.lookup(name, context=mgr) + Modified: cpsskins/branches/jmo-perspectives/standard/filters/style/__init__.py ============================================================================== --- cpsskins/branches/jmo-perspectives/standard/filters/style/__init__.py (original) +++ cpsskins/branches/jmo-perspectives/standard/filters/style/__init__.py Fri Apr 7 16:35:23 2006 @@ -25,6 +25,7 @@ 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 startTag = re.compile('<.*?>') classAttr = re.compile(' class="(.*?)"') @@ -130,7 +131,7 @@ self.style = style def __str__(self): - return 'style%s' % self.style.identifier + return 'style%s' % unicode(IRelatable(self.style)) def __call__(self): """Render the style in CSS""" Modified: cpsskins/branches/jmo-perspectives/standard/formats/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/standard/formats/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/standard/formats/configure.zcml Fri Apr 7 16:35:23 2006 @@ -29,13 +29,6 @@ predicate=".style.hasStyle" /> - <!-- Setting --> - <cpsskins:setting - name="style" - schema=".style.IStyle" - factory=".style.StyleFactory" - /> - <!-- Widget --> <cpsskins:format name="widget" Modified: cpsskins/branches/jmo-perspectives/utils.py ============================================================================== --- cpsskins/branches/jmo-perspectives/utils.py (original) +++ cpsskins/branches/jmo-perspectives/utils.py Fri Apr 7 16:35:23 2006 @@ -17,8 +17,9 @@ """ __docformat__ = "reStructuredText" -from zope.component import queryUtility +from zope.component import queryUtility, getUtility +from cpsskins.setup.interfaces import IResourceManager from cpsskins.thememanager import IThemeManagementFolder THEMES_MANAGER_NAME = 'themes' -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins