def testStylesheetTag(self): stylesheet = get_test_stylesheet_asset() urls = default_stylesheet_cache.get_urls((stylesheet,)) self.assertEqual( Template("{% load assets %}{% stylesheet stylesheet %}").render(Context({ "stylesheet": stylesheet, })), '<link rel="stylesheet" href="{url}">'.format( url = urls[0], ), )
def testStylesheetTag(self): stylesheet = get_test_stylesheet_asset() urls = default_stylesheet_cache.get_urls((stylesheet,)) self.assertEqual( Template("{% load assets %}{% stylesheet stylesheet %}").render(Context({ "stylesheet": stylesheet, })), u'<link rel="stylesheet" href="{url}">'.format( url = urls[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, }
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, }