Introduced a default extra_context dictionary.
This commit is contained in:
@@ -13,6 +13,7 @@ class Compressor(object):
|
|||||||
|
|
||||||
def __init__(self, content=None, output_prefix="compressed"):
|
def __init__(self, content=None, output_prefix="compressed"):
|
||||||
self.content = content or ""
|
self.content = content or ""
|
||||||
|
self.extra_context = {}
|
||||||
self.type = None
|
self.type = None
|
||||||
self.output_prefix = output_prefix
|
self.output_prefix = output_prefix
|
||||||
self.split_content = []
|
self.split_content = []
|
||||||
@@ -131,13 +132,17 @@ class Compressor(object):
|
|||||||
def output(self):
|
def output(self):
|
||||||
if not settings.COMPRESS_ENABLED:
|
if not settings.COMPRESS_ENABLED:
|
||||||
return self.content
|
return self.content
|
||||||
self.save_file()
|
context = {
|
||||||
context = getattr(self, 'extra_context', {})
|
"saved": self.save_file(),
|
||||||
context['url'] = self.storage.url(self.new_filepath)
|
"url": self.storage.url(self.new_filepath),
|
||||||
|
}
|
||||||
|
context.update(self.extra_context)
|
||||||
return render_to_string(self.template_name, context)
|
return render_to_string(self.template_name, context)
|
||||||
|
|
||||||
def output_inline(self):
|
def output_inline(self):
|
||||||
context = {'content': settings.COMPRESS_ENABLED and self.combined or self.concat()}
|
if settings.COMPRESS_ENABLED:
|
||||||
if hasattr(self, 'extra_context'):
|
content = self.combined
|
||||||
context.update(self.extra_context)
|
else:
|
||||||
|
content = self.concat()
|
||||||
|
context = dict(content=content, **self.extra_context)
|
||||||
return render_to_string(self.template_name_inline, context)
|
return render_to_string(self.template_name_inline, context)
|
||||||
|
|||||||
@@ -49,6 +49,6 @@ class CssCompressor(Compressor):
|
|||||||
return self.content
|
return self.content
|
||||||
ret = []
|
ret = []
|
||||||
for media, subnode in self.media_nodes:
|
for media, subnode in self.media_nodes:
|
||||||
subnode.extra_context = {'media': media}
|
subnode.extra_context.update({'media': media})
|
||||||
ret.append(subnode.output())
|
ret.append(subnode.output())
|
||||||
return ''.join(ret)
|
return ''.join(ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user