Skip to content

Commit

Permalink
Paint it black.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipperPA committed Oct 3, 2022
1 parent bec48af commit a67a012
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
64 changes: 33 additions & 31 deletions wagtailcontentstream/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,86 +31,88 @@ class CaptionedImageBlock(StructBlock):
"""
An image block with a caption, credit, and alignment.
"""

image = ImageChooserBlock(
help_text='The image to display.',
help_text="The image to display.",
)
caption = TextBlock(
required=False,
help_text='The caption will appear under the image, if entered.'
required=False, help_text="The caption will appear under the image, if entered."
)
credit = TextBlock(
required=False,
help_text='The credit will appear under the image, if entered.'
required=False, help_text="The credit will appear under the image, if entered."
)
align = ChoiceBlock(
choices=[
('left', 'Left'),
('right', 'Right'),
('center', 'Center'),
('full', 'Full Width'),
("left", "Left"),
("right", "Right"),
("center", "Center"),
("full", "Full Width"),
],
default='left',
help_text='How to align the image in the body of the page.'
default="left",
help_text="How to align the image in the body of the page.",
)

class Meta:
icon = 'image'
template = 'wagtailcontentstream/blocks/captioned_image.html'
help_text = 'Select an image and add a caption (optional).'
icon = "image"
template = "wagtailcontentstream/blocks/captioned_image.html"
help_text = "Select an image and add a caption (optional)."


class ContentStreamBlock(StreamBlock):
"""
Contains the elements we'll want to have in a Content Stream.
"""

heading = TextBlock(
icon='title',
template='wagtailcontentstream/blocks/heading.html',
icon="title",
template="wagtailcontentstream/blocks/heading.html",
)
paragraph = RichTextBlock(
icon='pilcrow',
features=['bold', 'italic', 'link', 'ol', 'ul', 'monospace'],
icon="pilcrow",
features=["bold", "italic", "link", "ol", "ul", "monospace"],
)
image = CaptionedImageBlock()
document = DocumentChooserBlock()
embed = EmbedBlock(icon='media')
table = TableBlock(icon='table')
code = CodeBlock(icon='code')
embed = EmbedBlock(icon="media")
table = TableBlock(icon="table")
code = CodeBlock(icon="code")

class Meta:
help_text = 'The main page body.'
help_text = "The main page body."


class ContentStreamBlockWithRawCode(ContentStreamBlock):
raw_code = CodeBlock(
icon='code',
language='html',
template='wagtailcodeblock/raw_code.html',
icon="code",
language="html",
template="wagtailcodeblock/raw_code.html",
)


class SectionStructBlock(StructBlock):
"""
Contains the elements we'll want to have in a Sectioned Content Stream block.
"""

section_heading = TextBlock(
icon='title',
help_text='Heading for this section.',
icon="title",
help_text="Heading for this section.",
)
body = ContentStreamBlock(
help_text='The body content goes here.',
help_text="The body content goes here.",
)

class Meta:
template = 'wagtailcontentstream/blocks/section_struct_block.html'
icon = 'doc-full-inverse'
template = "wagtailcontentstream/blocks/section_struct_block.html"
icon = "doc-full-inverse"


class SectionBlock(StreamBlock):
"""
Streamblock to associate multiple blocks with a section.
"""

section = SectionStructBlock()

class Meta:
help_text = 'The main page body.'
help_text = "The main page body."
6 changes: 3 additions & 3 deletions wagtailcontentstream/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ContentStreamPage(Page):
)

content_panels = Page.content_panels + [
StreamFieldPanel('body'),
StreamFieldPanel("body"),
]

class Meta:
Expand All @@ -32,7 +32,7 @@ class ContentStreamPageWithRawCode(Page):
)

content_panels = Page.content_panels + [
StreamFieldPanel('body'),
StreamFieldPanel("body"),
]

class Meta:
Expand All @@ -46,7 +46,7 @@ class SectionContentStreamPage(Page):
)

content_panels = Page.content_panels + [
StreamFieldPanel('body'),
StreamFieldPanel("body"),
]

class Meta:
Expand Down
26 changes: 14 additions & 12 deletions wagtailcontentstream/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
from wagtail.admin.rich_text.converters.html_to_contentstate import (
InlineStyleElementHandler,
)
from wagtail.admin.rich_text.editors.draftail.features import InlineStyleFeature
from wagtail.core import hooks


@hooks.register('register_rich_text_features')
@hooks.register("register_rich_text_features")
def register_monospace_feature(features):
"""
Registering the `monospace` feature, which uses the `CODE` Draft.js inline style type,
and is stored as HTML with a `<code>` tag.
"""
feature_name = 'monospace'
draftail_type = 'CODE'
html_tag = 'code'
feature_name = "monospace"
draftail_type = "CODE"
html_tag = "code"

# Configure how Draftail handles the feature in its toolbar.
control = {
'type': draftail_type,
'label': '{ }',
'description': 'Monospace',
"type": draftail_type,
"label": "{ }",
"description": "Monospace",
}

# Call register_editor_plugin to register the configuration for Draftail.
features.register_editor_plugin(
'draftail', feature_name, InlineStyleFeature(control)
"draftail", feature_name, InlineStyleFeature(control)
)

# Configure the content transform from the DB to the editor and back.
db_conversion = {
'from_database_format': {html_tag: InlineStyleElementHandler(draftail_type)},
'to_database_format': {'style_map': {draftail_type: html_tag}},
"from_database_format": {html_tag: InlineStyleElementHandler(draftail_type)},
"to_database_format": {"style_map": {draftail_type: html_tag}},
}

# Call register_converter_rule to register the content transformation conversion.
features.default_features.append(feature_name)
features.register_converter_rule('contentstate', feature_name, db_conversion)
features.register_converter_rule("contentstate", feature_name, db_conversion)

0 comments on commit a67a012

Please sign in to comment.