Ejemplo 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)
 def testScriptTag(self):
     script = get_test_javascript_asset()
     urls = default_javascript_cache.get_urls((script,))
     self.assertEqual(
         Template("{% load assets %}{% script script %}").render(Context({
             "script": script,
         })),
         '<script src="{url}"></script>'.format(
             url = urls[0],
         ),
     )
Ejemplo n.º 3
0
 def testScriptTag(self):
     script = get_test_javascript_asset()
     urls = default_javascript_cache.get_urls((script,))
     self.assertEqual(
         Template("{% load assets %}{% script script %}").render(Context({
             "script": script,
         })),
         u'<script src="{url}"></script>'.format(
             url = urls[0],
         ),
     )
Ejemplo n.º 4
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)