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)
示例#2
0
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 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 django_static(path)
示例#4
0
def static(path):
    # Copied from ``django_libsass.static`` as there is no way to reference their method in
    # LIBSASS_CUSTOM_FUNCTIONS in settings.py. The setting does not accept function paths. It
    # expects reference to the real function, but ``django_libsass`` module may not be imported in
    # ``settings.py``, because it requires settings already configured.
    from django.templatetags.static import static as django_static
    return '"{}"'.format(django_static(path))
def static(path):
    # Copied from ``django_libsass.static`` as there is no way to reference their method in
    # LIBSASS_CUSTOM_FUNCTIONS in settings.py. The setting does not accept function paths. It
    # expects reference to the real function, but ``django_libsass`` module may not be imported in
    # ``settings.py``, because it requires settings already configured.
    from django.templatetags.static import static as django_static
    return '"{}"'.format(django_static(path))
示例#6
0
    def get_static_url(self, path):
        """
        Works just like the ``static`` template tag.

        Args:
            path (str): The path relative to the static directory.

        Returns:
            str: The static URL.

        """
        return django_static(path)
示例#7
0
def cradmin_theme_static(context, path, absolute=False):
    """
    Works just like the ``{% static %}`` template tag,
    except that it expects ``path`` to be relative to the
    path specified in the :setting:`DJANGO_CRADMIN_THEME_PREFIX`
    setting.

    Args:
        path (str): The path to lookup.
        absolute (bool): Should we create an absolute url including the domain?
            Defaults to ``False``.
    """
    staticpath = posixpath.join(settings.DJANGO_CRADMIN_THEME_PREFIX, path)
    full_path = django_static(staticpath)
    if absolute:
        url = context['request'].build_absolute_uri(full_path)
    else:
        url = full_path
    return url
 def _static(self, path):
     return django_static(path)
示例#9
0
 def _static(self, path):
     return django_static(path)
示例#10
0
def static(path):
    rev = get_revision()
    qs = (u'?rev=' + rev) if rev else u''
    return django_static(path) + qs