From 0f042701492a45e602e93601075c5da03264c78c Mon Sep 17 00:00:00 2001 From: Jannon Frank Date: Tue, 17 Jul 2012 16:23:15 -0700 Subject: [PATCH] single files of a type should remain unchanged --- compressor/base.py | 8 ++++++-- compressor/tests/test_base.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compressor/base.py b/compressor/base.py index 7b03eacea..6b601363f 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -59,10 +59,14 @@ def group_contents(self): charset = attrs.get("charset", self.charset) mimetype = attrs.get("type", None) if mimetype: - if kind == SOURCE_FILE: - value = self.get_filecontent(value, charset) idx = groups.get(mimetype, -1) if idx >= 0: + # get the content of this elem if it's a file + if kind == SOURCE_FILE: + value = self.get_filecontent(value, charset) + # if there is only 1 existing and it's a file, convert it too + if len(contents[idx][3]) == 1 and contents[idx][0] == SOURCE_FILE: + contents[idx][1] = self.get_filecontent(contents[idx][1], charset) contents[idx][0] = SOURCE_HUNK contents[idx][1] += value contents[idx][3].extend(elems) diff --git a/compressor/tests/test_base.py b/compressor/tests/test_base.py index 8a8bab0e6..d03e739d5 100644 --- a/compressor/tests/test_base.py +++ b/compressor/tests/test_base.py @@ -173,6 +173,19 @@ def test_css_group(self): split = [[x[0], x[1], x[2], make_elems_str(self.css_node.parser, x[3])] for x in split] self.assertEqual(out, split) + def test_css_single(self): + css_node = CssCompressor("""""") + css_node.opts = {'group_first': 'true'} + out = [ + [SOURCE_FILE, + os.path.join(settings.COMPRESS_ROOT, u'css', u'one.css'), + u'css/one.css', + u''], + ] + split = css_node.group_contents() + split = [[x[0], x[1], x[2], make_elems_str(self.css_node.parser, x[3])] for x in split] + self.assertEqual(out, split) + def test_js_group(self): out = [ [SOURCE_HUNK,