Exemplo n.º 1
0
def register_color_feature(name, colour, features):
    feature_name = get_feature_name(name)
    type_ = get_feature_name_upper(name)
    tag = 'span'

    control = {'type': type_, 'icon': get_setting('ICON')}

    is_classname = colour.startswith('.')
    if is_classname:
        colour = colour[1:]
        detection = '%s[class="%s"]'
        control['class'] = colour
        editor_colors = get_setting('EDITOR_COLOURS')
        editor_color = editor_colors.get(name, "#00f")
        control['style'] = {'color': editor_color}
        props = {'class': colour}
    else:
        detection = '%s[style="color: %s;"]'
        control['style'] = {'color': colour}
        props = {
            'style': {
                'color': colour,
            }
        }

    control['description'] = colour
    detection = detection % (tag, colour)

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.InlineStyleFeature(control))

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                detection: InlineStyleElementHandler(type_)
            },
            'to_database_format': {
                'style_map': {
                    type_: {
                        'element': tag,
                        'props': props
                    }
                },
            },
        })

    features.default_features.append(feature_name)
def register_textcolour_feature(features):
    # register all colour features
    register_all_colour_features(features)

    # register the color picker
    feature_name = 'textcolour'
    type_ = feature_name.upper()

    control = {
        'type': type_,
        'icon': get_setting('ICON'),
        'description': _('Text Colour'),
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(
            control,
            js=[
                'colourpicker/js/chooser.js',
                'colourpicker/js/colourpicker.js',
            ],
            css={
                'all': ['colourpicker/css/colourpicker.css'],
            }))

    features.default_features.append(feature_name)
Exemplo n.º 3
0
def get_list_colour_features_name():
    """
    Add list names into your
    models.py RichTextField(features=[get_list_features_name()]
    """
    list_features_name = list()

    for name, colour in get_setting('COLOURS').items():
        name_feature = get_feature_name(name)
        list_features_name.append(name_feature)
    return list_features_name
Exemplo n.º 4
0
def register_color_feature(name, colour, features):
    feature_name = get_feature_name(name)
    type_ = get_feature_name_upper(name)
    tag = 'span'
    detection = '%s[style="color: %s;"]' % (tag, colour)

    control = {
        'type': type_,
        'icon': get_setting('ICON'),
        'description': colour,
        'style': {
            'color': colour
        }
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.InlineStyleFeature(control))

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                detection: InlineStyleElementHandler(type_)
            },
            'to_database_format': {
                'style_map': {
                    type_: {
                        'element': tag,
                        'props': {
                            'style': {
                                'color': colour
                            }
                        }
                    }
                }
            },
        })

    features.default_features.append(feature_name)
Exemplo n.º 5
0
def get_colour_choices():
    return tuple(get_setting('COLOURS').items())
Exemplo n.º 6
0
def register_all_colour_features(features):
    for name, colour in get_setting('COLOURS').items():
        register_color_feature(name, colour, features)
Exemplo n.º 7
0
def get_feature_name_list():
    return [
        get_feature_name_upper(name) for name in get_setting('COLOURS').keys()
    ]