More constants.
This commit is contained in:
@@ -14,6 +14,7 @@ from compressor.utils.decorators import cached_property
|
|||||||
|
|
||||||
# Some constants for nicer handling.
|
# Some constants for nicer handling.
|
||||||
SOURCE_HUNK, SOURCE_FILE = 1, 2
|
SOURCE_HUNK, SOURCE_FILE = 1, 2
|
||||||
|
METHOD_INPUT, METHOD_OUTPUT = 'input', 'output'
|
||||||
|
|
||||||
|
|
||||||
class Compressor(object):
|
class Compressor(object):
|
||||||
@@ -83,7 +84,7 @@ class Compressor(object):
|
|||||||
def mtimes(self):
|
def mtimes(self):
|
||||||
return [str(get_mtime(value))
|
return [str(get_mtime(value))
|
||||||
for kind, value, basename, elem in self.split_contents()
|
for kind, value, basename, elem in self.split_contents()
|
||||||
if kind == 'file']
|
if kind == SOURCE_FILE]
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def cachekey(self):
|
def cachekey(self):
|
||||||
@@ -95,7 +96,7 @@ class Compressor(object):
|
|||||||
def hunks(self):
|
def hunks(self):
|
||||||
for kind, value, basename, elem in self.split_contents():
|
for kind, value, basename, elem in self.split_contents():
|
||||||
if kind == SOURCE_HUNK:
|
if kind == SOURCE_HUNK:
|
||||||
content = self.filter(value, "input",
|
content = self.filter(value, METHOD_INPUT,
|
||||||
elem=elem, kind=kind, basename=basename)
|
elem=elem, kind=kind, basename=basename)
|
||||||
yield unicode(content)
|
yield unicode(content)
|
||||||
elif kind == SOURCE_FILE:
|
elif kind == SOURCE_FILE:
|
||||||
@@ -108,7 +109,7 @@ class Compressor(object):
|
|||||||
"IOError while processing '%s': %s" % (value, e))
|
"IOError while processing '%s': %s" % (value, e))
|
||||||
finally:
|
finally:
|
||||||
fd.close()
|
fd.close()
|
||||||
content = self.filter(content, "input",
|
content = self.filter(content, METHOD_INPUT,
|
||||||
filename=value, basename=basename, elem=elem, kind=kind)
|
filename=value, basename=basename, elem=elem, kind=kind)
|
||||||
attribs = self.parser.elem_attribs(elem)
|
attribs = self.parser.elem_attribs(elem)
|
||||||
charset = attribs.get("charset", self.charset)
|
charset = attribs.get("charset", self.charset)
|
||||||
@@ -138,7 +139,7 @@ class Compressor(object):
|
|||||||
|
|
||||||
def filter(self, content, method, **kwargs):
|
def filter(self, content, method, **kwargs):
|
||||||
# run compiler
|
# run compiler
|
||||||
if method == "input":
|
if method == METHOD_INPUT:
|
||||||
content = self.precompile(content, **kwargs)
|
content = self.precompile(content, **kwargs)
|
||||||
|
|
||||||
for filter_cls in self.cached_filters:
|
for filter_cls in self.cached_filters:
|
||||||
@@ -153,10 +154,10 @@ class Compressor(object):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def combined(self):
|
def combined(self):
|
||||||
return self.filter(self.concat, method="output")
|
|
||||||
|
|
||||||
def hash(self, content):
|
def hash(self, content):
|
||||||
return get_hexdigest(content)[:12]
|
return get_hexdigest(content)[:12]
|
||||||
|
return self.filter(self.concat, method=METHOD_OUTPUT)
|
||||||
|
|
||||||
def filepath(self, content):
|
def filepath(self, content):
|
||||||
return os.path.join(settings.COMPRESS_OUTPUT_DIR.strip(os.sep),
|
return os.path.join(settings.COMPRESS_OUTPUT_DIR.strip(os.sep),
|
||||||
|
|||||||
Reference in New Issue
Block a user