Exemplo n.º 1
0
def resolve_script_src(src, _src):
    """Resolves the given src attribute of the script."""
    all_src = (src,) + _src
    src_urls = list(filter(is_url, all_src))
    if src_urls:
        if len(src_urls) == len(all_src):
            return all_src  # All are URLs, which is allowed.
        else:
            raise ValueError("Mixed assets and absolute URLs are not allowed in script tags.")
    assets = StaticAsset.load("js", all_src)
    return default_javascript_cache.get_urls(assets)
Exemplo n.º 2
0
def resolve_script_src(src, _src):
    """Resolves the given src attribute of the script."""
    all_src = (src, ) + _src
    src_urls = list(filter(is_url, all_src))
    if src_urls:
        if len(src_urls) == len(all_src):
            return all_src  # All are URLs, which is allowed.
        else:
            raise ValueError(
                "Mixed assets and absolute URLs are not allowed in script tags."
            )
    assets = StaticAsset.load("js", all_src)
    return default_javascript_cache.get_urls(assets)
Exemplo n.º 3
0
def stylesheet(href="default", *_href, **attrs):
    """Renders one or more stylesheet tags."""
    compile = attrs.pop("compile", True)
    all_href = (href,) + _href
    href_urls = list(filter(is_url, all_href))
    if href_urls:
        if len(href_urls) == len(all_href):
            urls = all_href  # All are URLs, which is allowed.
        else:
            raise ValueError("Mixed assets and absolute URLs are not allowed in stylesheet tags.")
    else:
        assets = StaticAsset.load("css", all_href)
        urls = default_stylesheet_cache.get_urls(assets, compile=compile)
    return {
        "urls": urls,
        "attrs": attrs,
    }
Exemplo n.º 4
0
def stylesheet(href="default", *_href, **attrs):
    """Renders one or more stylesheet tags."""
    compile = attrs.pop("compile", True)
    all_href = (href, ) + _href
    href_urls = list(filter(is_url, all_href))
    if href_urls:
        if len(href_urls) == len(all_href):
            urls = all_href  # All are URLs, which is allowed.
        else:
            raise ValueError(
                "Mixed assets and absolute URLs are not allowed in stylesheet tags."
            )
    else:
        assets = StaticAsset.load("css", all_href)
        urls = default_stylesheet_cache.get_urls(assets, compile=compile)
    return {
        "urls": urls,
        "attrs": attrs,
    }
Exemplo n.º 5
0
 def compile_iter(self, namespace="default"):
     """Iterates over all assets in the given namespace, compiling as it goes."""
     for plugin_name, plugin in six.iteritems(self._plugins):
         assets = StaticAsset.load(plugin_name, namespace)
         plugin.compile_assets(assets)
         yield plugin, assets
Exemplo n.º 6
0
 def compile_iter(self, namespace="default"):
     """Iterates over all assets in the given namespace, compiling as it goes."""
     for plugin_name, plugin in self._plugins.iteritems():
         assets = StaticAsset.load(plugin_name, namespace)
         plugin.compile_assets(assets)
         yield plugin, assets