Esempio n. 1
0
    def url_to(self, path, alt=None, absolute=False, external=False):
        """Calculates the URL from the current source object to the given
        other source object.  Alternatively a path can also be provided
        instead of a source object.  If the path starts with a leading
        bang (``!``) then no resolving is performed.
        """
        if alt is None:
            alt = getattr(path, 'alt', None)
            if alt is None:
                alt = self.alt

        resolve = True
        path = getattr(path, 'url_path', path)
        if path[:1] == '!':
            resolve = False
            path = path[1:]

        if resolve:
            source = self.pad.get(posixpath.join(self.path, path), alt=alt)
            if source is not None:
                path = source.url_path

        if absolute:
            return path
        elif external:
            return self.pad.make_absolute_url(path)
        return make_relative_url(self.url_path, path)
Esempio n. 2
0
    def url_to(self, path, alt=None, absolute=False, external=False):
        """Calculates the URL from the current source object to the given
        other source object.  Alternatively a path can also be provided
        instead of a source object.  If the path starts with a leading
        bang (``!``) then no resolving is performed.
        """
        if alt is None:
            alt = getattr(path, 'alt', None)
            if alt is None:
                alt = self.alt

        resolve = True
        path = getattr(path, 'url_path', path)
        if path[:1] == '!':
            resolve = False
            path = path[1:]

        if resolve:
            source = self.pad.get(posixpath.join(self.path, path), alt=alt)
            if source is not None:
                path = source.url_path

        if absolute:
            return path
        elif external:
            return self.pad.make_absolute_url(path)
        return make_relative_url(self.url_path, path)
Esempio n. 3
0
 def url_to(self, path, alt=None, absolute=False, external=False):
     """Returns a URL to another path."""
     if self.source is None:
         raise RuntimeError('Can only generate paths to other pages if '
                            'the context has a source document set.')
     rv = self.source.url_to(path, alt=alt, absolute=True)
     if absolute:
         return rv
     elif external:
         return self.pad.make_absolute_url(rv)
     return make_relative_url(self.base_url, rv)
Esempio n. 4
0
 def url_to(self, path, alt=None, absolute=False, external=False):
     """Returns a URL to another path."""
     if self.source is None:
         raise RuntimeError('Can only generate paths to other pages if '
                            'the context has a source document set.')
     rv = self.source.url_to(path, alt=alt, absolute=True)
     if absolute:
         return rv
     elif external:
         return self.pad.make_absolute_url(rv)
     return make_relative_url(self.base_url, rv)
Esempio n. 5
0
def test_make_relative_url_relative_source_absolute_target():
    from lektor.utils import make_relative_url
    with pytest.raises(ValueError):
        make_relative_url("rel/a/tive/", "/abs/o/lute")
Esempio n. 6
0
def test_make_relative_url(source, target, expected):
    from lektor.utils import make_relative_url
    assert make_relative_url(source, target) == expected
Esempio n. 7
0
def test_make_relative_url_relative_source_absolute_target():
    with pytest.raises(ValueError):
        make_relative_url("rel/a/tive/", "/abs/o/lute")
Esempio n. 8
0
def test_make_relative_url(source, target, expected):
    assert make_relative_url(source, target) == expected