Example #1
0
 def compile_templates(self, paths):
     compiled = ""
     if not paths:
         return compiled
     namespace = settings.PIPELINE_TEMPLATE_NAMESPACE
     base_path = self.base_path(paths)
     for path in paths:
         contents = self.read_file(path)
         if settings.PIPELINE_TEMPLATE_TRANSLATOR:
             translator = to_class(settings.PIPELINE_TEMPLATE_TRANSLATOR)
             if translator:
                 translator = translator(contents)
                 contents = translator.translate_content()
         contents = re.sub(r"\r?\n", "\\\\n", contents)
         contents = re.sub(r"'", "\\'", contents)
         name = self.template_name(path, base_path)
         compiled += "%s['%s'] = %s('%s');\n" % (
             namespace,
             name,
             settings.PIPELINE_TEMPLATE_FUNC,
             contents
         )
     compiler = TEMPLATE_FUNC if settings.PIPELINE_TEMPLATE_FUNC == DEFAULT_TEMPLATE_FUNC else ""
     return "\n".join([
         "%(namespace)s = %(namespace)s || {};" % {'namespace': namespace},
         compiler,
         compiled
     ])
Example #2
0
 def _test_compiler(self, compiler_cls_str, infile, expected):
     compiler_cls = to_class(compiler_cls_str)
     compiler = compiler_cls(verbose=False, storage=staticfiles_storage)
     infile_path = staticfiles_storage.path(infile)
     outfile_path = compiler.output_path(infile_path, compiler.output_extension)
     compiler.compile_file(_(infile_path), _(outfile_path), force=True)
     with open(outfile_path) as f:
         result = f.read()
     with staticfiles_storage.open(expected) as f:
         expected = f.read()
     self.assertEqual(smart_bytes(result), expected)
Example #3
0
 def css_compressor(self):
     return to_class(settings.PIPELINE_CSS_COMPRESSOR)
Example #4
0
 def compilers(self):
     return [to_class(compiler) for compiler in settings.PIPELINE_COMPILERS]
Example #5
0
 def precompilers(self):
     return [to_class(precompiler) for precompiler in settings.PIPELINE_PRECOMPILERS]
 def js_compressor(self):
     return to_class(settings.JS_COMPRESSOR)
Example #7
0
 def versioner(self):
     return to_class(settings.PIPELINE_VERSIONING)(self)