Commit 4bac1a4d by Timothée Peignier

remove mhtml embedding

parent 273d0abd
......@@ -67,8 +67,8 @@ Group options
**Optional**
Is the variant you want to apply to your CSS. This allow you to embed images
and fonts in CSS with data-URI or MHTML.
Allowed values are : ``None``, ``datauri`` or ``mhtml``.
and fonts in CSS with data-URI.
Allowed values are : ``None`` and ``datauri``.
Defaults to ``None``.
......@@ -182,7 +182,7 @@ Embedding fonts and images
==========================
You can embed fonts and images directly in your compiled css, using Data-URI in
modern browser or MHTML in Internet Explorer 7 or below.
modern browser.
To do so, setup variant group options to the method you wish to use : ::
......
......@@ -15,10 +15,6 @@ EMBEDDABLE = r'[/]?embed/'
URL_DETECTOR = r'url\([\'"]?([^\s)]+\.[a-z]+[\?\#\d\w]*)[\'"]?\)'
URL_REPLACER = r'url\(__EMBED__(.+?)(\?\d+)?\)'
MHTML_START = "/*\r\nContent-Type: multipart/related; boundary=\"MHTML_MARK\"\r\n\r\n"
MHTML_SEPARATOR = "--MHTML_MARK\r\n"
MHTML_END = "\r\n--MHTML_MARK--\r\n*/\r\n"
DEFAULT_TEMPLATE_FUNC = "template"
TEMPLATE_FUNC = """var template = function(str){var fn = new Function('obj', 'var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(\''+str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/<%=([\s\S]+?)%>/g,function(match,code){return "',"+code.replace(/\\'/g, "'")+",'";}).replace(/<%([\s\S]+?)%>/g,function(match,code){return "');"+code.replace(/\\'/g, "'").replace(/[\r\n\t]/g,' ')+"__p.push('";}).replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+"');}return __p.join('');");return fn;};"""
......@@ -52,7 +48,7 @@ class Compressor(object):
return to_class(settings.PIPELINE_CSS_COMPRESSOR)
css_compressor = property(css_compressor)
def compress_js(self, paths, templates=None, asset_url=None, **kwargs):
def compress_js(self, paths, templates=None, **kwargs):
"""Concatenate and compress JS files"""
js = self.concatenate(paths)
if templates:
......@@ -65,8 +61,7 @@ class Compressor(object):
return js
def compress_css(self, paths, variant=None, asset_url=None,
absolute_paths=True, **kwargs):
def compress_css(self, paths, variant=None, absolute_paths=True, **kwargs):
"""Concatenate and compress CSS files"""
css = self.concatenate_and_rewrite(paths, variant,
absolute_paths)
......@@ -77,8 +72,6 @@ class Compressor(object):
return css
elif variant == "datauri":
return self.with_data_uri(css)
elif variant == "mhtml":
return self.with_mhtml(css, asset_url)
else:
raise CompressorError("\"%s\" is not a valid variant" % variant)
......@@ -176,29 +169,6 @@ class Compressor(object):
return "url(\"data:%s;charset=utf-8;base64,%s\")" % (mime_type, data)
return re.sub(URL_REPLACER, datauri, css)
def with_mhtml(self, css, asset_url):
paths = {}
def mhtml(match):
path = match.group(1)
if not path in paths:
paths[path] = "%s-%s" % (match.start(), os.path.basename(path))
return "url(mhtml:%s!%s)" % (asset_url, paths[path])
css = re.sub(URL_REPLACER, mhtml, css)
mhtml = []
for path, location in paths.items():
mime_type = self.mime_type(path)
data = self.encoded_content(path)
mhtml.extend([
MHTML_SEPARATOR,
"Content-Location: %s\r\n" % location,
"Content-Type: %s\r\n" % mime_type,
"Content-Transfer-Encoding: base64\r\n\r\n",
data,
"\r\n"
])
output = [MHTML_START, mhtml, MHTML_END, css]
return ''.join([part for parts in output for part in parts])
def encoded_content(self, path):
"""Return the base64 encoded contents"""
if path in self.__class__.asset_contents:
......
......@@ -101,8 +101,7 @@ class Packager(object):
if self.verbose:
print "Saving: %s" % output_filename
paths = self.compile(package.paths)
content = compress(paths,
asset_url=self.individual_url(output_filename), **kwargs)
content = compress(paths, **kwargs)
self.save_file(output_filename, content)
signal.send(sender=self, package=package, **kwargs)
return output_filename
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment