Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Handle css correct If COMPRESS_PRECOMPILERS is used and COMPRESS_ENABLED is False #194

Merged
merged 3 commits into from

6 participants

@peterlundberg

This is described also in #120 which then might be closeable. This is a serious issue when developing with for instance mixed css/less code.

This is based on threepress/django_compressor@f94c05e

and is confirmed to fix the issue when I have tested manually. I am not sure where to best or if at all add tests.

@jezdez
Owner

I can't merge this without a way to reproduce this, as mentioned in #120. Please add a test.

@jezdez
Owner

BTW, running the tests is as easy as explained here: http://django_compressor.readthedocs.org/en/latest/contributing/#tests

@peterlundberg

Ok I gave this a shot.

New tests in base.py and templatetags.py seams not to reproduce this on develop f752c7b.

BTW the dox in contributing are not updated to the new tox.ini location on develop.

Some git magic and i tried on 1.1.1 and this seams to happen. Tomorrow I will try our codebase against develop for a longer time and see how it works.
1) What is the roadmap for releasing what is on develop (1.2?). Is there any point providing a 1.1.3 for this?
2) Are you interested in the tests anyway?

@AdrianRibao

If it helps, I had the same problem with the stable version, but everything works ok on the master branch, but the package on pypi should be updated soon.

@peterlundberg

Just to confirm. This is not an issue on the master branch, only on the 1.1 on pypi. The tests i did are on my fork and should probably be added as this has happened once. Let me know if there is anything else I might be able to help with.

@jezdez jezdez merged commit 78d1db2 into from
@reinout

Will there be a new release soon? This bug badly breaks my development cycle :-)

I can make a custom package and stick that into our company-internal pypi clone, but I'd rather just use a real release.

@jezdez
Owner

Yeah, there will be a release, once the more glaring bugs are fixed. I assume it'll take not long till then. Any help would be appreciated as always :)

@reinout

Is it an idea to tag those glaring bugs? "1.2" or so? For something with glaring bugs, it works like a charm for me :-)

@jezdez
Owner

Yeah, sounds like a plan :)

@23doors

Would be really great if this plan could be set in motion ;)

@mrcoles

Currently it's impossible to group CSS files when when COMPRESS_ENABLED=False, even when you run python manage.py compress --force.

It'd be great if this line know about the --force option. It looks like it'd require the info to be passed through somehow in this line: https://github.com/django-compressor/django-compressor/blob/e037be06a43190193f8e81e304993fce7f081ff1/compressor/management/commands/compress.py#L228

IDK if it’d be OK to sneak something through on template, context, or node to be checked in the above line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 compressor/css.py
@@ -30,9 +30,10 @@ def split_contents(self):
if data:
self.split_content.append(data)
media = elem_attribs.get('media', None)
- # Append to the previous node if it had the same media type,
- # otherwise create a new node.
- if self.media_nodes and self.media_nodes[-1][0] == media:
+ # Append to the previous node if it had the same media type
+ append_to_previous = self.media_nodes and self.media_nodes[-1][0] == media
+ # and we are not just precompiling, otherwise create a new node.
+ if append_to_previous and settings.COMPRESS_ENABLED:
self.media_nodes[-1][1].split_content.append(data)
else:
node = CssCompressor(content=self.parser.elem_str(elem),
View
26 compressor/tests/base.py
@@ -142,21 +142,39 @@ def setUp(self):
<style type="text/css" media="print">p { border:5px solid green;}</style>
<link rel="stylesheet" href="/media/css/two.css" type="text/css" media="all">
<style type="text/css">h1 { border:5px solid green;}</style>"""
- self.css_node = CssCompressor(self.css)
def test_css_output(self):
- links = BeautifulSoup(self.css_node.output()).findAll('link')
+ css_node = CssCompressor(self.css)
+ links = BeautifulSoup(css_node.output()).findAll('link')
media = [u'screen', u'print', u'all', None]
self.assertEqual(len(links), 4)
self.assertEqual(media, [l.get('media', None) for l in links])
def test_avoid_reordering_css(self):
css = self.css + '<style type="text/css" media="print">p { border:10px solid red;}</style>'
- node = CssCompressor(css)
+ css_node = CssCompressor(css)
media = [u'screen', u'print', u'all', None, u'print']
- links = BeautifulSoup(node.output()).findAll('link')
+ links = BeautifulSoup(css_node.output()).findAll('link')
self.assertEqual(media, [l.get('media', None) for l in links])
+ def test_passthough_when_compress_disabled(self):
+ original_precompilers = settings.COMPRESS_PRECOMPILERS
+ settings.COMPRESS_ENABLED = False
+ settings.COMPRESS_PRECOMPILERS = (
+ ('text/foobar', 'python %s {infile} {outfile}' % os.path.join(test_dir, 'precompiler.py')),
+ )
+ css = """\
+<link rel="stylesheet" href="/media/css/one.css" type="text/css" media="screen">
+<link rel="stylesheet" href="/media/css/two.css" type="text/css" media="screen">
+<style type="text/foobar" media="screen">h1 { border:5px solid green;}</style>"""
+ css_node = CssCompressor(css)
+ output = BeautifulSoup(css_node.output()).findAll(['link','style'])
+ self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None],
+ [l.get('href', None) for l in output])
+ self.assertEqual([u'screen', u'screen', u'screen'],
+ [l.get('media', None) for l in output])
+ settings.COMPRESS_PRECOMPILERS = original_precompilers
+
class VerboseTestCase(CompressorTestCase):
View
40 compressor/tests/templatetags.py
@@ -137,6 +137,7 @@ def setUp(self):
settings.COMPRESS_ENABLED = True
settings.COMPRESS_PRECOMPILERS = (
('text/coffeescript', '%s %s' % (python, precompiler)),
+ ('text/less', '%s %s' % (python, precompiler)),
)
self.context = {'MEDIA_URL': settings.COMPRESS_URL}
@@ -222,6 +223,45 @@ def test_multiple_file_order_conserved(self):
finally:
settings.COMPRESS_ENABLED = self.old_enabled
+ def test_css_multiple_files_disabled_compression(self):
+ self.old_enabled = settings.COMPRESS_ENABLED
+ settings.COMPRESS_ENABLED = False
+ assert(settings.COMPRESS_PRECOMPILERS)
+ try:
+ template = u"""
+ {% load compress %}{% compress css %}
+ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/one.css"></link>
+ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/two.css"></link>
+ {% endcompress %}"""
+
+ out = '\n'.join([
+ '<link rel="stylesheet" type="text/css" href="/media/css/one.css" />',
+ '<link rel="stylesheet" type="text/css" href="/media/css/two.css" />'])
+
+ self.assertEqual(out, render(template, self.context))
+ finally:
+ settings.COMPRESS_ENABLED = self.old_enabled
+
+ def test_css_multiple_files_mixed_precompile_disabled_compression(self):
+ self.old_enabled = settings.COMPRESS_ENABLED
+ settings.COMPRESS_ENABLED = False
+ assert(settings.COMPRESS_PRECOMPILERS)
+ try:
+ template = u"""
+ {% load compress %}{% compress css %}
+ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/one.css"/>
+ <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/two.css"/>
+ <link rel="stylesheet" type="text/less" href="{{ MEDIA_URL }}css/url/test.css"/>
+ {% endcompress %}"""
+
+ out = '\n'.join([
+ '<link rel="stylesheet" type="text/css" href="/media/css/one.css" />',
+ '<link rel="stylesheet" type="text/css" href="/media/css/two.css" />',
+ '<link rel="stylesheet" href="/media/CACHE/css/test.c4f8a285c249.css" type="text/css" />'])
+ self.assertEqual(out, render(template, self.context))
+ finally:
+ settings.COMPRESS_ENABLED = self.old_enabled
+
def script(content="", src="", scripttype="text/javascript"):
"""
returns a unicode text html script element.
Something went wrong with that request. Please try again.