Przeglądaj źródła

Init: establish basic pattern of adding block previews

Jeremy Childers 1 miesiąc temu
rodzic
commit
691982660e

+ 7 - 0
.cr.ini

@@ -0,0 +1,7 @@
+# This is a deployment file for CodeRed Cloud hosting.
+# If you are not using CodeRed Cloud, you can delete this file.
+#
+# https://www.codered.cloud/cli/
+#
+[cr]
+deploy_include = website/static/website/css/custom.css

+ 69 - 0
coderedcms/blocks/layout_blocks.py

@@ -34,6 +34,16 @@ class ColumnBlock(BaseLayoutBlock):
         template = "coderedcms/blocks/column_block.html"
         icon = "placeholder"
         label = "Column"
+        preview_template = "wagtailcore/shared/block_preview.html"
+        description = "Renders the content in a column."
+        preview_value = (
+            {
+                "settings": {
+                    "custom_template": "",
+                },
+                "content": [("text", "<h1>This is a column!</h1>")],
+            },
+        )
 
 
 class GridBlock(BaseLayoutBlock):
@@ -50,6 +60,33 @@ class GridBlock(BaseLayoutBlock):
         template = "coderedcms/blocks/grid_block.html"
         icon = "cr-columns"
         label = _("Responsive Grid Row")
+        preview_template = "wagtailcore/shared/block_preview.html"
+        description = "Renders a row of columns."
+        preview_value = {
+            "settings": {
+                "custom_template": "",
+            },
+            "content": [
+                (
+                    "content",
+                    {
+                        "settings": {
+                            "custom_template": "",
+                        },
+                        "content": [("text", "<h1>This is a row block!</h1>")],
+                    },
+                ),
+                (
+                    "content",
+                    {
+                        "settings": {
+                            "custom_template": "",
+                        },
+                        "content": [("text", "<h1>With Two Columns!</h1>")],
+                    },
+                ),
+            ],
+        }
 
     def __init__(self, local_blocks=None, **kwargs):
         super().__init__(local_blocks=[("content", ColumnBlock(local_blocks))])
@@ -111,3 +148,35 @@ class HeroBlock(BaseLayoutBlock):
         template = "coderedcms/blocks/hero_block.html"
         icon = "cr-newspaper-o"
         label = "Hero Unit"
+        preview_value = {
+            "settings": {
+                "custom_template": "",
+            },
+            "background_color": "#ff0011",
+            "foreground_color": "#ffffff",
+            "content": [
+                (
+                    "row",
+                    {
+                        "settings": {
+                            "custom_template": "",
+                        },
+                        "content": [
+                            (
+                                "content",
+                                {
+                                    "settings": {
+                                        "custom_template": "",
+                                    },
+                                    "content": [
+                                        ("text", "<h1>This is a hero block!")
+                                    ],
+                                },
+                            )
+                        ],
+                    },
+                )
+            ],
+        }
+        preview_template = "wagtailcore/shared/block_preview.html"
+        description = "Wrapper with color and image background options."

+ 15 - 0
coderedcms/templates/wagtailcore/shared/block_preview.html

@@ -0,0 +1,15 @@
+{% extends "wagtailcore/shared/block_preview.html" %}
+{% load static coderedcms_tags %}
+
+{% block css %}
+{{ block.super }}
+{% django_setting "DEBUG" as debug %}
+{% if debug %}
+<link rel="stylesheet" href="{% static 'coderedcms/css/crx-front.css' %}?v={% coderedcms_version %}">
+{% else %}
+<link rel="stylesheet" href="{% static 'coderedcms/css/crx-front.min.css' %}?v={% coderedcms_version %}">
+{% endif %}
+<link rel="stylesheet"
+  href="{% static 'coderedcms/vendor/bootstrap/dist/css/bootstrap.min.css' %}?v={% coderedcms_version %}">
+
+{% endblock %}

+ 1 - 1
pyproject.toml

@@ -38,7 +38,7 @@ dependencies = [
     "Django>=4.2,<6.0",  # should be the same as wagtail
     "geocoder==1.38.*",
     "icalendar==6.1.*",
-    "wagtail>=6.3,<7.0",
+    "wagtail>=6.4,<7.0",
     "wagtail-cache>=2.4,<3",
     "wagtail-flexible-forms==2.*",
     "wagtail-seo==3.*",