How to use the lektor.types.Type 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 / lektor / types / flow.py View on Github external
raise BadFlowBlock('Did not find beginning of flow block')
        else:
            if block is not None:
                blocks.append((block, buf))
                buf = []
            block = block_start.group(1)
            continue
        buf.append(_line_unescape_re.sub('####\\1####\\2', line))

    if block is not None:
        blocks.append((block, buf))

    return blocks


class FlowType(Type):
    widget = 'flow'

    def __init__(self, env, options):
        Type.__init__(self, env, options)
        self.flow_blocks = [
            x.strip() for x in options.get('flow_blocks', '').split(',')
            if x.strip()] or None

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing flow')
        if raw.pad is None:
            return raw.missing_value('Flow value was technically present '
                                     'but used in a place where it cannot '
                                     'be used.')
github ulope / pyformat.info / vendor / lektor / lektor / types / flow.py View on Github external
raise BadFlowBlock('Did not find beginning of flow block')
        else:
            if block is not None:
                blocks.append((block, buf))
                buf = []
            block = block_start.group(1)
            continue
        buf.append(_line_unescape_re.sub('####\\1####\\2', line))

    if block is not None:
        blocks.append((block, buf))

    return blocks


class FlowType(Type):
    widget = 'flow'

    def __init__(self, env, options):
        Type.__init__(self, env, options)
        self.flow_blocks = [
            x.strip() for x in options.get('flow_blocks', '').split(',')
            if x.strip()] or None

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing flow')
        if raw.pad is None:
            return raw.missing_value('Flow value was technically present '
                                     'but used in a place where it cannot '
                                     'be used.')
github lektor / lektor-archive / lektor / types / flow.py View on Github external
raise BadFlowBlock('Did not find beginning of flow block')
        else:
            if block is not None:
                blocks.append((block, buf))
                buf = []
            block = block_start.group(1)
            continue
        buf.append(_line_unescape_re.sub('####\\1####\\2', line))

    if block is not None:
        blocks.append((block, buf))

    return blocks


class FlowType(Type):

    def __init__(self, env, options):
        Type.__init__(self, env, options)
        self.flow_blocks = [
            x.strip() for x in options.get('flow_blocks', '').split(',')
            if x.strip()] or None

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing flow')
        if raw.pad is None:
            return raw.missing_value('Flow value was technically present '
                                     'but used in a place where it cannot '
                                     'be used.')

        db = raw.pad.db
github lektor / lektor / lektor / types / primitives.py View on Github external
self.options, 'addon_label') or None
        return rv


class StringType(SingleInputType):

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing string')
        try:
            return raw.value.splitlines()[0].strip()
        except IndexError:
            return u''


class StringsType(Type):
    widget = 'multiline-text'

    def value_from_raw(self, raw):
        return [x.strip() for x in (raw.value or '').splitlines()]


class TextType(Type):
    widget = 'multiline-text'

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing text')
        return raw.value


class HtmlType(Type):
github ulope / pyformat.info / vendor / lektor / lektor / types / formats.py View on Github external
from lektor.types import Type
from lektor.markdown import Markdown


class MarkdownDescriptor(object):

    def __init__(self, source):
        self.source = source

    def __get__(self, obj, type=None):
        if obj is None:
            return self
        return Markdown(self.source, record=obj)


class MarkdownType(Type):
    widget = 'multiline-text'

    def value_from_raw(self, raw):
        return MarkdownDescriptor(raw.value or u'')
github ulope / pyformat.info / vendor / lektor / lektor / types / primitives.py View on Github external
return raw.bad_value('Not an integer')


class FloatType(SingleInputType):
    widget = 'float'

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing float value')
        try:
            return float(raw.value.strip())
        except ValueError:
            return raw.bad_value('Not an integer')


class BooleanType(Type):
    widget = 'checkbox'

    def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        rv = Type.to_json(self, pad, record, alt)
        rv['checkbox_label_i18n'] = get_i18n_block(
            self.options, 'checkbox_label')
        return rv

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing boolean')
        val = bool_from_string(raw.value.strip().lower())
        if val is None:
            return raw.bad_value('Bad boolean value')
        return val
github lektor / lektor-archive / lektor / types / special.py View on Github external
from lektor.types import Type
from lektor.utils import slugify, Url


class SortKeyType(Type):

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing sort key')
        try:
            return int(raw.value.strip())
        except ValueError:
            return raw.bad_value('Bad sort key value')


class SlugType(Type):

    def value_from_raw(self, raw):
        if raw.value is None:
            return raw.missing_value('Missing slug')
        return slugify(raw.value)
github lektor / lektor / lektor / types / multi.py View on Github external
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        rv = Type.to_json(self, pad, record, alt)
        if self.source.has_choices:
            rv['choices'] = list(self.source.iter_choices(pad, record, alt))
        return rv
github lektor / lektor / lektor / types / fake.py View on Github external
from lektor.types import Type
from lektor.environment import PRIMARY_ALT
from lektor.i18n import get_i18n_block


class FakeType(Type):

    def value_from_raw(self, raw):
        return None

    def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        rv = Type.to_json(self, pad, record, alt)
        rv['is_fake_type'] = True
        return rv


class LineType(FakeType):
    widget = 'f-line'


class SpacingType(FakeType):
    widget = 'f-spacing'