def handle(self, **options): verbosity = int(options.get("verbosity", 1)) # Run the compiler. for namespace in StaticAsset.get_namespaces(): try: for plugin, assets in default_asset_compiler.compile_iter( namespace): if verbosity >= 2: self.stdout.write( "Compiled {asset_type} assets in {namespace} namespace\n" .format( asset_type=plugin.asset_type, namespace=namespace, )) if verbosity >= 3: for asset in assets: self.stdout.write(" - {asset}\n".format( asset=asset.get_name(), )) except Exception as ex: if hasattr(ex, "detail_message"): self.stdout.write("\n{}\n".format(ex.detail_message)) raise else: if verbosity == 1: self.stdout.write( "Compiled assets in {namespace} namespace\n".format( namespace=namespace))
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 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 iter_test_assets(valid_extensions): for finder in finders.get_finders(): for path, storage in finder.list(()): extension = os.path.splitext(path)[1].lower() if not valid_extensions or extension in valid_extensions: if getattr(storage, "prefix", None): path = os.path.join(storage.prefix, path) asset = StaticAsset(path) try: default_asset_cache.get_name(asset) except: continue else: yield asset
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, }
def handle(self, **options): verbosity = int(options.get("verbosity", 1)) # Run the compiler. for namespace in StaticAsset.get_namespaces(): try: for plugin, assets in default_asset_compiler.compile_iter(namespace): if verbosity >= 2: self.stdout.write("Compiled {asset_type} assets in {namespace} namespace\n".format( asset_type = plugin.asset_type, namespace = namespace, )) if verbosity >= 3: for asset in assets: self.stdout.write(" - {asset}\n".format( asset = asset.get_name(), )) except Exception as ex: if hasattr(ex, "detail_message"): self.stdout.write("\n{}\n".format(ex.detail_message)) raise else: if verbosity == 1: self.stdout.write("Compiled assets in {namespace} namespace\n".format(namespace=namespace))
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
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