Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install z3ext.cssregistry

How to install z3ext.cssregistry

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3ext.cssregistry
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.6.0 Available View build log
1.5.0 Available View build log
Windows (64-bit)
1.6.0 Available View build log
1.5.0 Available View build log
Mac OS X (10.5+)
1.6.0 Available View build log
1.5.0 Available View build log
Linux (32-bit)
1.6.0 Available View build log
1.5.0 Available View build log
Linux (64-bit)
1.6.0 Available View build log
1.5.0 Available View build log
Web
 
Author
License
ZPL 2.1
Lastest release
version 1.6.0 on Jan 19th, 2011

CSS Registry

A registry for linked Stylesheet files and Javascripts.

This registry is mainly aimed at solving the following usecases:

  • Enable skin developer to change css properties without having to resort to override css files itself
  • Enable more componentialization of the stylesheets.

Some usefull imports

>>> from zope import interface, component
>>> from zope.interface.verify import verifyObject
>>> from z3ext.cssregistry.interfaces import \
...   Layer, ICSSRegistry, ICSSRegistryLayer
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()

Load directive declaration

>>> from zope.configuration import xmlconfig
>>> context = xmlconfig.string("""
... <configure>
...    <include package="z3ext.cssregistry" file="meta.zcml" />
... </configure>""")

Now we can create css registry

>>> context = xmlconfig.string("""
... <configure xmlns:browser="http://namespaces.zope.org/browser">
...   <browser:cssregistry>
...      <property name="color1" value="#f5f5f5" />
...      <property name="color2" value="white" />
...      <property name="fontFamilyH1" value="Verdana" />
...      <property name="fontFamilyH2" value="Arial" />
...   </browser:cssregistry>
... </configure>""", context)

browser:cssregistry diretive creates ICSSRegistry. It accepts name,title,layer parameters. All parameters not required, by default registry will have blank name and registered against IDefaultBrowserLayer layer. We can't register cssregistry for layer, because in that case it whould be available as resource (++resource++) So directive register multi adapter for ICSSRegistryLayer and supplied layer

>>> registry = component.getMultiAdapter((Layer, Layer, request), ICSSRegistry)
>>> verifyObject(ICSSRegistry, registry)
True
>>> registry['color1'].value
u'#f5f5f5'
>>> registry['fontFamilyH1'].value
u'Verdana'

We also can add more properties later:

>>> context = xmlconfig.string("""
... <configure xmlns:browser="http://namespaces.zope.org/browser">
...   <browser:cssproperty name="color3" value="#225593" />
... </configure>""", context)
>>> registry['color3'].value
u'#225593'
zrt command

z3ext.cssregistry package aslo register new command for z3c.zrtresource.

>>> from z3ext.cssregistry.command import cssregistry_factory
>>> from z3c.zrtresource.interfaces import IZRTCommandFactory
>>> component.provideUtility(cssregistry_factory, IZRTCommandFactory, 'cssregistry')

Now we can use cssregistry for zrtresource resources

>>> import tempfile
>>> fn = tempfile.mktemp('.css')
>>> open(fn, 'w').write('''\
... /* zrt-cssregistry: */
... h1 {
...   color: color1;
...   font: fontFamilyH1;
... }
...
... h2 {
...   color: color2;
...   font: fontFamilyH2;
... }''')
>>> from z3c.zrtresource.zrtresource import ZRTFileResourceFactory
>>> cssFactory = ZRTFileResourceFactory(fn, None, 'site.css')
>>> from zope.publisher.browser import TestRequest
>>> css = cssFactory(TestRequest())
>>> print css.GET()
h1 {
  color: #f5f5f5;
  font: Verdana;
}
<BLANKLINE>
h2 {
  color: white;
  font: Arial;
}

Now if we need change css file we only need change cssregistry properties

>>> registry['color1'].value = 'black'
>>> print css.GET()
h1 {
  color: black;
  font: Verdana;
}
<BLANKLINE>
h2 {
  color: white;
  font: Arial;
}

We also can use named cssregistries

>>> context = xmlconfig.string("""
... <configure xmlns:browser="http://namespaces.zope.org/browser">
...   <browser:cssregistry name="mycss">
...      <property name="color1" value="#d5d5d5" />
...      <property name="color2" value="black" />
...      <property name="fontFamilyH1" value="Tahoma" />
...      <property name="fontFamilyH2" value="Courier" />
...   </browser:cssregistry>
... </configure>""", context)
>>> open(fn, 'w').write('''\
... /* zrt-cssregistry: mycss */
... h1 {
...   color: color1;
...   font: fontFamilyH1;
... }
...
... h2 {
...   color: color2;
...   font: fontFamilyH2;
... }''')
>>> cssFactory = ZRTFileResourceFactory(fn, None, 'site.css')
>>> css = cssFactory(TestRequest())
>>> print css.GET()
h1 {
  color: #d5d5d5;
  font: Tahoma;
}
<BLANKLINE>
h2 {
  color: black;
  font: Courier;
}

If cssregistry is unknown nothing will happen

>>> open(fn, 'w').write('''\
... /* zrt-cssregistry: unknown */
... h1 {
...   color: color1;
...   font: fontFamilyH1;
... }''')
>>> cssFactory = ZRTFileResourceFactory(fn, None, 'site.css')
>>> css = cssFactory(TestRequest())
>>> print css.GET()
h1 {
  color: color1;
  font: fontFamilyH1;
}
Registry methods
>>> registry.keys()
[u'color1', u'color3', u'color2', u'fontFamilyH2', u'fontFamilyH1']
>>> list(iter(registry))
[u'color1', u'color3', u'color2', u'fontFamilyH2', u'fontFamilyH1']
>>> for key, prop in registry.items():
...     print key, prop
color1 <z3ext.cssregistry.property.Property ...>
color3 <z3ext.cssregistry.property.Property ...>
color2 <z3ext.cssregistry.property.Property ...>
fontFamilyH2 <z3ext.cssregistry.property.Property ...>
fontFamilyH1 <z3ext.cssregistry.property.Property ...>
>>> len(registry)
5
>>> u'color1' in registry
True
>>> registry.get(u'color1')
<z3ext.cssregistry.property.Property ...>
>>> del registry[u'color1']
>>> registry.keys()
[u'color3', u'color2', u'fontFamilyH2', u'fontFamilyH1']

CHANGES

1.6.0 (Unreleased)
  • Remove zope.app.testing test dependency
  • Made tests compatible with zope.browserresource 3.11, thus requiring at least this version.
1.5.0 (2009-08-11)
  • Do not use z3c.autoinclude
  • Copyright holder changed
1.4.0 (2008-11-25)
  • z3ext.controlpanel configlet moved to z3ext.ui.cssregistry package
1.3.2 (2008-11-24)
  • Include z3ext.controlpanel if installed
1.3.1 (2008-11-13)
  • Added property title
  • Property description is i18n aware
  • Fix Persistent property management
  • Added translations: ru, nl
1.3.0 (2008-10-10)
  • Update i18n
  • Do not use Persistent for registry and property
1.2.2 (2008-04-01)
  • Configlet declaration moved to seperate zcml file
1.2.1 (2008-03-31)
  • Fix wrong import
1.2.0 (2008-03-21)
  • tests updated
  • move to svn.zope.org
1.1.3 (2008-02-11)
  • Fixed control panel configlet
1.1.2 (2008-02-08)
  • Security declarations fixed
1.1.1 (2008-02-08)
  • Remove support cssregistry as utility
1.1.0 (2008-02-08)
  • Added controlpanel configlet
  • Code cleanup
1.0.0 (2007-12-01)
  • Initial release.

Subscribe to package updates

Last updated Jan 19th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.