Fix TemplateFilter breakage
Fixes #533. The problem was introduced in 09dc849, never got around
to fix it before :(
This commit is contained in:
@@ -276,7 +276,7 @@ class Compressor(object):
|
||||
except AttributeError:
|
||||
raise FilterDoesNotExist('Could not find "%s".' % filter_or_command)
|
||||
filter = precompiler_class(
|
||||
content, attrs, filter_type=self.type, charset=charset,
|
||||
content, attrs=attrs, filter_type=self.type, charset=charset,
|
||||
filename=filename)
|
||||
return True, filter.input(**kwargs)
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ class FilterBase(object):
|
||||
Subclasses should implement `input` and/or `output` methods which must
|
||||
return a string (unicode under python 2) or raise a NotImplementedError.
|
||||
"""
|
||||
def __init__(self, content, filter_type=None, filename=None, verbose=0,
|
||||
charset=None):
|
||||
def __init__(self, content, attrs=None, filter_type=None, filename=None,
|
||||
verbose=0, charset=None, **kwargs):
|
||||
self.type = filter_type or getattr(self, 'type', None)
|
||||
self.content = content
|
||||
self.verbose = verbose or settings.COMPRESS_VERBOSE
|
||||
@@ -118,8 +118,8 @@ class CompilerFilter(FilterBase):
|
||||
options = ()
|
||||
default_encoding = settings.FILE_CHARSET
|
||||
|
||||
def __init__(self, content, command=None, *args, **kwargs):
|
||||
super(CompilerFilter, self).__init__(content, *args, **kwargs)
|
||||
def __init__(self, content, command=None, **kwargs):
|
||||
super(CompilerFilter, self).__init__(content, **kwargs)
|
||||
self.cwd = None
|
||||
|
||||
if command:
|
||||
@@ -216,9 +216,9 @@ class CompilerFilter(FilterBase):
|
||||
|
||||
class CachedCompilerFilter(CompilerFilter):
|
||||
|
||||
def __init__(self, mimetype, **kwargs):
|
||||
def __init__(self, mimetype, *args, **kwargs):
|
||||
self.mimetype = mimetype
|
||||
super(CachedCompilerFilter, self).__init__(**kwargs)
|
||||
super(CachedCompilerFilter, self).__init__(*args, **kwargs)
|
||||
|
||||
def input(self, **kwargs):
|
||||
if self.mimetype in settings.COMPRESS_CACHEABLE_PRECOMPILERS:
|
||||
|
||||
@@ -282,6 +282,15 @@ class CompressorTestCase(SimpleTestCase):
|
||||
css_node = CssCompressor(css)
|
||||
self.assertRaises(FilterError, css_node.output, 'inline')
|
||||
|
||||
@override_settings(COMPRESS_PRECOMPILERS=(
|
||||
('text/django', 'compressor.filters.template.TemplateFilter'),
|
||||
), COMPRESS_ENABLED=True)
|
||||
def test_template_precompiler(self):
|
||||
css = '<style type="text/django">p { border:10px solid {% if 1 %}green{% else %}red{% endif %};}</style>'
|
||||
css_node = CssCompressor(css)
|
||||
output = make_soup(css_node.output('inline'))
|
||||
self.assertEqual(output.text, 'p { border:10px solid green;}')
|
||||
|
||||
|
||||
class CssMediaTestCase(SimpleTestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user