# HG changeset patch # User Adrien Di Mascio # Date 1315304411 -7200 # Node ID a3f9ba4d44eb1c76a73059392ad8f6dad65e0b0d # Parent 46a8cf85d1864a4b4e3f4ecf4a7408efaefdd38e [web] add option to make resources-concat optional (implements #1910615) diff -r 46a8cf85d186 -r a3f9ba4d44eb test/unittest_utils.py --- a/test/unittest_utils.py Tue Sep 06 12:20:09 2011 +0200 +++ b/test/unittest_utils.py Tue Sep 06 12:20:11 2011 +0200 @@ -159,9 +159,17 @@ self.assertEqual(self.encode(TestCase), 'null') class HTMLHeadTC(CubicWebTC): + + def htmlhead(self, datadir_url): + req = self.request() + base_url = u'http://test.fr/data/' + req.datadir_url = base_url + head = HTMLHead(req) + return head + def test_concat_urls(self): base_url = u'http://test.fr/data/' - head = HTMLHead(base_url) + head = self.htmlhead(base_url) urls = [base_url + u'bob1.js', base_url + u'bob2.js', base_url + u'bob3.js'] @@ -171,7 +179,7 @@ def test_group_urls(self): base_url = u'http://test.fr/data/' - head = HTMLHead(base_url) + head = self.htmlhead(base_url) urls_spec = [(base_url + u'bob0.js', None), (base_url + u'bob1.js', None), (u'http://ext.com/bob2.js', None), @@ -196,7 +204,7 @@ def test_getvalue_with_concat(self): base_url = u'http://test.fr/data/' - head = HTMLHead(base_url) + head = self.htmlhead(base_url) head.add_js(base_url + u'bob0.js') head.add_js(base_url + u'bob1.js') head.add_js(u'http://ext.com/bob2.js') @@ -224,20 +232,22 @@ self.assertEqual(result, expected) def test_getvalue_without_concat(self): - base_url = u'http://test.fr/data/' - head = HTMLHead() - head.add_js(base_url + u'bob0.js') - head.add_js(base_url + u'bob1.js') - head.add_js(u'http://ext.com/bob2.js') - head.add_js(u'http://ext.com/bob3.js') - head.add_css(base_url + u'bob4.css') - head.add_css(base_url + u'bob5.css') - head.add_css(base_url + u'bob6.css', 'print') - head.add_css(base_url + u'bob7.css', 'print') - head.add_ie_css(base_url + u'bob8.css') - head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]') - result = head.getvalue() - expected = u""" + self.config.global_set_option('concat-resources', False) + try: + base_url = u'http://test.fr/data/' + head = self.htmlhead(base_url) + head.add_js(base_url + u'bob0.js') + head.add_js(base_url + u'bob1.js') + head.add_js(u'http://ext.com/bob2.js') + head.add_js(u'http://ext.com/bob3.js') + head.add_css(base_url + u'bob4.css') + head.add_css(base_url + u'bob5.css') + head.add_css(base_url + u'bob6.css', 'print') + head.add_css(base_url + u'bob7.css', 'print') + head.add_ie_css(base_url + u'bob8.css') + head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]') + result = head.getvalue() + expected = u""" @@ -253,7 +263,9 @@ """ - self.assertEqual(result, expected) + self.assertEqual(result, expected) + finally: + self.config.global_set_option('concat-resources', True) class DocTest(DocTest): from cubicweb import utils as module diff -r 46a8cf85d186 -r a3f9ba4d44eb utils.py --- a/utils.py Tue Sep 06 12:20:09 2011 +0200 +++ b/utils.py Tue Sep 06 12:20:11 2011 +0200 @@ -227,7 +227,7 @@ xhtml_safe_script_opening = u'' - def __init__(self, datadir_url=None): + def __init__(self, req): super(HTMLHead, self).__init__() self.jsvars = [] self.jsfiles = [] @@ -235,8 +235,8 @@ self.ie_cssfiles = [] self.post_inlined_scripts = [] self.pagedata_unload = False - self.datadir_url = datadir_url - + self._cw = req + self.datadir_url = req.datadir_url def add_raw(self, rawheader): self.write(rawheader) @@ -348,20 +348,26 @@ w(vardecl + u'\n') w(self.xhtml_safe_script_closing) # 2/ css files - for cssfile, media in (self.group_urls(self.cssfiles) if self.datadir_url else self.cssfiles): + ie_cssfiles = ((x, (y, z)) for x, y, z in self.ie_cssfiles) + if self.datadir_url and self._cw.vreg.config['concat-resources']: + cssfiles = self.group_urls(self.cssfiles) + ie_cssfiles = self.group_urls(ie_cssfiles) + jsfiles = (x for x, _ in self.group_urls((x, None) for x in self.jsfiles)) + else: + cssfiles = self.cssfiles + jsfiles = self.jsfiles + for cssfile, media in cssfiles: w(u'\n' % (media, xml_escape(cssfile))) # 3/ ie css if necessary - if self.ie_cssfiles: - ie_cssfiles = ((x, (y, z)) for x, y, z in self.ie_cssfiles) - for cssfile, (media, iespec) in (self.group_urls(ie_cssfiles) if self.datadir_url else ie_cssfiles): + if self.ie_cssfiles: # use self.ie_cssfiles because `ie_cssfiles` is a genexp + for cssfile, (media, iespec) in ie_cssfiles: w(u' \n') # 4/ js files - jsfiles = ((x, None) for x in self.jsfiles) - for jsfile, media in self.group_urls(jsfiles) if self.datadir_url else jsfiles: + for jsfile in jsfiles: if skiphead: # Don't insert