def resolve_source_to_url(self, filepath, item): if self.env.config.get('url'): return url_prefix_join(self.env.url, item) filename = item if hasattr(self.env._app, 'blueprints'): try: blueprint, name = item.split('/', 1) self.env._app.blueprints[blueprint] # keyerror if no module endpoint = '%s.static' % blueprint filename = name except (ValueError, KeyError): endpoint = 'static' else: # Module support for Flask < 0.7 try: module, name = item.split('/', 1) self.env._app.modules[module] # keyerror if no module endpoint = '%s.static' % module filename = name except (ValueError, KeyError): endpoint = '.static' ctx = None if not _request_ctx_stack.top: ctx = self.env._app.test_request_context() ctx.push() try: return url_for(endpoint, filename=filename) finally: if ctx: ctx.pop()
def resolve_source_to_url(self, filepath, item): if not self.use_staticfiles: return Resolver.resolve_source_to_url(self, filepath, item) # With staticfiles enabled, searching the url mappings, as the # parent implementation does, will not help. Instead, we can # assume that the url is the root url + the original relative # item that was specified (and searched for using the finders). return url_prefix_join(self.env.url, item)
def resolve_source_to_url(self, ctx, filepath, item): if not self.use_staticfiles: return Resolver.resolve_source_to_url(self, ctx, filepath, item) # With staticfiles enabled, searching the url mappings, as the # parent implementation does, will not help. Instead, we can # assume that the url is the root url + the original relative # item that was specified (and searched for using the finders). return url_prefix_join(ctx.url, item)
def resolve_source_to_url(self, filepath, item): if not self.use_staticfiles: return Resolver.resolve_source_to_url(self, filepath, item) # With staticfiles enabled, searching the url mappings, as the # parent implementation does, will not help. Instead, we can # assume that the url is the root url + the original relative # item that was specified (and searched for using the finders). # The only exception is when the relative url contains a wildcard. # In that case we need to extract from the filepath the right part # of the path and then join it with the root url. if '*' in item: path, _ = item.rsplit('*', 1) item = '%s%s' % (path, filepath.rsplit(path, 1)[1]) return url_prefix_join(self.env.url, item)