How to use the lektor.context.Context 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_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)
github lektor / lektor / tests / test_types.py View on Github external
def test_string(env, pad):
    field = make_field(env, 'string')

    with Context(pad=pad):
        rv = field.deserialize_value('', pad=pad)
        assert rv == ''

        rv = field.deserialize_value(None, pad=pad)
        assert isinstance(rv, Undefined)

        rv = field.deserialize_value('foo\nbar', pad=pad)
        assert rv == 'foo'

        rv = field.deserialize_value(' 123 ', pad=pad)
        assert rv == '123'
github lektor / lektor / tests / test_types.py View on Github external
def test_integer(env, pad):
    field = make_field(env, 'integer')

    with Context(pad=pad):
        rv = field.deserialize_value('', pad=pad)
        assert isinstance(rv, BadValue)

        rv = field.deserialize_value(None, pad=pad)
        assert isinstance(rv, Undefined)

        rv = field.deserialize_value('42', pad=pad)
        assert rv == 42

        rv = field.deserialize_value(' 23 ', pad=pad)
        assert rv == 23
github lektor / lektor / tests / test_types.py View on Github external
def test_boolean(env, pad):
    field = make_field(env, 'boolean')

    with Context(pad=pad):
        rv = field.deserialize_value('', pad=pad)
        assert isinstance(rv, BadValue)

        rv = field.deserialize_value(None, pad=pad)
        assert isinstance(rv, Undefined)

        for s in 'true', 'TRUE', 'True', '1', 'yes':
            rv = field.deserialize_value(s, pad=pad)
            assert rv is True

        for s in 'false', 'FALSE', 'False', '0', 'no':
            rv = field.deserialize_value(s, pad=pad)
            assert rv is False
github lektor / lektor-archive / lektor / builder.py View on Github external
def begin_update(self):
        """Begins an update block."""
        if self.in_update_block:
            raise RuntimeError('Artifact is already open for updates.')
        self.updated = False
        ctx = Context(self)
        ctx.push()
        self.in_update_block = True
        self.clear_dirty_flag()
        return ctx
github lektor / lektor / lektor / builder.py View on Github external
def begin_update(self):
        """Begins an update block."""
        if self.in_update_block:
            raise RuntimeError('Artifact is already open for updates.')
        self.updated = False
        ctx = Context(self)
        ctx.push()
        self.in_update_block = True
        self.clear_dirty_flag()
        return ctx