How to use the lektor.utils.join_path function in Lektor

To help you get started, we’ve selected a few Lektor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lektor / lektor / tests / test_utils.py View on Github external
assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
def test_join_path():
    from lektor.utils import join_path

    assert join_path('a', 'b') == 'a/b'
    assert join_path('/a', 'b') == '/a/b'
    assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
def test_join_path():
    from lektor.utils import join_path

    assert join_path('a', 'b') == 'a/b'
    assert join_path('/a', 'b') == '/a/b'
    assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'
github lektor / lektor / tests / test_utils.py View on Github external
assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
def test_join_path():
    from lektor.utils import join_path

    assert join_path('a', 'b') == 'a/b'
    assert join_path('/a', 'b') == '/a/b'
    assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
def test_join_path():
    from lektor.utils import join_path

    assert join_path('a', 'b') == 'a/b'
    assert join_path('/a', 'b') == '/a/b'
    assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github lektor / lektor / tests / test_utils.py View on Github external
def test_join_path():
    from lektor.utils import join_path

    assert join_path('a', 'b') == 'a/b'
    assert join_path('/a', 'b') == '/a/b'
    assert join_path('a@b', 'c') == 'a@b/c'
    assert join_path('a@b', '') == 'a@b'
    assert join_path('a@b', '@c') == 'a@c'
    assert join_path('a@b/c', 'a@b') == 'a/a@b'

    assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
github lektor / lektor / tests / test_utils.py View on Github external
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
    assert join_path('blog@archive/2015', '..') == 'blog@archive'
    assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
    assert join_path('blog@archive', '..') == 'blog'
    assert join_path('blog@archive', '.') == 'blog@archive'
    assert join_path('blog@archive', '') == 'blog@archive'

    # special behavior: parent of pagination paths is always the actual
    # page parent.
    assert join_path('/blog@1', '..') == '/'
    assert join_path('/blog@2', '..') == '/'

    # But joins on the same level keep the path
    assert join_path('/blog@1', '.') == '/blog@1'
    assert join_path('/blog@2', '.') == '/blog@2'
    assert join_path('/blog@1', '') == '/blog@1'
    assert join_path('/blog@2', '') == '/blog@2'
github ulope / pyformat.info / vendor / lektor / lektor / sourceobj.py View on Github external
alt = self.alt

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

        if resolve:
            if not path.startswith('/'):
                if self.path is None:
                    raise RuntimeError('Cannot use relative URL generation '
                                       'from sources that do not have a '
                                       'path.  The source object without '
                                       'a path is %r' % self)
                path = join_path(self.path, path)
            source = self.pad.get(path, alt=alt)
            if source is not None:
                path = source.url_path
        else:
            path = posixpath.join(self.url_path, path)

        if absolute:
            return path
        if base_url is None:
            base_url = self.url_path
        return self.pad.make_url(path, base_url, absolute, external)