[uiprops] introduce lazystr to get a chance to change style without having to change all properties
--- a/web/propertysheet.py Thu Jul 08 12:54:25 2010 +0200
+++ b/web/propertysheet.py Thu Jul 08 12:54:27 2010 +0200
@@ -23,6 +23,13 @@
import os
import os.path as osp
+class lazystr(object):
+ def __init__(self, string, context):
+ self.string = string
+ self.context = context
+ def __str__(self):
+ return self.string % self.context
+
class PropertySheet(dict):
def __init__(self, cache_directory, **context):
@@ -30,8 +37,12 @@
self.context = context
self.reset()
context['sheet'] = self
+ context['lazystr'] = self.lazystr
self._percent_rgx = re.compile('%(?!\()')
+ def lazystr(self, str):
+ return lazystr(str, self)
+
def reset(self):
self.clear()
self._ordered_propfiles = []
--- a/web/test/data/sheet1.py Thu Jul 08 12:54:25 2010 +0200
+++ b/web/test/data/sheet1.py Thu Jul 08 12:54:27 2010 +0200
@@ -1,3 +1,4 @@
bgcolor = '#000000'
stylesheets = ['%s/cubicweb.css' % datadir_url]
logo = '%s/logo.png' % datadir_url
+lazy = lazystr('%(bgcolor)s')
--- a/web/test/unittest_propertysheet.py Thu Jul 08 12:54:25 2010 +0200
+++ b/web/test/unittest_propertysheet.py Thu Jul 08 12:54:27 2010 +0200
@@ -27,6 +27,10 @@
# defined by sheet1, extended by sheet2
self.assertEquals(ps['stylesheets'], ['http://cwtest.com/cubicweb.css',
'http://cwtest.com/mycube.css'])
+ # lazy string defined by sheet1
+ self.assertIsInstance(ps['lazy'], lazystr)
+ self.assertEquals(str(ps['lazy']), '#FFFFFF')
+ # test compilation
self.assertEquals(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'),
'a {bgcolor: #FFFFFF; size: 1%;}')
self.assertEquals(ps.process_resource(DATADIR, 'pouet.css'),