Exemplo n.º 1
0
    def _minify(self, file_type, files, position, out):

        cache = Env.get('cache_dir')
        out_name = 'minified_' + out
        out = os.path.join(cache, out_name)

        raw = []
        for file_path in files:
            f = open(file_path, 'r').read()

            if file_type == 'script':
                data = jsmin(f)
            else:
                data = cssmin(f)
                data = data.replace('../images/', '../static/images/')

            raw.append({'file': file_path, 'date': int(os.path.getmtime(file_path)), 'data': data})

        # Combine all files together with some comments
        data = ''
        for r in raw:
            data += self.comment.get(file_type) % (r.get('file'), r.get('date'))
            data += r.get('data') + '\n\n'

        self.createFile(out, data.strip())

        if not self.minified.get(file_type):
            self.minified[file_type] = {}
        if not self.minified[file_type].get(position):
            self.minified[file_type][position] = []

        minified_url = 'api/%s/file.cache/%s?%s' % (Env.setting('api_key'), out_name, tryInt(os.path.getmtime(out)))
        self.minified[file_type][position].append(minified_url)
Exemplo n.º 2
0
    def _minify(self, file_type, files, position, out):

        cache = Env.get('cache_dir')
        out_name = out
        out = os.path.join(cache, 'minified', out_name)

        raw = []
        for file_path in files:
            f = open(file_path, 'r').read()

            if file_type == 'script':
                data = jsmin(f)
            else:
                data = self.prefix(f)
                data = cssmin(data)
                data = data.replace('../images/', '../static/images/')
                data = data.replace('../fonts/', '../static/fonts/')
                data = data.replace('../../static/',
                                    '../static/')  # Replace inside plugins

            raw.append({
                'file': file_path,
                'date': int(os.path.getmtime(file_path)),
                'data': data
            })

        # Combine all files together with some comments
        data = ''
        for r in raw:
            data += self.comment.get(file_type) % (ss(
                r.get('file')), r.get('date'))
            data += r.get('data') + '\n\n'

        self.createFile(out, data.strip())

        if not self.minified.get(file_type):
            self.minified[file_type] = {}
        if not self.minified[file_type].get(position):
            self.minified[file_type][position] = []

        minified_url = 'minified/%s?%s' % (out_name,
                                           tryInt(os.path.getmtime(out)))
        self.minified[file_type][position].append(minified_url)
Exemplo n.º 3
0
    def _minify(self, file_type, files, position, out):

        cache = Env.get("cache_dir")
        out_name = out
        out = os.path.join(cache, "minified", out_name)

        raw = []
        for file_path in files:
            f = open(file_path, "r").read()

            if file_type == "script":
                data = jsmin(f)
            else:
                data = self.prefix(f)
                data = cssmin(data)
                data = data.replace("../images/", "../static/images/")
                data = data.replace("../fonts/", "../static/fonts/")
                data = data.replace("../../static/", "../static/")  # Replace inside plugins

            raw.append({"file": file_path, "date": int(os.path.getmtime(file_path)), "data": data})

        # Combine all files together with some comments
        data = ""
        for r in raw:
            data += self.comment.get(file_type) % (ss(r.get("file")), r.get("date"))
            data += r.get("data") + "\n\n"

        self.createFile(out, data.strip())

        if not self.minified.get(file_type):
            self.minified[file_type] = {}
        if not self.minified[file_type].get(position):
            self.minified[file_type][position] = []

        minified_url = "minified/%s?%s" % (out_name, tryInt(os.path.getmtime(out)))
        self.minified[file_type][position].append(minified_url)