# HG changeset patch # User Sylvain Thénault # Date 1278586467 -7200 # Node ID 9cb13d1b2ce4d5172daa0c76f4c4b92a38ae10da # Parent 82cac9383dd8d7e29de244d9f59cdafcff5ac6ed [uiprops] introduce lazystr to get a chance to change style without having to change all properties diff -r 82cac9383dd8 -r 9cb13d1b2ce4 web/propertysheet.py --- 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 = [] diff -r 82cac9383dd8 -r 9cb13d1b2ce4 web/test/data/sheet1.py --- 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') diff -r 82cac9383dd8 -r 9cb13d1b2ce4 web/test/unittest_propertysheet.py --- 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'),