How to use Lektor - 10 common examples

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_types.py View on Github external
def md(s):
        rv = field.deserialize_value(s, pad=pad)
        assert isinstance(rv, MarkdownDescriptor)
        return text_type(rv.__get__(source)).strip()
github lektor / lektor / tests / test_unicode.py View on Github external
def get_unicode_builder(tmpdir):
    from lektor.project import Project
    from lektor.environment import Environment
    from lektor.db import Database
    from lektor.builder import Builder

    proj = Project.from_path(os.path.join(os.path.dirname(__file__),
                                          u'ünicöde-project'))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir('output')))
github lektor / lektor / tests / test_prev_next_sibling.py View on Github external
# Create post3, check that post2 and post4's dependencies are updated.
    post3_dir = os.path.join(env.project.tree, 'content', 'post3')

    def cleanup():
        try:
            shutil.rmtree(post3_dir)
        except (OSError, IOError):
            pass

    request.addfinalizer(cleanup)
    os.makedirs(post3_dir)
    open(os.path.join(post3_dir, 'contents.lr'), 'w+').close()

    reporter.clear()
    builder = Builder(env.new_pad(), builder.destination_path)
    builder.build_all()

    # post2, post3, and post4 had to be rebuilt, but not post1.
    assert set(['post2', 'post3', 'post4']) == set(reporter.artifact_ids)

    # post2 depends on post3 now, not post4.
    assert 'content/post3/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' not in reporter.deps['post2']

    # post4 depends on post3 now, not post2.
    assert 'content/post3/contents.lr' in reporter.deps['post4']
    assert 'content/post2/contents.lr' not in reporter.deps['post4']
github lektor / lektor / tests / test_prev_next_sibling.py View on Github external
def test_prev_next_dependencies(request, tmpdir, pntest_env, pntest_reporter):
    env, reporter = pntest_env, pntest_reporter
    builder = Builder(env.new_pad(), str(tmpdir.mkdir("output")))
    builder.build_all()

    # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other,
    # posts 2 and 3 depend on each other, but posts 1 and 3 are independent.
    assert 'content/post2/contents.lr' in reporter.deps['post1']
    assert 'content/post3/contents.lr' not in reporter.deps['post1']
    assert '/post1@siblings' in reporter.deps['post1']

    assert 'content/post1/contents.lr' in reporter.deps['post2']
    assert 'content/post4/contents.lr' in reporter.deps['post2']
    assert '/post2@siblings' in reporter.deps['post2']

    assert 'content/post1/contents.lr' not in reporter.deps['post4']
    assert 'content/post2/contents.lr' in reporter.deps['post4']
    assert '/post4@siblings' in reporter.deps['post4']
github lektor / lektor / tests / test_unicode.py View on Github external
def get_unicode_builder(tmpdir):
    from lektor.project import Project
    from lektor.environment import Environment
    from lektor.db import Database
    from lektor.builder import Builder

    proj = Project.from_path(os.path.join(os.path.dirname(__file__),
                                          u'ünicöde-project'))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir('output')))
github lektor / lektor / tests / test_themes.py View on Github external
def theme_pad(theme_env):
    from lektor.db import Database
    return Database(theme_env).new_pad()
github lektor / lektor / tests / test_types.py View on Github external
def test_datetime_timezone_utc(env, pad):
    field = make_field(env, 'datetime')
    with Context(pad=pad):
        # Known timezone name, UTC
        rv = field.deserialize_value('2016-04-30 01:02:03 UTC', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is get_timezone('UTC')
github lektor / lektor / tests / test_types.py View on Github external
def test_markdown_links(env, pad):
    field = make_field(env, 'markdown')
    source = DummySource()

    def md(s):
        rv = field.deserialize_value(s, pad=pad)
        assert isinstance(rv, MarkdownDescriptor)
        return text_type(rv.__get__(source)).strip()

    with Context(pad=pad):
        assert md('[foo](http://example.com/)') == (
            '<p><a href="http://example.com/">foo</a></p>'
        )
        assert md('[foo](javascript:foo)') == (
            '<p><a>foo</a></p>'
        )

        img = (
            'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4'
            '//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
        )
        assert md('![test](data:image/png;base64,%s)' % img) == (
            '<p><img alt="test" src="data:image/png;base64,%s"></p>'
        ) % img
github nixjdm / lektor-tags / tests / test_lektor_tags.py View on Github external
def test_tags_expression(pad, builder, env):
    with Context(pad=pad):
        plugin = env.plugins["tags"]
        conf = plugin.get_config()
        parent = pad.get("/blog")

        conf["tags"] = 'parent.children.filter(F.published).distinct("tags")'
        assert plugin.get_all_tags(parent) == ["tag1", "tag2"]

        conf["tags"] = '["foo", "bar", "bar"]'
        assert plugin.get_all_tags(parent) == ["bar", "foo"]
github lektor / lektor / tests / test_types.py View on Github external
def test_datetime_timezone_mst(env, pad):
    field = make_field(env, 'datetime')
    with Context(pad=pad):
        # MST - http://www.timeanddate.com/time/zones/mst
        rv = field.deserialize_value('2016-04-30 01:02:03 -0700', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, -7 * 60 * 60)