Skip to content

Commit

Permalink
single files of a type should remain unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
jannon committed Jul 17, 2012
1 parent 65b676e commit 0f04270
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compressor/base.py
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions compressor/tests/test_base.py
Expand Up @@ -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("""<link rel="stylesheet" href="/media/css/one.css" type="text/css" />""")
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'<link rel="stylesheet" href="/media/css/one.css" type="text/css" />'],
]
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,
Expand Down

0 comments on commit 0f04270

Please sign in to comment.