Esempio n. 1
0
 def pack(self, package):
     if (
         "output" not in package
         or "type" not in package
         or not package["output"]
         or not package["type"]
         or len(package["paths"]) == 0
     ):
         return ""
     if package["type"] == "css":
         compressor = CSSCompressor(self.verbose)
         signal = css_compressed
     else:
         compressor = JSCompressor(self.verbose)
         signal = js_compressed
     if settings.COMPRESS_AUTO or self.force:
         need_update, version = self.versioning.need_update(package["output"], package["paths"])
         if need_update or self.force:
             output_filename = self.versioning.output_filename(
                 package["output"], self.versioning.version(package["paths"])
             )
             self.versioning.cleanup(package["output"])
             if self.verbose or self.force:
                 print "Version: %s" % version
                 print "Saving: %s" % make_relative_path(output_filename)
             paths = self.compile(package["paths"])
             content = compressor.compress(paths)
             if not self.save_file(output_filename, content):
                 return ""
             signal.send(sender=self, package=package, version=version)
     else:
         filename_base, filename = os.path.split(package["output"])
         version = self.versioning.version_from_file(filename_base, filename)
     return self.versioning.output_filename(package["output"], version)
Esempio n. 2
0
 def test_css_concatenate(self):
     settings.COMPRESS_CSS_COMPRESSORS = []
     settings.COMPRESS_ROOT = os.path.join(os.path.dirname(__file__),
                                           "testdata/")
     compressor = CSSCompressor()
     output = compressor.compress(css_list)
     test_file = open(
         os.path.join(settings.COMPRESS_ROOT, 'css/results1.css'), 'rb')
     self.assertEqual(test_file.read().decode('utf8'), output)
     test_file.close()
Esempio n. 3
0
 def test_css_concatenate(self):
     settings.COMPRESS_CSS_COMPRESSORS = []
     settings.COMPRESS_ROOT = os.path.join(os.path.dirname(__file__),
                                           "testdata/")
     compressor = CSSCompressor()
     output = compressor.compress(css_list)
     test_file = open(os.path.join(settings.COMPRESS_ROOT,
                           'css/results1.css'), 'rb')
     self.assertEqual(test_file.read().decode('utf8'), output)
     test_file.close()
Esempio n. 4
0
 def test_csstidy(self):
     tidy = glob.glob(settings.COMPRESS_CSSTIDY_BINARY)
     if tidy:
         settings.COMPRESS_CSS_COMPRESSORS = [
           'compress.compressors.csstidy.CSSTidyCompressor']
         compressor = CSSCompressor()
         output = compressor.compress(css_list)
         test_file = open(os.path.join(settings.COMPRESS_ROOT,
                                'css/results_tidy.css'), 'rb')
         self.assertEqual(test_file.read().decode('utf8'), output)
         test_file.close()
Esempio n. 5
0
 def test_csstidy(self):
     tidy = glob.glob(settings.COMPRESS_CSSTIDY_BINARY)
     if tidy:
         settings.COMPRESS_CSS_COMPRESSORS = [
             'compress.compressors.csstidy.CSSTidyCompressor'
         ]
         compressor = CSSCompressor()
         output = compressor.compress(css_list)
         test_file = open(
             os.path.join(settings.COMPRESS_ROOT, 'css/results_tidy.css'),
             'rb')
         self.assertEqual(test_file.read().decode('utf8'), output)
         test_file.close()