Commit 9779559a by Timothée Peignier

Merge pull request #120 from pdr/master

make embed max size and embed path configurable
parents 2fe0dad3 d892b009
...@@ -188,6 +188,23 @@ Images and fonts are embedded following these rules : ...@@ -188,6 +188,23 @@ Images and fonts are embedded following these rules :
at all in Internet Explorer 8. at all in Internet Explorer 8.
- If asset path contains a directory named "**embed**". - If asset path contains a directory named "**embed**".
You can override these rules using the following settings:
``PIPELINE_EMBED_MAX_IMAGE_SIZE``
..........................
Setting that controls the maximum image size (in bytes) to embed in CSS using Data-URIs.
Internet Explorer 8 has issues with assets under 32 kilobytes.
Defaults to ``32700``
``PIPELINE_EMBED_PATH``
..........................
Setting the directory that an asset needs to be in so that it is embedded
Defaults to ``r'[/]?embed/'``
Rewriting CSS urls Rewriting CSS urls
================== ==================
......
...@@ -16,9 +16,6 @@ from pipeline.conf import settings ...@@ -16,9 +16,6 @@ from pipeline.conf import settings
from pipeline.utils import to_class, relpath from pipeline.utils import to_class, relpath
from pipeline.storage import default_storage from pipeline.storage import default_storage
MAX_IMAGE_SIZE = 32700
EMBEDDABLE = r'[/]?embed/'
URL_DETECTOR = r'url\([\'"]?([^\s)]+\.[a-z]+[\?\#\d\w]*)[\'"]?\)' URL_DETECTOR = r'url\([\'"]?([^\s)]+\.[a-z]+[\?\#\d\w]*)[\'"]?\)'
URL_REPLACER = r'url\(__EMBED__(.+?)(\?\d+)?\)' URL_REPLACER = r'url\(__EMBED__(.+?)(\?\d+)?\)'
...@@ -157,13 +154,14 @@ class Compressor(object): ...@@ -157,13 +154,14 @@ class Compressor(object):
"""Is the asset embeddable ?""" """Is the asset embeddable ?"""
name, ext = os.path.splitext(path) name, ext = os.path.splitext(path)
font = ext in FONT_EXTS font = ext in FONT_EXTS
if not variant: if not variant:
return False return False
if not (re.search(EMBEDDABLE, path) and self.storage.exists(path)): if not (re.search(settings.PIPELINE_EMBED_PATH, path) and self.storage.exists(path)):
return False return False
if not ext in EMBED_EXTS: if not ext in EMBED_EXTS:
return False return False
if not (font or len(self.encoded_content(path)) < MAX_IMAGE_SIZE): if not (font or len(self.encoded_content(path)) < settings.PIPELINE_EMBED_MAX_IMAGE_SIZE):
return False return False
return True return True
......
from django.conf import settings from django.conf import settings
PIPELINE = getattr(settings, 'PIPELINE', not settings.DEBUG) PIPELINE = getattr(settings, 'PIPELINE', not settings.DEBUG)
PIPELINE_ROOT = getattr(settings, 'PIPELINE_ROOT', settings.STATIC_ROOT) PIPELINE_ROOT = getattr(settings, 'PIPELINE_ROOT', settings.STATIC_ROOT)
PIPELINE_URL = getattr(settings, 'PIPELINE_URL', settings.STATIC_URL) PIPELINE_URL = getattr(settings, 'PIPELINE_URL', settings.STATIC_URL)
...@@ -56,5 +55,8 @@ PIPELINE_MIMETYPES = getattr(settings, 'PIPELINE_MIMETYPES', ( ...@@ -56,5 +55,8 @@ PIPELINE_MIMETYPES = getattr(settings, 'PIPELINE_MIMETYPES', (
('text/javascript', '.js') ('text/javascript', '.js')
)) ))
PIPELINE_EMBED_MAX_IMAGE_SIZE = getattr(settings, 'PIPELINE_EMBED_MAX_IMAGE_SIZE', 32700)
PIPELINE_EMBED_PATH = getattr(settings, 'PIPELINE_EMBED_PATH', r'[/]?embed/')
if PIPELINE_COMPILERS is None: if PIPELINE_COMPILERS is None:
PIPELINE_COMPILERS = [] PIPELINE_COMPILERS = []
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