Skip to content

Commit

Permalink
Introduced a default extra_context dictionary.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Feb 16, 2011
1 parent bda59c0 commit 95da02a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions compressor/base.py
Expand Up @@ -13,6 +13,7 @@ class Compressor(object):

def __init__(self, content=None, output_prefix="compressed"):
self.content = content or ""
self.extra_context = {}
self.type = None
self.output_prefix = output_prefix
self.split_content = []
Expand Down Expand Up @@ -131,13 +132,17 @@ def save_file(self):
def output(self):
if not settings.COMPRESS_ENABLED:
return self.content
self.save_file()
context = getattr(self, 'extra_context', {})
context['url'] = self.storage.url(self.new_filepath)
context = {
"saved": self.save_file(),
"url": self.storage.url(self.new_filepath),
}
context.update(self.extra_context)
return render_to_string(self.template_name, context)

def output_inline(self):
context = {'content': settings.COMPRESS_ENABLED and self.combined or self.concat()}
if hasattr(self, 'extra_context'):
context.update(self.extra_context)
if settings.COMPRESS_ENABLED:
content = self.combined
else:
content = self.concat()
context = dict(content=content, **self.extra_context)
return render_to_string(self.template_name_inline, context)
2 changes: 1 addition & 1 deletion compressor/css.py
Expand Up @@ -49,6 +49,6 @@ def output(self):
return self.content
ret = []
for media, subnode in self.media_nodes:
subnode.extra_context = {'media': media}
subnode.extra_context.update({'media': media})
ret.append(subnode.output())
return ''.join(ret)

0 comments on commit 95da02a

Please sign in to comment.