Stop hardcoding the template names and provide an API for returning custom paths. Fixed #167.
This commit is contained in:
@@ -50,6 +50,18 @@ class Compressor(object):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
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):
|
def get_basename(self, url):
|
||||||
try:
|
try:
|
||||||
base_url = self.storage.base_url
|
base_url = self.storage.base_url
|
||||||
@@ -269,5 +281,5 @@ class Compressor(object):
|
|||||||
final_context = Context(self.context)
|
final_context = Context(self.context)
|
||||||
post_compress.send(sender=self.__class__, type=self.type,
|
post_compress.send(sender=self.__class__, type=self.type,
|
||||||
mode=mode, context=final_context)
|
mode=mode, context=final_context)
|
||||||
return render_to_string("compressor/%s_%s.html" %
|
template_name = self.get_template_name(mode)
|
||||||
(self.type, mode), final_context)
|
return render_to_string(template_name, final_context)
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ from compressor.exceptions import UncompressableFileError
|
|||||||
|
|
||||||
|
|
||||||
class CssCompressor(Compressor):
|
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):
|
def __init__(self, content=None, output_prefix="css", context=None):
|
||||||
super(CssCompressor, self).__init__(content=content,
|
super(CssCompressor, self).__init__(content=content,
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ from compressor.exceptions import UncompressableFileError
|
|||||||
|
|
||||||
|
|
||||||
class JsCompressor(Compressor):
|
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):
|
def __init__(self, content=None, output_prefix="js", context=None):
|
||||||
super(JsCompressor, self).__init__(content, output_prefix, context)
|
super(JsCompressor, self).__init__(content, output_prefix, context)
|
||||||
|
|||||||
@@ -207,7 +207,9 @@ class Command(NoArgsCommand):
|
|||||||
# above, so we need to catch that (and ignore it, just like above)
|
# above, so we need to catch that (and ignore it, just like above)
|
||||||
# as well.
|
# as well.
|
||||||
if verbosity > 0:
|
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
|
continue
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
context.push()
|
context.push()
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{# left fot backwards compatibility #}{% include "compressor/css_file.html" %}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{# left fot backwards compatibility #}{% include "compressor/js_file.html" %}
|
|
||||||
Reference in New Issue
Block a user