def static(path): """Generate a URL for the specified static file.""" try: return django_static(path) except ValueError as err: log.error("Static helper error: %s" % err) return ""
def static(path): """ Use the Django builtin static file resolver to return an absolute path usable as CSS url() argument. Sass equivalent of the 'static' template tag. """ return '"{}"'.format(django_static(path))
def prefix_sourcemap(sourcemap, base_path): decoded_sourcemap = json.loads(sourcemap) source_urls = [] include_paths = get_include_paths() for source_filename in decoded_sourcemap['sources']: # expand source_filename into an absolute file path full_source_path = os.path.normpath(os.path.join(base_path, source_filename)) # look for a path in include_paths that is a prefix of full_source_path for path in include_paths: if full_source_path.startswith(path): # A matching path has been found; take the remainder as a relative path. # include_paths entries do not include a trailing slash; # [len(path) + 1:] ensures that we trim the path plus trailing slash remainder = full_source_path[len(path) + 1:] # Invoke the 'static' template tag to turn the relative path into a URL source_urls.append(django_static(remainder)) break else: # no matching path was found in include_paths; return the original source filename # as a fallback source_urls.append(source_filename) decoded_sourcemap['sources'] = source_urls return json.dumps(decoded_sourcemap)
def static(path): """Generate a URL for the specified static file.""" try: return django_static(path) except ValueError as err: log.error('Static helper error: %s' % err) return ''