Esempio n. 1
0
def inline_css(bundle, media=False, debug=None):
    """
    If we are in debug mode, just output a single style tag for each css file.
    If we are not in debug mode, return a style that contains bundle-min.css.
    Forces a regular css() call for external URLs (no inline allowed).

    Extracted from jingo-minify and re-registered, see:
    https://github.com/jsocol/jingo-minify/pull/41
    Added: turns relative links to absolute ones using STATIC_URL.
    """
    if debug is None:
        debug = getattr(settings, "TEMPLATE_DEBUG", False)

    if debug:
        items = [_get_compiled_css_url(i) for i in settings.MINIFY_BUNDLES["css"][bundle]]
    else:
        items = ["css/%s-min.css" % bundle]

    if not media:
        media = getattr(settings, "CSS_MEDIA_DEFAULT", "screen,projection,tv")

    contents = []
    for css in items:
        if is_external(css):
            return _build_html([css], '<link rel="stylesheet" media="%s" ' 'href="%%s" />' % media)
        with open(get_path(css), "r") as f:
            css_content = f.read()
            css_parsed = re.sub(r"url\(([^)]*?)\)", _relative_to_absolute, css_content)
            contents.append(css_parsed)

    return _build_html(contents, '<style type="text/css" media="%s">%%s' "</style>" % media)
Esempio n. 2
0
def inline_css(bundle, media=False, debug=None):
    """
    If we are in debug mode, just output a single style tag for each css file.
    If we are not in debug mode, return a style that contains bundle-min.css.
    Forces a regular css() call for external URLs (no inline allowed).

    Extracted from jingo-minify and re-registered, see:
    https://github.com/jsocol/jingo-minify/pull/41
    Added: turns relative links to absolute ones using STATIC_URL.
    """
    if debug is None:
        debug = getattr(settings, 'TEMPLATE_DEBUG', False)

    if debug:
        items = [
            _get_compiled_css_url(i)
            for i in settings.MINIFY_BUNDLES['css'][bundle]
        ]
    else:
        items = ['css/%s-min.css' % bundle]

    if not media:
        media = getattr(settings, 'CSS_MEDIA_DEFAULT', 'screen,projection,tv')

    contents = []
    for css in items:
        if is_external(css):
            return _build_html([css], '<link rel="stylesheet" media="%s" '
                               'href="%%s" />' % media)
        with open(get_path(css), 'r') as f:
            css_content = f.read()
            css_parsed = re.sub(r'url\(([^)]*?)\)', _relative_to_absolute,
                                css_content)
            contents.append(css_parsed)

    return _build_html(
        contents, '<style type="text/css" media="%s">%%s'
        '</style>' % media)
Esempio n. 3
0
    def _zamboni_qunit(request, path, template):
        from time import time
        import django_qunit.views
        import jingo
        import mock

        # Patch `js` so that CI gets cache-busted JS with TEMPLATE_DEBUG=True.
        # (This will be fixed in `jingo-minify` with bug 717094.)
        from jingo_minify.helpers import _build_html
        import jinja2
        def js(bundle, defer=False, async=False):
            items = settings.MINIFY_BUNDLES['js'][bundle]
            attrs = ['src="%s?v=%s"' % ('%s', time())]
            if defer:
                attrs.append('defer')
            if async:
                attrs.append('async')
            string = '<script %s></script>' % ' '.join(attrs)
            return _build_html(items, string)
Esempio n. 4
0
    def _zamboni_qunit(request, path, template):
        from time import time
        import django_qunit.views
        import jingo
        import mock

        # Patch `js` so that CI gets cache-busted JS with TEMPLATE_DEBUG=True.
        # (This will be fixed in `jingo-minify` with bug 717094.)
        from jingo_minify.helpers import _build_html
        import jinja2

        def js(bundle, defer=False, async=False):
            items = settings.MINIFY_BUNDLES['js'][bundle]
            attrs = ['src="%s?v=%s"' % ('%s', time())]
            if defer:
                attrs.append('defer')
            if async:
                attrs.append('async')
            string = '<script %s></script>' % ' '.join(attrs)
            return _build_html(items, string)