wire simple pages to PageRenderer (stage 3)

Home, Content (about/delivery/privacy/terms), Contact, and ErrorHTML
now render through the generic PageRenderer instead of hardcoded
templates. Block wrapper divs enable CSS grid targeting. Featured
products block supports layout/card_variant/columns settings for
different page contexts. Contact page uses CSS grid on data-block-type
attributes for two-column layout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-26 18:29:20 +00:00
parent ca9f32fa42
commit c69e51051f
12 changed files with 147 additions and 85 deletions

View File

@ -458,15 +458,15 @@ See: [plan](docs/plans/shipping-sync.md) for implementation details
See: [docs/plans/analytics-v2.md](docs/plans/analytics-v2.md) for v2 plan See: [docs/plans/analytics-v2.md](docs/plans/analytics-v2.md) for v2 plan
### Page Editor ### Page Editor
**Status:** In progress — Stage 2 of 9 complete, 1284 tests **Status:** In progress — Stage 3 of 9 complete, 1284 tests
Database-driven page builder. Every page is a flat list of blocks stored as JSON — add, remove, reorder, and edit blocks on any page. One generic renderer for all pages (no page-specific render functions). Portable blocks (hero, featured_products, image_text, etc.) work on any page. Page-specific blocks (product_hero, cart_items, etc.) are restricted to their native page. Block data loaders dynamically load data based on which blocks are on the page. ETS-cached page definitions. Mobile-first admin editor with live preview, undo/redo, accessible reordering (no drag-and-drop), inline settings forms, and "reset to defaults". CSS-driven page layout (not renderer-driven). Database-driven page builder. Every page is a flat list of blocks stored as JSON — add, remove, reorder, and edit blocks on any page. One generic renderer for all pages (no page-specific render functions). Portable blocks (hero, featured_products, image_text, etc.) work on any page. Page-specific blocks (product_hero, cart_items, etc.) are restricted to their native page. Block data loaders dynamically load data based on which blocks are on the page. ETS-cached page definitions. Mobile-first admin editor with live preview, undo/redo, accessible reordering (no drag-and-drop), inline settings forms, and "reset to defaults". CSS-driven page layout (not renderer-driven).
**Stages:** **Stages:**
1. ~~Foundation — data model, cache, block registry~~ ✅ (`35f96e4`) 1. ~~Foundation — data model, cache, block registry~~ ✅ (`35f96e4`)
2. ~~Page renderer — generic renderer tested in isolation~~ ✅ (`32f54c7`) 2. ~~Page renderer — generic renderer tested in isolation~~ ✅ (`32f54c7`)
3. **Next →** Wire simple pages — Home, Content (x4), Contact, Error 3. ~~Wire simple pages — Home, Content (x4), Contact, Error~~ ✅
4. Wire shop pages — Collection, PDP, Cart, Search 4. **Next →** Wire shop pages — Collection, PDP, Cart, Search
5. Wire order pages + theme preview — CheckoutSuccess, Orders, OrderDetail, theme editor 5. Wire order pages + theme preview — CheckoutSuccess, Orders, OrderDetail, theme editor
6. Admin editor — page list + block management (reorder, add, remove, duplicate, save) 6. Admin editor — page list + block management (reorder, add, remove, duplicate, save)
7. Admin editor — inline block settings editing 7. Admin editor — inline block settings editing

View File

@ -2444,6 +2444,9 @@
max-width: 56rem; max-width: 56rem;
padding-top: 0; padding-top: 0;
padding-bottom: 4rem; padding-bottom: 4rem;
& > [data-block-type="hero"] { grid-column: 1 / -1; }
& > [data-block-type="contact_form"] { grid-column: 1; }
} }
.contact-grid { .contact-grid {
@ -2527,6 +2530,7 @@
.footer-bottom { flex-direction: row; } .footer-bottom { flex-direction: row; }
.pdp-grid { grid-template-columns: repeat(2, 1fr); } .pdp-grid { grid-template-columns: repeat(2, 1fr); }
.contact-grid { grid-template-columns: repeat(2, 1fr); } .contact-grid { grid-template-columns: repeat(2, 1fr); }
.contact-main { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2rem; }
.product-grid[data-columns="fixed-4"] { .product-grid[data-columns="fixed-4"] {
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
} }

View File

@ -1,6 +1,6 @@
# Page builder plan # Page builder plan
Status: In progress (Stage 2 complete) Status: In progress (Stage 3 complete)
## Context ## Context

View File

@ -26,6 +26,9 @@ defmodule Berrypod.Pages do
{:ok, page_data} -> page_data {:ok, page_data} -> page_data
:miss -> get_page_uncached(slug) :miss -> get_page_uncached(slug)
end end
rescue
# ETS table might not exist yet during startup
ArgumentError -> get_page_uncached(slug)
end end
@doc """ @doc """

View File

@ -22,6 +22,8 @@ defmodule Berrypod.Pages.BlockTypes do
%{key: "description", label: "Description", type: :textarea, default: ""}, %{key: "description", label: "Description", type: :textarea, default: ""},
%{key: "cta_text", label: "Button text", type: :text, default: ""}, %{key: "cta_text", label: "Button text", type: :text, default: ""},
%{key: "cta_href", label: "Button link", type: :text, default: ""}, %{key: "cta_href", label: "Button link", type: :text, default: ""},
%{key: "secondary_cta_text", label: "Secondary button text", type: :text, default: ""},
%{key: "secondary_cta_href", label: "Secondary button link", type: :text, default: ""},
%{ %{
key: "variant", key: "variant",
label: "Style", label: "Style",
@ -37,7 +39,28 @@ defmodule Berrypod.Pages.BlockTypes do
allowed_on: :all, allowed_on: :all,
settings_schema: [ settings_schema: [
%{key: "title", label: "Title", type: :text, default: "Featured products"}, %{key: "title", label: "Title", type: :text, default: "Featured products"},
%{key: "product_count", label: "Number of products", type: :number, default: 8} %{key: "product_count", label: "Number of products", type: :number, default: 8},
%{
key: "layout",
label: "Layout",
type: :select,
options: ~w(section grid),
default: "section"
},
%{
key: "card_variant",
label: "Card style",
type: :select,
options: ~w(featured default minimal compact),
default: "featured"
},
%{
key: "columns",
label: "Columns",
type: :select,
options: ~w(auto fixed-4),
default: "auto"
}
], ],
data_loader: :load_featured_products data_loader: :load_featured_products
}, },

View File

@ -65,12 +65,12 @@ defmodule Berrypod.Pages.Defaults do
[ [
block("hero", %{ block("hero", %{
"title" => "About the studio", "title" => "About the studio",
"description" => "", "description" => "Your story goes here \u2013 this is sample content for the demo shop",
"variant" => "sunken" "variant" => "sunken"
}), }),
block("content_body", %{ block("content_body", %{
"image_src" => "/mockups/night-sky-blanket-3", "image_src" => "/mockups/night-sky-blanket-3",
"image_alt" => "Night sky blanket" "image_alt" => "Night sky blanket draped over a chair"
}) })
] ]
end end
@ -78,8 +78,8 @@ defmodule Berrypod.Pages.Defaults do
defp blocks("delivery") do defp blocks("delivery") do
[ [
block("hero", %{ block("hero", %{
"title" => "Delivery information", "title" => "Delivery & returns",
"description" => "", "description" => "Everything you need to know about shipping and returns",
"variant" => "page" "variant" => "page"
}), }),
block("content_body") block("content_body")
@ -90,7 +90,7 @@ defmodule Berrypod.Pages.Defaults do
[ [
block("hero", %{ block("hero", %{
"title" => "Privacy policy", "title" => "Privacy policy",
"description" => "", "description" => "How we handle your personal information",
"variant" => "page" "variant" => "page"
}), }),
block("content_body") block("content_body")
@ -100,8 +100,8 @@ defmodule Berrypod.Pages.Defaults do
defp blocks("terms") do defp blocks("terms") do
[ [
block("hero", %{ block("hero", %{
"title" => "Terms & conditions", "title" => "Terms of service",
"description" => "", "description" => "The legal bits",
"variant" => "page" "variant" => "page"
}), }),
block("content_body") block("content_body")
@ -186,11 +186,16 @@ defmodule Berrypod.Pages.Defaults do
block("hero", %{ block("hero", %{
"variant" => "error", "variant" => "error",
"cta_text" => "Go to Homepage", "cta_text" => "Go to Homepage",
"cta_href" => "/" "cta_href" => "/",
"secondary_cta_text" => "Browse Products",
"secondary_cta_href" => "/collections/all"
}), }),
block("featured_products", %{ block("featured_products", %{
"title" => "Featured products", "title" => "Featured products",
"product_count" => 4 "product_count" => 4,
"layout" => "grid",
"card_variant" => "minimal",
"columns" => "fixed-4"
}) })
] ]
end end

View File

@ -6,6 +6,8 @@ defmodule BerrypodWeb.ErrorHTML do
""" """
use BerrypodWeb, :html use BerrypodWeb, :html
alias Berrypod.Pages
alias Berrypod.Pages.Defaults
alias Berrypod.Settings alias Berrypod.Settings
alias Berrypod.Settings.ThemeSettings alias Berrypod.Settings.ThemeSettings
alias Berrypod.Media alias Berrypod.Media
@ -76,22 +78,26 @@ defmodule BerrypodWeb.ErrorHTML do
{theme_settings, generated_css} = load_theme_data() {theme_settings, generated_css} = load_theme_data()
logo_image = safe_load(&Media.get_logo/0) logo_image = safe_load(&Media.get_logo/0)
header_image = safe_load(&Media.get_header/0) header_image = safe_load(&Media.get_header/0)
products = safe_load(fn -> Products.list_visible_products(limit: 4) end) || []
categories = safe_load(fn -> Products.list_categories() end) || [] categories = safe_load(fn -> Products.list_categories() end) || []
page = safe_load(fn -> Pages.get_page("error") end) || Defaults.for_slug("error")
assigns = assigns =
assigns assigns
|> Map.put(:theme_settings, theme_settings) |> Map.put(:theme_settings, theme_settings)
|> Map.put(:generated_css, generated_css) |> Map.put(:generated_css, generated_css)
|> Map.put(:logo_image, logo_image) |> Map.put(:logo_image, logo_image)
|> Map.put(:header_image, header_image) |> Map.put(:header_image, header_image)
|> Map.put(:products, products)
|> Map.put(:categories, categories) |> Map.put(:categories, categories)
|> Map.put(:mode, :shop) |> Map.put(:mode, :shop)
|> Map.put(:cart_items, []) |> Map.put(:cart_items, [])
|> Map.put(:cart_count, 0) |> Map.put(:cart_count, 0)
|> Map.put(:cart_subtotal, "£0.00") |> Map.put(:cart_subtotal, "£0.00")
|> Map.put(:page, page)
# Load block data (e.g. products for featured_products block)
extra = safe_load(fn -> Pages.load_block_data(page.blocks, assigns) end) || %{}
assigns = Map.merge(assigns, extra)
~H""" ~H"""
<!DOCTYPE html> <!DOCTYPE html>
@ -118,20 +124,7 @@ defmodule BerrypodWeb.ErrorHTML do
data-layout={@theme_settings.layout_width} data-layout={@theme_settings.layout_width}
data-shadow={@theme_settings.card_shadow} data-shadow={@theme_settings.card_shadow}
> >
<BerrypodWeb.PageTemplates.error <BerrypodWeb.PageRenderer.render_page {assigns} />
theme_settings={@theme_settings}
logo_image={@logo_image}
header_image={@header_image}
products={@products}
categories={@categories}
error_code={@error_code}
error_title={@error_title}
error_description={@error_description}
mode={@mode}
cart_items={@cart_items}
cart_count={@cart_count}
cart_subtotal={@cart_subtotal}
/>
</div> </div>
</body> </body>
</html> </html>

View File

@ -3,10 +3,13 @@ defmodule BerrypodWeb.Shop.Contact do
alias Berrypod.Orders alias Berrypod.Orders
alias Berrypod.Orders.OrderNotifier alias Berrypod.Orders.OrderNotifier
alias Berrypod.Pages
alias BerrypodWeb.OrderLookupController alias BerrypodWeb.OrderLookupController
@impl true @impl true
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
page = Pages.get_page("contact")
{:ok, {:ok,
socket socket
|> assign(:page_title, "Contact") |> assign(:page_title, "Contact")
@ -15,7 +18,8 @@ defmodule BerrypodWeb.Shop.Contact do
"Get in touch with us for any questions or help with your order." "Get in touch with us for any questions or help with your order."
) )
|> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/contact") |> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/contact")
|> assign(:tracking_state, :idle)} |> assign(:tracking_state, :idle)
|> assign(:page, page)}
end end
@impl true @impl true
@ -43,7 +47,7 @@ defmodule BerrypodWeb.Shop.Contact do
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<BerrypodWeb.PageTemplates.contact {assigns} /> <BerrypodWeb.PageRenderer.render_page {assigns} />
""" """
end end
end end

View File

@ -2,6 +2,7 @@ defmodule BerrypodWeb.Shop.Content do
use BerrypodWeb, :live_view use BerrypodWeb, :live_view
alias Berrypod.LegalPages alias Berrypod.LegalPages
alias Berrypod.Pages
alias Berrypod.Theme.PreviewData alias Berrypod.Theme.PreviewData
@impl true @impl true
@ -11,65 +12,68 @@ defmodule BerrypodWeb.Shop.Content do
@impl true @impl true
def handle_params(_params, _uri, socket) do def handle_params(_params, _uri, socket) do
config = page_config(socket.assigns.live_action) slug = to_string(socket.assigns.live_action)
{:noreply, assign(socket, config)} page = Pages.get_page(slug)
{seo, content_blocks} = page_config(socket.assigns.live_action)
socket =
socket
|> assign(seo)
|> assign(:page, page)
|> assign(:content_blocks, content_blocks)
{:noreply, socket}
end end
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<BerrypodWeb.PageTemplates.content {assigns} /> <BerrypodWeb.PageRenderer.render_page {assigns} />
""" """
end end
# Returns {seo_assigns, content_blocks} for each content page
defp page_config(:about) do defp page_config(:about) do
%{ {
page_title: "About", %{
page_description: "Your story goes here this is sample content for the demo shop", page_title: "About",
og_url: BerrypodWeb.Endpoint.url() <> "/about", page_description: "Your story goes here \u2013 this is sample content for the demo shop",
active_page: "about", og_url: BerrypodWeb.Endpoint.url() <> "/about"
hero_title: "About the studio", },
hero_description: "Your story goes here this is sample content for the demo shop", PreviewData.about_content()
hero_background: :sunken,
image_src: "/mockups/night-sky-blanket-3",
image_alt: "Night sky blanket draped over a chair",
content_blocks: PreviewData.about_content()
} }
end end
defp page_config(:delivery) do defp page_config(:delivery) do
%{ {
page_title: "Delivery & returns", %{
page_description: "Everything you need to know about shipping and returns.", page_title: "Delivery & returns",
og_url: BerrypodWeb.Endpoint.url() <> "/delivery", page_description: "Everything you need to know about shipping and returns.",
active_page: "delivery", og_url: BerrypodWeb.Endpoint.url() <> "/delivery"
hero_title: "Delivery & returns", },
hero_description: "Everything you need to know about shipping and returns", LegalPages.delivery_content()
content_blocks: LegalPages.delivery_content()
} }
end end
defp page_config(:privacy) do defp page_config(:privacy) do
%{ {
page_title: "Privacy policy", %{
page_description: "How we handle your personal information.", page_title: "Privacy policy",
og_url: BerrypodWeb.Endpoint.url() <> "/privacy", page_description: "How we handle your personal information.",
active_page: "privacy", og_url: BerrypodWeb.Endpoint.url() <> "/privacy"
hero_title: "Privacy policy", },
hero_description: "How we handle your personal information", LegalPages.privacy_content()
content_blocks: LegalPages.privacy_content()
} }
end end
defp page_config(:terms) do defp page_config(:terms) do
%{ {
page_title: "Terms of service", %{
page_description: "The terms and conditions governing purchases from our shop.", page_title: "Terms of service",
og_url: BerrypodWeb.Endpoint.url() <> "/terms", page_description: "The terms and conditions governing purchases from our shop.",
active_page: "terms", og_url: BerrypodWeb.Endpoint.url() <> "/terms"
hero_title: "Terms of service", },
hero_description: "The legal bits", LegalPages.terms_content()
content_blocks: LegalPages.terms_content()
} }
end end
end end

View File

@ -1,11 +1,12 @@
defmodule BerrypodWeb.Shop.Home do defmodule BerrypodWeb.Shop.Home do
use BerrypodWeb, :live_view use BerrypodWeb, :live_view
alias Berrypod.Products alias Berrypod.Pages
@impl true @impl true
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
products = Products.list_visible_products(limit: 8) page = Pages.get_page("home")
extra = Pages.load_block_data(page.blocks, socket.assigns)
base = BerrypodWeb.Endpoint.url() base = BerrypodWeb.Endpoint.url()
site_name = socket.assigns.theme_settings.site_name site_name = socket.assigns.theme_settings.site_name
@ -26,7 +27,8 @@ defmodule BerrypodWeb.Shop.Home do
|> assign(:page_title, "Home") |> assign(:page_title, "Home")
|> assign(:og_url, base <> "/") |> assign(:og_url, base <> "/")
|> assign(:json_ld, org_ld) |> assign(:json_ld, org_ld)
|> assign(:products, products) |> assign(:page, page)
|> assign(extra)
{:ok, socket} {:ok, socket}
end end
@ -34,7 +36,7 @@ defmodule BerrypodWeb.Shop.Home do
@impl true @impl true
def render(assigns) do def render(assigns) do
~H""" ~H"""
<BerrypodWeb.PageTemplates.home {assigns} /> <BerrypodWeb.PageRenderer.render_page {assigns} />
""" """
end end
end end

View File

@ -30,9 +30,9 @@ defmodule BerrypodWeb.PageRenderer do
error_page={@page.slug == "error"} error_page={@page.slug == "error"}
> >
<main id="main-content" class={page_main_class(@page.slug)}> <main id="main-content" class={page_main_class(@page.slug)}>
<%= for block <- @page.blocks do %> <div :for={block <- @page.blocks} data-block-type={block["type"]}>
{render_block(Map.merge(@block_assigns, %{block: block, page_slug: @page.slug}))} {render_block(Map.merge(@block_assigns, %{block: block, page_slug: @page.slug}))}
<% end %> </div>
</main> </main>
</.shop_layout> </.shop_layout>
""" """
@ -85,14 +85,30 @@ defmodule BerrypodWeb.PageRenderer do
assigns = assigns =
assigns assigns
|> assign(:section_title, settings["title"] || "Featured products") |> assign(:section_title, settings["title"] || "Featured products")
|> assign(:layout, settings["layout"] || "section")
|> assign(:card_variant, card_variant(settings["card_variant"]))
|> assign(:columns, grid_columns(settings["columns"]))
~H""" ~H"""
<.featured_products_section <%= if @layout == "grid" do %>
title={@section_title} <.product_grid columns={@columns} theme_settings={@theme_settings}>
products={assigns[:products] || []} <%= for product <- assigns[:products] || [] do %>
theme_settings={@theme_settings} <.product_card
mode={@mode} product={product}
/> theme_settings={@theme_settings}
mode={@mode}
variant={@card_variant}
/>
<% end %>
</.product_grid>
<% else %>
<.featured_products_section
title={@section_title}
products={assigns[:products] || []}
theme_settings={@theme_settings}
mode={@mode}
/>
<% end %>
""" """
end end
@ -728,6 +744,14 @@ defmodule BerrypodWeb.PageRenderer do
defp hero_background("sunken"), do: :sunken defp hero_background("sunken"), do: :sunken
defp hero_background(_), do: :base defp hero_background(_), do: :base
defp card_variant("minimal"), do: :minimal
defp card_variant("compact"), do: :compact
defp card_variant("default"), do: :default
defp card_variant(_), do: :featured
defp grid_columns("fixed-4"), do: :fixed_4
defp grid_columns(_), do: nil
defp breadcrumb_items(%{category: cat, title: title}) when not is_nil(cat) do defp breadcrumb_items(%{category: cat, title: title}) when not is_nil(cat) do
slug = cat |> String.downcase() |> String.replace(" ", "-") slug = cat |> String.downcase() |> String.replace(" ", "-")

View File

@ -66,7 +66,7 @@ defmodule BerrypodWeb.PageRendererTest do
test "delivery page renders hero" do test "delivery page renders hero" do
html = render_page("delivery", %{content_blocks: []}) html = render_page("delivery", %{content_blocks: []})
assert html =~ "Delivery information" assert html =~ "Delivery &amp; returns"
end end
test "privacy page renders hero" do test "privacy page renders hero" do
@ -78,7 +78,7 @@ defmodule BerrypodWeb.PageRendererTest do
test "terms page renders hero" do test "terms page renders hero" do
html = render_page("terms", %{content_blocks: []}) html = render_page("terms", %{content_blocks: []})
assert html =~ "Terms &amp; conditions" assert html =~ "Terms of service"
end end
test "contact page renders hero, form, and sidebar blocks" do test "contact page renders hero, form, and sidebar blocks" do