Beispiel #1
0
 def test_precompiler_infile_outfile(self):
     command = '%s %s -f {infile} -o {outfile}' % (sys.executable,
                                                   self.test_precompiler)
     compiler = CompilerFilter(content=self.content,
                               filename=self.filename,
                               charset=self.CHARSET,
                               command=command)
     self.assertEqual("body { color:#990; }", compiler.input())
Beispiel #2
0
 def test_precompiler_stdin_stdout(self):
     command = '%s %s' % (sys.executable, self.test_precompiler)
     compiler = CompilerFilter(content=self.content,
                               filename=None,
                               charset=None,
                               command=command)
     self.assertEqual("body { color:#990; }%s" % os.linesep,
                      compiler.input())
Beispiel #3
0
 def test_precompiler_infile_with_spaces(self):
     self.setup_infile('static/css/filename with spaces.css')
     command = '%s %s -f {infile} -o {outfile}' % (sys.executable,
                                                   self.test_precompiler)
     compiler = CompilerFilter(content=self.content,
                               filename=self.filename,
                               charset=self.CHARSET,
                               command=command)
     self.assertEqual("body { color:#424242; }", compiler.input())
Beispiel #4
0
    def precompile(self,
                   content,
                   kind=None,
                   elem=None,
                   filename=None,
                   charset=None,
                   **kwargs):
        """
        Processes file using a pre compiler.

        This is the place where files like coffee script are processed.
        """
        if not kind:
            return False, content
        attrs = self.parser.elem_attribs(elem)
        mimetype = attrs.get("type", None)
        if mimetype:
            filter_or_command = self.all_mimetypes.get(mimetype)
            if filter_or_command is None:
                if mimetype not in ("text/css", "text/javascript"):
                    raise CompressorError("Couldn't find any precompiler in "
                                          "COMPRESS_PRECOMPILERS setting for "
                                          "mimetype '%s'." % mimetype)
            else:
                mod_name, cls_name = get_mod_func(filter_or_command)
                try:
                    mod = import_module(mod_name)
                except (ImportError, TypeError):
                    filter = CompilerFilter(content,
                                            filter_type=self.type,
                                            filename=filename,
                                            charset=charset,
                                            command=filter_or_command)
                    return True, filter.input(**kwargs)
                try:
                    precompiler_class = getattr(mod, cls_name)
                except AttributeError:
                    raise FilterDoesNotExist('Could not find "%s".' %
                                             filter_or_command)
                else:
                    filter = precompiler_class(content,
                                               attrs,
                                               filter_type=self.type,
                                               charset=charset,
                                               filename=filename)
                    return True, filter.input(**kwargs)

        return False, content
Beispiel #5
0
 def test_precompiler_dict_options(self):
     command = "%s %s {option}" % (sys.executable, self.test_precompiler)
     option = (
         "option",
         "option",
     )
     CompilerFilter.options = dict([option])
     compiler = CompilerFilter(content=self.content,
                               filename=self.filename,
                               charset=self.CHARSET,
                               command=command)
     self.assertIn(option, compiler.options)
Beispiel #6
0
    def precompile(self, content, kind=None, elem=None, filename=None,
                   charset=None, **kwargs):
        """
        Processes file using a pre compiler.

        This is the place where files like coffee script are processed.
        """
        if not kind:
            return False, content
        attrs = self.parser.elem_attribs(elem)
        mimetype = attrs.get("type", None)
        if mimetype:
            filter_or_command = self.all_mimetypes.get(mimetype)
            if filter_or_command is None:
                if mimetype not in ("text/css", "text/javascript"):
                    raise CompressorError("Couldn't find any precompiler in "
                                          "COMPRESS_PRECOMPILERS setting for "
                                          "mimetype '%s'." % mimetype)
            else:
                mod_name, cls_name = get_mod_func(filter_or_command)
                try:
                    mod = import_module(mod_name)
                except ImportError:
                    filter = CompilerFilter(
                        content, filter_type=self.type, filename=filename,
                        charset=charset, command=filter_or_command)
                    return True, filter.input(**kwargs)
                try:
                    precompiler_class = getattr(mod, cls_name)
                except AttributeError:
                    raise FilterDoesNotExist('Could not find "%s".' %
                            filter_or_command)
                else:
                    filter = precompiler_class(
                        content, attrs, filter_type=self.type, charset=charset,
                        filename=filename)
                    return True, filter.input(**kwargs)

        return False, content
Beispiel #7
0
 def precompile(self, content, kind=None, elem=None, filename=None, **kwargs):
     if not kind:
         return False, content
     attrs = self.parser.elem_attribs(elem)
     mimetype = attrs.get("type", None)
     if mimetype:
         command = self.all_mimetypes.get(mimetype)
         if command is None:
             if mimetype not in ("text/css", "text/javascript"):
                 raise CompressorError("Couldn't find any precompiler in "
                                       "COMPRESS_PRECOMPILERS setting for "
                                       "mimetype '%s'." % mimetype)
         else:
             return True, CompilerFilter(content, filter_type=self.type,
                 command=command, filename=filename).input(**kwargs)
     return False, content
Beispiel #8
0
 def test_precompiler_output_unicode(self):
     command = '%s %s' % (sys.executable, self.test_precompiler)
     compiler = CompilerFilter(content=self.content,
                               filename=self.filename,
                               command=command)
     self.assertEqual(type(compiler.input()), str)