Ensure hunks are filtered when compression is forced

This commit is contained in:
Ben Firshman
2011-09-22 21:17:55 +01:00
committed by Jannis Leidel
parent ecdd5ecbc7
commit a9461cc869

View File

@@ -114,14 +114,14 @@ class Compressor(object):
[self.content] + self.mtimes).encode(self.charset), 12) [self.content] + self.mtimes).encode(self.charset), 12)
@memoize @memoize
def hunks(self, mode='file'): def hunks(self, mode='file', forced=False):
""" """
The heart of content parsing, iterates of the The heart of content parsing, iterates of the
list of split contents and looks at its kind list of split contents and looks at its kind
to decide what to do with it. Should yield a to decide what to do with it. Should yield a
bunch of precompiled and/or rendered hunks. bunch of precompiled and/or rendered hunks.
""" """
enabled = settings.COMPRESS_ENABLED enabled = settings.COMPRESS_ENABLED or forced
for kind, value, basename, elem in self.split_contents(): for kind, value, basename, elem in self.split_contents():
precompiled = False precompiled = False
@@ -160,14 +160,14 @@ class Compressor(object):
return self.filter(content, method=METHOD_OUTPUT) return self.filter(content, method=METHOD_OUTPUT)
@memoize @memoize
def filtered_input(self, mode='file'): def filtered_input(self, mode='file', forced=False):
""" """
Passes each hunk (file or code) to the 'input' methods Passes each hunk (file or code) to the 'input' methods
of the compressor filters. of the compressor filters.
""" """
verbatim_content = [] verbatim_content = []
rendered_content = [] rendered_content = []
for mode, hunk in self.hunks(mode): for mode, hunk in self.hunks(mode, forced):
if mode == 'verbatim': if mode == 'verbatim':
verbatim_content.append(hunk) verbatim_content.append(hunk)
else: else:
@@ -208,7 +208,7 @@ class Compressor(object):
any custom modification. Calls other mode specific methods or simply any custom modification. Calls other mode specific methods or simply
returns the content directly. returns the content directly.
""" """
verbatim_content, rendered_content = self.filtered_input(mode) verbatim_content, rendered_content = self.filtered_input(mode, forced)
if not verbatim_content and not rendered_content: if not verbatim_content and not rendered_content:
return '' return ''