mcms-layouts 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcms_layouts/__init__.py +0 -0
- mcms_layouts/admin.py +45 -0
- mcms_layouts/apps.py +19 -0
- mcms_layouts/exceptions.py +13 -0
- mcms_layouts/layout.py +23 -0
- mcms_layouts/manager.py +65 -0
- mcms_layouts/mapping.py +14 -0
- mcms_layouts/migrations/0001_initial.py +36 -0
- mcms_layouts/migrations/0002_alter_layoutmodel_id_alter_layoutmodel_identifier_and_more.py +47 -0
- mcms_layouts/migrations/__init__.py +0 -0
- mcms_layouts/models/__init__.py +0 -0
- mcms_layouts/models/layout.py +39 -0
- mcms_layouts/py.typed +0 -0
- mcms_layouts/registry.py +7 -0
- mcms_layouts/repository.py +72 -0
- mcms_layouts/settings.py +0 -0
- mcms_layouts-0.1.0.dist-info/METADATA +217 -0
- mcms_layouts-0.1.0.dist-info/RECORD +19 -0
- mcms_layouts-0.1.0.dist-info/WHEEL +4 -0
mcms_layouts/__init__.py
ADDED
|
File without changes
|
mcms_layouts/admin.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
from django.urls import reverse
|
|
3
|
+
|
|
4
|
+
from mcms_layouts.models.layout import LayoutModel
|
|
5
|
+
from django.utils.html import format_html
|
|
6
|
+
|
|
7
|
+
from mcms_layouts.manager import LayoutManager
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@admin.register(LayoutModel)
|
|
11
|
+
class LayoutAdmin(admin.ModelAdmin):
|
|
12
|
+
list_display = (
|
|
13
|
+
"name",
|
|
14
|
+
"identifier",
|
|
15
|
+
"edit_with_mcms",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
fields = ("name", "identifier")
|
|
19
|
+
|
|
20
|
+
@admin.display(description="MCMS Editor")
|
|
21
|
+
def edit_with_mcms(self, obj: LayoutModel) -> str:
|
|
22
|
+
url = reverse(
|
|
23
|
+
"mcms_editor:layout_edit",
|
|
24
|
+
kwargs={"layout_id": obj.pk},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return format_html(
|
|
28
|
+
'<a class="button" href="{}">Edit with MCMS</a>',
|
|
29
|
+
url,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def save_model(self, request, obj: LayoutModel, form, change):
|
|
33
|
+
if not change:
|
|
34
|
+
self.init_layout(obj)
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
super().save_model(request, obj, form, change)
|
|
38
|
+
|
|
39
|
+
def init_layout(self, obj: LayoutModel):
|
|
40
|
+
from django.apps import apps
|
|
41
|
+
|
|
42
|
+
layout_manager: LayoutManager = apps.get_app_config("mcms").layout_manager
|
|
43
|
+
return layout_manager.create_new(
|
|
44
|
+
name=obj.name, identifier=obj.identifier, render_tree=obj.render_tree
|
|
45
|
+
)
|
mcms_layouts/apps.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from django.apps import AppConfig
|
|
4
|
+
|
|
5
|
+
from mcms_layouts.registry import LayoutRegistry
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MCMSLayoutsConfig(AppConfig):
|
|
9
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
10
|
+
name = "mcms_layouts"
|
|
11
|
+
verbose_name = "MCMS Layouts"
|
|
12
|
+
|
|
13
|
+
def __init__(self, app_name: str, app_module: Any | None) -> None:
|
|
14
|
+
super().__init__(app_name, app_module)
|
|
15
|
+
|
|
16
|
+
def ready(self) -> None:
|
|
17
|
+
from mcms_layouts.manager import LayoutManager
|
|
18
|
+
|
|
19
|
+
self.layout_manager: LayoutManager = LayoutManager(LayoutRegistry())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from mcms_core.exceptions import MCMSError
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MCMSLayoutError(MCMSError):
|
|
5
|
+
"""Raised when an MCMSLayout Error occurs"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LayoutRepositoryError(MCMSLayoutError):
|
|
9
|
+
"""Raised when repository exceptions occur"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LayoutManagerError(MCMSLayoutError):
|
|
13
|
+
"""Raised when repository exceptions occur"""
|
mcms_layouts/layout.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from mcms_render.tree import RenderTree
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MCMSLayout:
|
|
5
|
+
def __init__(
|
|
6
|
+
self, name: str, identifier: str, render_tree: RenderTree = RenderTree()
|
|
7
|
+
) -> None:
|
|
8
|
+
self.name = name
|
|
9
|
+
self.identifier = identifier
|
|
10
|
+
self.render_tree = render_tree
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def content_node(self) -> str | None:
|
|
14
|
+
return MCMSLayout.get_content_node(self.render_tree)
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def get_content_node(render_tree: RenderTree):
|
|
18
|
+
for id, node in render_tree.nodes.items():
|
|
19
|
+
if (
|
|
20
|
+
node.component_id == "primary" or node.component_id == "empty"
|
|
21
|
+
) and "layout-content" in node.values:
|
|
22
|
+
if node.values["layout-content"]:
|
|
23
|
+
return id
|
mcms_layouts/manager.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from uuid import UUID
|
|
2
|
+
|
|
3
|
+
from mcms_layouts.repository import LayoutRepository
|
|
4
|
+
from mcms_layouts.registry import LayoutRegistry
|
|
5
|
+
from mcms_layouts.layout import MCMSLayout
|
|
6
|
+
from mcms_layouts.exceptions import LayoutManagerError
|
|
7
|
+
|
|
8
|
+
from mcms_render.tree import RenderTree
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LayoutManager:
|
|
12
|
+
def __init__(self, layout_registry: LayoutRegistry) -> None:
|
|
13
|
+
self.layout_registry = layout_registry
|
|
14
|
+
self.layout_repository = LayoutRepository()
|
|
15
|
+
|
|
16
|
+
def create_new(
|
|
17
|
+
self, name: str, identifier: str, render_tree: RenderTree = RenderTree()
|
|
18
|
+
) -> MCMSLayout:
|
|
19
|
+
layout: MCMSLayout = MCMSLayout(
|
|
20
|
+
name=name, identifier=identifier, render_tree=render_tree
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
if name not in self.layout_registry:
|
|
24
|
+
self.layout_repository.create(layout)
|
|
25
|
+
self.layout_registry.register_layout(layout)
|
|
26
|
+
else:
|
|
27
|
+
raise LayoutManagerError("Layout Identifier Already Exists!")
|
|
28
|
+
|
|
29
|
+
return layout
|
|
30
|
+
|
|
31
|
+
def load(self) -> None:
|
|
32
|
+
try:
|
|
33
|
+
layouts: list[MCMSLayout] = self.layout_repository.get_all()
|
|
34
|
+
for layout in layouts:
|
|
35
|
+
self.layout_registry.register_layout(layout)
|
|
36
|
+
except Exception:
|
|
37
|
+
raise LayoutManagerError(
|
|
38
|
+
"Layouts already loaded! load() should only be called once!"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def update(self, layout: MCMSLayout) -> None:
|
|
42
|
+
self.layout_registry.update(layout.identifier, layout)
|
|
43
|
+
self.layout_repository.update(layout)
|
|
44
|
+
|
|
45
|
+
def delete(self, identifier: str) -> None:
|
|
46
|
+
self.layout_repository.delete(identifier)
|
|
47
|
+
if identifier in self.layout_registry:
|
|
48
|
+
self.layout_registry.unregister(identifier)
|
|
49
|
+
|
|
50
|
+
def join_layout_to_content(
|
|
51
|
+
self, layout: MCMSLayout, render_tree: RenderTree
|
|
52
|
+
) -> RenderTree:
|
|
53
|
+
new_render_tree = layout.render_tree.clone(deep_copy=True)
|
|
54
|
+
content_node_id = MCMSLayout.get_content_node(new_render_tree)
|
|
55
|
+
|
|
56
|
+
if content_node_id:
|
|
57
|
+
new_render_tree.insert_tree(
|
|
58
|
+
UUID(content_node_id), render_tree, deep_copy=True
|
|
59
|
+
)
|
|
60
|
+
else:
|
|
61
|
+
raise LayoutManagerError(
|
|
62
|
+
"Cannot Join Render Tree to Layout without a Content Node"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return new_render_tree
|
mcms_layouts/mapping.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from mcms_render.serialization import RenderTreeSerializer
|
|
2
|
+
|
|
3
|
+
from mcms_layouts.models.layout import LayoutModel
|
|
4
|
+
from mcms_layouts.layout import MCMSLayout
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def layout_model_to_domain(layout_model: LayoutModel) -> MCMSLayout:
|
|
8
|
+
render_tree_serializer: RenderTreeSerializer = RenderTreeSerializer()
|
|
9
|
+
|
|
10
|
+
return MCMSLayout(
|
|
11
|
+
name=layout_model.name,
|
|
12
|
+
identifier=layout_model.identifier,
|
|
13
|
+
render_tree=render_tree_serializer.from_json(layout_model.render_tree),
|
|
14
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Generated by Django 6.0.7 on 2026-11-09 17:09
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
initial = True
|
|
9
|
+
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.CreateModel(
|
|
14
|
+
name="LayoutModel",
|
|
15
|
+
fields=[
|
|
16
|
+
(
|
|
17
|
+
"id",
|
|
18
|
+
models.UUIDField(
|
|
19
|
+
default=uuid.uuid4,
|
|
20
|
+
editable=False,
|
|
21
|
+
primary_key=True,
|
|
22
|
+
serialize=False,
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
("identifier", models.TextField(unique=True)),
|
|
26
|
+
("name", models.TextField()),
|
|
27
|
+
("render_tree", models.TextField()),
|
|
28
|
+
],
|
|
29
|
+
options={
|
|
30
|
+
"verbose_name": "Layout",
|
|
31
|
+
"verbose_name_plural": "Layouts",
|
|
32
|
+
"db_table": "mcms_layouts_layout",
|
|
33
|
+
"ordering": ("identifier",),
|
|
34
|
+
},
|
|
35
|
+
),
|
|
36
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Generated by Django 6.0.7 on 2026-11-11 17:51
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("mcms_layouts", "0001_initial"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name="layoutmodel",
|
|
15
|
+
name="id",
|
|
16
|
+
field=models.UUIDField(
|
|
17
|
+
default=uuid.uuid4,
|
|
18
|
+
editable=False,
|
|
19
|
+
help_text="Unique id for this layout.",
|
|
20
|
+
primary_key=True,
|
|
21
|
+
serialize=False,
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
migrations.AlterField(
|
|
25
|
+
model_name="layoutmodel",
|
|
26
|
+
name="identifier",
|
|
27
|
+
field=models.CharField(
|
|
28
|
+
help_text="Custom Unique identifier for this layout.",
|
|
29
|
+
max_length=100,
|
|
30
|
+
unique=True,
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
migrations.AlterField(
|
|
34
|
+
model_name="layoutmodel",
|
|
35
|
+
name="name",
|
|
36
|
+
field=models.CharField(
|
|
37
|
+
help_text="Display name for this layout.", max_length=255
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
migrations.AlterField(
|
|
41
|
+
model_name="layoutmodel",
|
|
42
|
+
name="render_tree",
|
|
43
|
+
field=models.JSONField(
|
|
44
|
+
help_text="Serialized RenderTree representing this layout."
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
from django.db import models
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class LayoutModel(models.Model):
|
|
8
|
+
id: models.UUIDField = models.UUIDField(
|
|
9
|
+
primary_key=True,
|
|
10
|
+
default=uuid.uuid4,
|
|
11
|
+
editable=False,
|
|
12
|
+
help_text="Unique id for this layout.",
|
|
13
|
+
)
|
|
14
|
+
identifier: models.CharField = models.CharField(
|
|
15
|
+
unique=True,
|
|
16
|
+
max_length=100,
|
|
17
|
+
help_text="Custom Unique identifier for this layout.",
|
|
18
|
+
)
|
|
19
|
+
name: models.CharField = models.CharField(
|
|
20
|
+
max_length=255, help_text="Display name for this layout."
|
|
21
|
+
)
|
|
22
|
+
render_tree: models.JSONField = models.JSONField(
|
|
23
|
+
help_text="Serialized RenderTree representing this layout."
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def __str__(self):
|
|
27
|
+
return self.identifier
|
|
28
|
+
|
|
29
|
+
class Meta:
|
|
30
|
+
"""
|
|
31
|
+
Metadata describing the Layout database table.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
verbose_name = "Layout"
|
|
35
|
+
verbose_name_plural = "Layouts"
|
|
36
|
+
|
|
37
|
+
db_table: Final[str] = "mcms_layouts_layout"
|
|
38
|
+
|
|
39
|
+
ordering: Final[tuple[str, ...]] = ("identifier",)
|
mcms_layouts/py.typed
ADDED
|
File without changes
|
mcms_layouts/registry.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from mcms_render.serialization import RenderTreeSerializer
|
|
2
|
+
|
|
3
|
+
from mcms_layouts.models.layout import LayoutModel
|
|
4
|
+
from mcms_layouts.mapping import layout_model_to_domain
|
|
5
|
+
from mcms_layouts.layout import MCMSLayout
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LayoutRepository:
|
|
9
|
+
def create(self, layout: MCMSLayout) -> MCMSLayout:
|
|
10
|
+
render_tree_serializer: RenderTreeSerializer = RenderTreeSerializer()
|
|
11
|
+
|
|
12
|
+
LayoutModel.objects.create(
|
|
13
|
+
name=layout.name,
|
|
14
|
+
identifier=layout.identifier,
|
|
15
|
+
render_tree=render_tree_serializer.to_json(layout.render_tree),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
return layout
|
|
19
|
+
|
|
20
|
+
def update_by_id(self, id: str, layout: MCMSLayout) -> MCMSLayout:
|
|
21
|
+
render_tree_serializer: RenderTreeSerializer = RenderTreeSerializer()
|
|
22
|
+
|
|
23
|
+
LayoutModel.objects.filter(
|
|
24
|
+
id=id,
|
|
25
|
+
).update(
|
|
26
|
+
name=layout.name,
|
|
27
|
+
identifier=layout.identifier,
|
|
28
|
+
render_tree=render_tree_serializer.to_json(layout.render_tree),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return layout
|
|
32
|
+
|
|
33
|
+
def update(self, layout: MCMSLayout) -> MCMSLayout:
|
|
34
|
+
render_tree_serializer: RenderTreeSerializer = RenderTreeSerializer()
|
|
35
|
+
|
|
36
|
+
LayoutModel.objects.filter(
|
|
37
|
+
identifier=layout.identifier,
|
|
38
|
+
).update(
|
|
39
|
+
name=layout.name,
|
|
40
|
+
render_tree=render_tree_serializer.to_json(layout.render_tree),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return layout
|
|
44
|
+
|
|
45
|
+
def get(self, identifier: str) -> MCMSLayout | None:
|
|
46
|
+
layout_model = LayoutModel.objects.get(identifier=identifier)
|
|
47
|
+
|
|
48
|
+
if not layout_model:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
return layout_model_to_domain(layout_model)
|
|
52
|
+
|
|
53
|
+
def get_by_id(self, layout_id: str) -> MCMSLayout:
|
|
54
|
+
layout_model = LayoutModel.objects.get(id=layout_id)
|
|
55
|
+
|
|
56
|
+
return layout_model_to_domain(layout_model)
|
|
57
|
+
|
|
58
|
+
def get_all(
|
|
59
|
+
self,
|
|
60
|
+
) -> list[MCMSLayout]:
|
|
61
|
+
"""Loads all layouts to the layout_registry. This must be called only once"""
|
|
62
|
+
layout_models = LayoutModel.objects.all()
|
|
63
|
+
|
|
64
|
+
result_set = []
|
|
65
|
+
for layout_model in layout_models:
|
|
66
|
+
layout = layout_model_to_domain(layout_model)
|
|
67
|
+
result_set.append(layout)
|
|
68
|
+
|
|
69
|
+
return result_set
|
|
70
|
+
|
|
71
|
+
def delete(self, identifier: str):
|
|
72
|
+
LayoutModel.objects.filter(identifier=identifier).delete()
|
mcms_layouts/settings.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: mcms-layouts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Provides reusable page layouts built on the MCMS `RenderTree` architecture
|
|
5
|
+
Author: MikemathuKE
|
|
6
|
+
Author-email: MikemathuKE <michaelmathu6@gmail.com>
|
|
7
|
+
Requires-Dist: mcms-core
|
|
8
|
+
Requires-Dist: mcms-render
|
|
9
|
+
Requires-Python: >=3.13
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# MCMS Layouts
|
|
13
|
+
|
|
14
|
+
`mcms_layouts` provides reusable page layouts built on the MCMS `RenderTree` architecture. A layout defines the structural composition shared across multiple pages and identifies where individual page content should be inserted.
|
|
15
|
+
|
|
16
|
+
Layouts allow pages to share common structures such as headers, navigation, sidebars, footers, and content containers without duplicating those structures in every page.
|
|
17
|
+
|
|
18
|
+
## Responsibilities
|
|
19
|
+
|
|
20
|
+
- Define and manage reusable layout definitions.
|
|
21
|
+
- Represent each layout using a `RenderTree`.
|
|
22
|
+
- Identify the page-content injection point within a layout.
|
|
23
|
+
- Provide layouts that can be associated with multiple pages.
|
|
24
|
+
- Keep layout structure independent of individual page content.
|
|
25
|
+
- Support layout reuse without sharing mutable render-node instances between pages.
|
|
26
|
+
|
|
27
|
+
## Layout Architecture
|
|
28
|
+
|
|
29
|
+
A layout is a reusable definition containing a `RenderTree`.
|
|
30
|
+
|
|
31
|
+
The tree contains ordinary MCMS components, including structural components and an `Empty` component designated as the page-content placeholder.
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
LayoutDefinition
|
|
35
|
+
├── identifier
|
|
36
|
+
├── name
|
|
37
|
+
├── description
|
|
38
|
+
└── RenderTree
|
|
39
|
+
├── Header
|
|
40
|
+
├── Navigation
|
|
41
|
+
├── Empty (layout_content=True)
|
|
42
|
+
└── Footer
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The layout tree defines the shared page structure. It does not contain the actual content of an individual page.
|
|
46
|
+
|
|
47
|
+
## Content Injection
|
|
48
|
+
|
|
49
|
+
Layouts use an `Empty` component to identify where page content should be injected.
|
|
50
|
+
|
|
51
|
+
The designated component is identified through its `layout_content` field:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
layout_content = True
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This is an instance-level property of the `Empty` component's render node. It distinguishes the content placeholder from other uses of the same component.
|
|
58
|
+
|
|
59
|
+
During composition, the page's content tree replaces the designated placeholder in the layout tree.
|
|
60
|
+
|
|
61
|
+
### Example
|
|
62
|
+
|
|
63
|
+
A layout might contain:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
Layout RenderTree
|
|
67
|
+
├── Header
|
|
68
|
+
├── Navigation
|
|
69
|
+
├── Empty (layout_content=True)
|
|
70
|
+
└── Footer
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
A page might contain:
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
Page RenderTree
|
|
77
|
+
├── Hero
|
|
78
|
+
├── About
|
|
79
|
+
└── Contact
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
After composition:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
Composed RenderTree
|
|
86
|
+
├── Header
|
|
87
|
+
├── Navigation
|
|
88
|
+
├── Hero
|
|
89
|
+
├── About
|
|
90
|
+
├── Contact
|
|
91
|
+
└── Footer
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The resulting tree is an ordinary `RenderTree` and can be processed by the existing rendering pipeline.
|
|
95
|
+
|
|
96
|
+
## Layout Composition
|
|
97
|
+
|
|
98
|
+
The responsibility for combining layout and page trees belongs to `mcms_render`, which owns the `RenderTree` structure and its manipulation operations.
|
|
99
|
+
|
|
100
|
+
The composition process follows these steps:
|
|
101
|
+
|
|
102
|
+
1. Retrieve the selected layout's `RenderTree`.
|
|
103
|
+
2. Clone the layout tree to create an independent composition.
|
|
104
|
+
3. Locate the `Empty` render node with `layout_content=True`.
|
|
105
|
+
4. Clone the page's content tree.
|
|
106
|
+
5. Replace the placeholder with the cloned page content.
|
|
107
|
+
6. Return the composed `RenderTree`.
|
|
108
|
+
|
|
109
|
+
The original layout and page trees remain unchanged.
|
|
110
|
+
|
|
111
|
+
Composition must preserve the existing `RenderTree` invariants:
|
|
112
|
+
|
|
113
|
+
- Unique node identifiers.
|
|
114
|
+
- Valid node registry entries.
|
|
115
|
+
- Correct parent-child relationships.
|
|
116
|
+
- Consistent child ordering.
|
|
117
|
+
- No shared node instances between independent trees.
|
|
118
|
+
- No cycles.
|
|
119
|
+
|
|
120
|
+
## Relationship with Pages
|
|
121
|
+
|
|
122
|
+
A page references a layout and maintains its own content `RenderTree`.
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
Page
|
|
126
|
+
├── Layout Reference
|
|
127
|
+
└── Content RenderTree
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The layout remains independently managed and can be reused by multiple pages.
|
|
131
|
+
|
|
132
|
+
Changing a page's layout does not require modifying its content tree. Similarly, modifying page content does not modify the reusable layout definition.
|
|
133
|
+
|
|
134
|
+
The composed tree is produced separately from the stored layout and page definitions.
|
|
135
|
+
|
|
136
|
+
## Relationship with Templates
|
|
137
|
+
|
|
138
|
+
Layouts and templates serve different purposes:
|
|
139
|
+
|
|
140
|
+
| Concept | Responsibility |
|
|
141
|
+
|---|---|
|
|
142
|
+
| Layout | Provides reusable structural composition surrounding page content |
|
|
143
|
+
| Template | Provides reusable component composition that can be inserted into page content |
|
|
144
|
+
|
|
145
|
+
A template is instantiated and absorbed into a page's content tree during authoring.
|
|
146
|
+
|
|
147
|
+
A layout is associated with a page and combined with its content tree during composition.
|
|
148
|
+
|
|
149
|
+
## Architectural Integrations
|
|
150
|
+
|
|
151
|
+
| Package | Relationship |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `mcms_core` | Provides shared infrastructure and exception conventions |
|
|
154
|
+
| `mcms_components` | Provides the components used to construct layouts, including structural components and `Empty` |
|
|
155
|
+
| `mcms_render` | Owns the `RenderTree` model, cloning, insertion, and layout-page composition |
|
|
156
|
+
| `mcms_pages` | Associates pages with layouts and maintains page content trees |
|
|
157
|
+
| `mcms_templates` | Provides reusable authoring-time component compositions |
|
|
158
|
+
| `mcms_editor` | Provides the authoring experience for creating and editing layouts |
|
|
159
|
+
|
|
160
|
+
These relationships describe architectural responsibilities. Refer to the package's `pyproject.toml` for its actual direct Python dependencies.
|
|
161
|
+
|
|
162
|
+
## Architectural Principles
|
|
163
|
+
|
|
164
|
+
### 1. Layouts are RenderTrees
|
|
165
|
+
|
|
166
|
+
A layout uses the same `RenderTree` representation as pages and templates. No separate layout-node or rendering model is introduced.
|
|
167
|
+
|
|
168
|
+
### 2. Layouts are reusable
|
|
169
|
+
|
|
170
|
+
A single layout can be associated with multiple pages without duplicating its structural definition.
|
|
171
|
+
|
|
172
|
+
### 3. Page content remains independent
|
|
173
|
+
|
|
174
|
+
The page owns its content tree, while the layout owns its structural tree.
|
|
175
|
+
|
|
176
|
+
### 4. Content injection is explicit
|
|
177
|
+
|
|
178
|
+
The `Empty` component with `layout_content=True` identifies the content injection point. Ordinary `Empty` components are not automatically treated as layout placeholders.
|
|
179
|
+
|
|
180
|
+
### 5. Composition does not mutate source trees
|
|
181
|
+
|
|
182
|
+
Layout-page composition operates on cloned trees. The original layout and page definitions remain unchanged.
|
|
183
|
+
|
|
184
|
+
### 6. The composed tree is a normal RenderTree
|
|
185
|
+
|
|
186
|
+
After composition, the resulting tree follows the same structural rules and rendering pipeline as any other MCMS RenderTree.
|
|
187
|
+
|
|
188
|
+
## Dependencies
|
|
189
|
+
|
|
190
|
+
### Architectural integrations
|
|
191
|
+
|
|
192
|
+
`mcms_render` is responsible for tree composition and manipulation. `mcms_components` provides the components used in layout definitions, while `mcms_pages` manages the association between pages and layouts.
|
|
193
|
+
|
|
194
|
+
### Python distribution dependencies
|
|
195
|
+
|
|
196
|
+
All MCMS Packages rely on django
|
|
197
|
+
|
|
198
|
+
## Development
|
|
199
|
+
|
|
200
|
+
Run the package tests from the repository root:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
uv run pytest packages/mcms-layouts/tests
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Run the repository-configured Ruff and mypy checks where applicable.
|
|
207
|
+
|
|
208
|
+
## Future Considerations
|
|
209
|
+
|
|
210
|
+
Potential future capabilities include:
|
|
211
|
+
|
|
212
|
+
- Multiple named content slots within a layout.
|
|
213
|
+
- Layout inheritance or nested layout structures.
|
|
214
|
+
- Layout-specific editor interfaces.
|
|
215
|
+
- Layout previews.
|
|
216
|
+
- Layout versioning and publishing.
|
|
217
|
+
- Layout assignment rules based on page type or other page metadata.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
mcms_layouts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mcms_layouts/admin.py,sha256=u_tY-XByOyj10C_tHDGnJYVj0JC1nMTCclo14Ax08U8,1283
|
|
3
|
+
mcms_layouts/apps.py,sha256=-I8qRUPDcjOrbAnatzJHn78360Uk7oCjZ2-aAhvra3s,545
|
|
4
|
+
mcms_layouts/exceptions.py,sha256=V4RcJ5IYTDXe2w8JKwZvwSwJHn0EjWI28FKBK6GYJOk,321
|
|
5
|
+
mcms_layouts/layout.py,sha256=tZLRT0qBY1_r3qMXMmhOrIpF44MlaSKExvTYSfiUYfg,741
|
|
6
|
+
mcms_layouts/manager.py,sha256=c0BxnH-UDsRhMVbOfk7JGs8LIw1R6NhAPgzMUtnun3Q,2260
|
|
7
|
+
mcms_layouts/mapping.py,sha256=kJeyC-Uq_OU_JsPtZJ1jt1xwfSvaWyUDii0gxkz2SZs,485
|
|
8
|
+
mcms_layouts/migrations/0001_initial.py,sha256=2gIFiMR9QRIknKppEZNnblAoJ-4JxV8iyaOMNdPuzJU,1000
|
|
9
|
+
mcms_layouts/migrations/0002_alter_layoutmodel_id_alter_layoutmodel_identifier_and_more.py,sha256=aeW_oFPUuCyTPvTToYlrAswX2TaIpgtt-tSGs-897-o,1346
|
|
10
|
+
mcms_layouts/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
mcms_layouts/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
mcms_layouts/models/layout.py,sha256=Td_IxHeFoH6VbqlTG185gr7kMVXcjALKnCbs3N_X5S8,1031
|
|
13
|
+
mcms_layouts/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
mcms_layouts/registry.py,sha256=7PFBVhqyXv9hFKa0rAzcYb0Lj6nxHQTmBhgiT69MecE,247
|
|
15
|
+
mcms_layouts/repository.py,sha256=CSx1_ijJZ1kRHsPmdhWIl8_HvJhzpf7KtyeWcMcw51o,2262
|
|
16
|
+
mcms_layouts/settings.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
mcms_layouts-0.1.0.dist-info/WHEEL,sha256=MWx7psoF7KNST9G72pGtiBYuaXRXQXBk9pw5R6FzYko,80
|
|
18
|
+
mcms_layouts-0.1.0.dist-info/METADATA,sha256=loDyhYLDsIJcS2cwRJSo51PIH_nCNPYD3NTkSdym1UI,7085
|
|
19
|
+
mcms_layouts-0.1.0.dist-info/RECORD,,
|