removed usage of JINJA2_FORCED

This commit is contained in:
Lucas Tan
2014-03-22 22:13:58 +08:00
parent e3e7a68d5b
commit 6413f43429
4 changed files with 8 additions and 9 deletions

View File

@@ -72,8 +72,6 @@ class CompressorConf(AppConf):
def JINJA2_GET_ENVIRONMENT():
import jinja2
return jinja2.Environment()
# Whether to force offline generation.
JINJA2_FORCED = False
class Meta:
prefix = 'compress'

View File

@@ -2,7 +2,6 @@ from jinja2 import nodes
from jinja2.ext import Extension
from jinja2.exceptions import TemplateSyntaxError
from compressor.conf import settings
from compressor.templatetags.compress import OUTPUT_FILE, CompressorMixin
@@ -35,12 +34,16 @@ class CompressorExtension(CompressorMixin, Extension):
# Skip the kind if used in the endblock, by using the kind in the
# endblock the templates are slightly more readable.
parser.stream.skip_if('name:' + kindarg.value)
return nodes.CallBlock(self.call_method('_compress', args), [], [],
return nodes.CallBlock(self.call_method('_compress_normal', args), [], [],
body).set_lineno(lineno)
def _compress(self, kind, mode, caller):
forced = settings.COMPRESS_JINJA2_FORCED
def _compress_forced(self, kind, mode, caller):
return self._compress(kind, mode, caller, True)
def _compress_normal(self, kind, mode, caller):
return self._compress(kind, mode, caller, False)
def _compress(self, kind, mode, caller, forced):
mode = mode or OUTPUT_FILE
original_content = caller()
context = {

View File

@@ -202,8 +202,6 @@ class Command(NoArgsCommand):
count = 0
results = []
offline_manifest = SortedDict()
old_forced = settings.COMPRESS_JINJA2_FORCED
settings.COMPRESS_JINJA2_FORCED = True
init_context = parser.get_init_context(settings.COMPRESS_OFFLINE_CONTEXT)
for template, nodes in compressor_nodes.items():
@@ -229,7 +227,6 @@ class Command(NoArgsCommand):
results.append(result)
count += 1
settings.COMPRESS_JINJA2_FORCED = old_forced
write_offline_manifest(offline_manifest)
log.write("done\nCompressed %d block(s) from %d template(s).\n" %

View File

@@ -119,6 +119,7 @@ class Jinja2Parser(object):
isinstance(node.call, Call) and
isinstance(node.call.node, ExtensionAttribute) and
node.call.node.identifier == self.COMPRESSOR_ID):
node.call.node.name = '_compress_forced'
yield node
else:
for node in self.walk_nodes(node, block_name=block_name):