コード例 #1
0
ファイル: __init__.py プロジェクト: Kami/django-assets
        def _rewrite(m):
            # get the regex matches; note how we maintain the exact
            # whitespace around the actual url; we'll indeed only
            # replace the url itself
            text_before = m.groups()[0]
            url = m.groups()[1]
            text_after = m.groups()[2]

            # normalize the url we got
            quotes_used = ''
            if url[:1] in '"\'':
                quotes_used = url[:1]
                url = url[1:]
            if url[-1:] in '"\'':
                url = url[:-1]

            # if path is an absolute one, keep it
            if not url.startswith('/') and not url.startswith('http://'):
                # rewritten url: relative path from new location (output)
                # to location of referenced file (source + current url)
                url = urlpath.relpath(output_url,
                                      urlparse.urljoin(source_url, url))

            result = 'url(%s%s%s%s%s)' % (
                        text_before, quotes_used, url, quotes_used, text_after)
            return result
コード例 #2
0
ファイル: __init__.py プロジェクト: 50onRed/webassets
    def replace_url(self, url):
        # Replace mode: manually adjust the location of files
        if callable(self.replace):
            return self.replace(url)
        elif self.replace is not False:
            for to_replace, sub in self.replace_dict.items():
                targeturl = urlparse.urljoin(self.source_url, url)
                if targeturl.startswith(to_replace):
                    url = "%s%s" % (sub, targeturl[len(to_replace):])
                    # Only apply the first match
                    break

        # Default mode: auto correct relative urls
        else:
            # If path is an absolute one, keep it
            parsed = urlparse.urlparse(url)
            if not parsed.scheme and not parsed.path.startswith('/'):
                abs_source_url = urlparse.urljoin(self.source_url, url)

                # relpath() will not detect this case
                if urlparse.urlparse(abs_source_url).scheme:
                    return abs_source_url

                # rewritten url: relative path from new location (output)
                # to location of referenced file (source + current url)
                url = urlpath.relpath(self.output_url, abs_source_url)

        return url
コード例 #3
0
        def _rewrite(m):
            # get the regex matches; note how we maintain the exact
            # whitespace around the actual url; we'll indeed only
            # replace the url itself
            text_before = m.groups()[0]
            url = m.groups()[1]
            text_after = m.groups()[2]

            # normalize the url we got
            quotes_used = ''
            if url[:1] in '"\'':
                quotes_used = url[:1]
                url = url[1:]
            if url[-1:] in '"\'':
                url = url[:-1]

            # if path is an absolute one, keep it
            if not url.startswith('/') and not url.startswith('http://'):
                # rewritten url: relative path from new location (output)
                # to location of referenced file (source + current url)
                url = urlpath.relpath(output_url,
                                      urlparse.urljoin(source_url, url))

            result = 'url(%s%s%s%s%s)' % (text_before, quotes_used, url,
                                          quotes_used, text_after)
            return result
コード例 #4
0
ファイル: __init__.py プロジェクト: abourget/webassets
    def replace_url(self, url):
        # Replace mode: manually adjust the location of files
        if self.replace is not False:
            for to_replace, sub in self.replace_dict.items():
                targeturl = urlparse.urljoin(self.source_url, url)
                if targeturl.startswith(to_replace):
                    url = "%s%s" % (sub, targeturl[len(to_replace):])
                    # Only apply the first match
                    break

        # Default mode: auto correct relative urls
        else:
            # If path is an absolute one, keep it
            if not url.startswith('/') and not (url.startswith('http://') or url.startswith('https://')):
                # rewritten url: relative path from new location (output)
                # to location of referenced file (source + current url)
                url = urlpath.relpath(self.output_url,
                    urlparse.urljoin(self.source_url, url))

        return url
コード例 #5
0
ファイル: __init__.py プロジェクト: tobiasandtobias/webassets
    def replace_url(self, url):
        # Replace mode: manually adjust the location of files
        if self.replace is not False:
            for to_replace, sub in self.replace_dict.items():
                targeturl = urlparse.urljoin(self.source_url, url)
                if targeturl.startswith(to_replace):
                    url = "%s%s" % (sub, targeturl[len(to_replace):])
                    # Only apply the first match
                    break

        # Default mode: auto correct relative urls
        else:
            # If path is an absolute one, keep it
            if not url.startswith('/') and not (url.startswith('http://')
                                                or url.startswith('https://')):
                # rewritten url: relative path from new location (output)
                # to location of referenced file (source + current url)
                url = urlpath.relpath(self.output_url,
                                      urlparse.urljoin(self.source_url, url))

        return url
コード例 #6
0
        def _rewrite(m):
            # Get the regex matches; note how we maintain the exact
            # whitespace around the actual url; we'll indeed only
            # replace the url itself.
            text_before = m.groups()[0]
            url = m.groups()[1]
            text_after = m.groups()[2]

            # normalize the url we got
            quotes_used = ''
            if url[:1] in '"\'':
                quotes_used = url[:1]
                url = url[1:]
            if url[-1:] in '"\'':
                url = url[:-1]

            # Replace mode: manually adjust the location of files
            if replace is not False:
                for to_replace, sub in replace.items():
                    targeturl = urlparse.urljoin(source_url, url)
                    if targeturl.startswith(to_replace):
                        url = "%s%s" % (sub, targeturl[len(to_replace):])
                        # Only apply the first match
                        break

            # Default mode: auto correct relative urls
            else:
                # If path is an absolute one, keep it
                if not url.startswith('/') and not (
                        url.startswith('http://')
                        or url.startswith('https://')):
                    # rewritten url: relative path from new location (output)
                    # to location of referenced file (source + current url)
                    url = urlpath.relpath(output_url,
                                          urlparse.urljoin(source_url, url))

            result = 'url(%s%s%s%s%s)' % (text_before, quotes_used, url,
                                          quotes_used, text_after)
            return result
コード例 #7
0
ファイル: __init__.py プロジェクト: obiwanus/webassets
        def _rewrite(m):
            # Get the regex matches; note how we maintain the exact
            # whitespace around the actual url; we'll indeed only
            # replace the url itself.
            text_before = m.groups()[0]
            url = m.groups()[1]
            text_after = m.groups()[2]

            # normalize the url we got
            quotes_used = ''
            if url[:1] in '"\'':
                quotes_used = url[:1]
                url = url[1:]
            if url[-1:] in '"\'':
                url = url[:-1]

            # Replace mode: manually adjust the location of files
            if replace is not False:
                for to_replace, sub in replace.items():
                    targeturl = urlparse.urljoin(source_url, url)
                    if targeturl.startswith(to_replace):
                        url = "%s%s" % (sub, targeturl[len(to_replace):])
                        # Only apply the first match
                        break

            # Default mode: auto correct relative urls
            else:
                # If path is an absolute one, keep it
                if not url.startswith('/') and not (url.startswith('http://') or url.startswith('https://')):
                    # rewritten url: relative path from new location (output)
                    # to location of referenced file (source + current url)
                    url = urlpath.relpath(output_url,
                                          urlparse.urljoin(source_url, url))

            result = 'url(%s%s%s%s%s)' % (
                        text_before, quotes_used, url, quotes_used, text_after)
            return result