Skip to content
Browse files

Stop hardcoding the template names and provide an API for returning c…

…ustom paths. Fixed #167.
  • Loading branch information...
1 parent 35eaaf3 commit 399585103ec7424034271794878049666f94fb0d @jezdez jezdez committed
View
16 compressor/base.py
@@ -50,6 +50,18 @@ def split_contents(self):
"""
raise NotImplementedError
+ def get_template_name(self, mode):
+ """
+ Returns the template path for the given mode.
+ """
+ try:
+ template = getattr(self, "template_name_%s" % mode)
+ if template:
+ return template
+ except AttributeError:
+ pass
+ return "compressor/%s_%s.html" % (self.type, mode)
+
def get_basename(self, url):
try:
base_url = self.storage.base_url
@@ -269,5 +281,5 @@ def render_output(self, mode, context=None):
final_context = Context(self.context)
post_compress.send(sender=self.__class__, type=self.type,
mode=mode, context=final_context)
- return render_to_string("compressor/%s_%s.html" %
- (self.type, mode), final_context)
+ template_name = self.get_template_name(mode)
+ return render_to_string(template_name, final_context)
View
2 compressor/css.py
@@ -4,8 +4,6 @@
class CssCompressor(Compressor):
- template_name = "compressor/css.html"
- template_name_inline = "compressor/css_inline.html"
def __init__(self, content=None, output_prefix="css", context=None):
super(CssCompressor, self).__init__(content=content,
View
2 compressor/js.py
@@ -4,8 +4,6 @@
class JsCompressor(Compressor):
- template_name = "compressor/js.html"
- template_name_inline = "compressor/js_inline.html"
def __init__(self, content=None, output_prefix="js", context=None):
super(JsCompressor, self).__init__(content, output_prefix, context)
View
4 compressor/management/commands/compress.py
@@ -207,7 +207,9 @@ def compress(self, log=None, **options):
# above, so we need to catch that (and ignore it, just like above)
# as well.
if verbosity > 0:
- log.write("Caught error when rendering extend node from template %s\n" % template.template_name)
+ log.write("Caught error when rendering extend node "
+ "from template %s\n" %
+ template.template_name)
continue
for node in nodes:
context.push()
View
1 compressor/templates/compressor/css.html
@@ -1 +0,0 @@
-{# left fot backwards compatibility #}{% include "compressor/css_file.html" %}
View
1 compressor/templates/compressor/js.html
@@ -1 +0,0 @@
-{# left fot backwards compatibility #}{% include "compressor/js_file.html" %}

0 comments on commit 3995851

Please sign in to comment.
Something went wrong with that request. Please try again.