Bootstrap the plugin-facing SDK module so the fleet migration (P2) becomes a mechanical block/core/X -> block/pluginsdk/X import rewrite. - abi/proto/v1: the single source-of-truth ABI proto tree, copied from the cms authoring source (cms/backend/abi/proto/v1) with go_package retargeted to git.dev.alexdunmow.com/block/pluginsdk/abi/v1;abiv1. Kills the hand-kept cms/core proto duplication (audit gap 4). - abi/v1: generated Go bindings (buf generate); byte-identical to core's abi/v1 save the embedded go_package path. - plugin/ (registration + DI surface), plugin/wasmguest/** (transport shim, caps stubs, bnwasm db driver, testdata fixtures + golden .pb), and the guest-facing type packages: blocks (+builtin/shared/tags), templates (+pongo/bn), auth, settings, content, gating, crypto, rbac, video, ai, subscriptions, menus, datasources. Internal imports rewritten core -> pluginsdk; zero block/core references remain. - README/AGENTS(+CLAUDE symlink)/Makefile: proto is the contract, Go is one binding; no replace directives; templates/bn is a synced copy authored in cms. Spec: cms docs/superpowers/specs/2026-07-07-proto-first-plugin-sdk-design.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package pongo
|
|
|
|
import (
|
|
"context"
|
|
"maps"
|
|
|
|
"git.dev.alexdunmow.com/block/ninjatpl"
|
|
|
|
"git.dev.alexdunmow.com/block/pluginsdk/blocks"
|
|
"git.dev.alexdunmow.com/block/pluginsdk/templates/bn"
|
|
)
|
|
|
|
// buildPageContext builds a ninjatpl.Context with pre-rendered head/body HTML
|
|
// and all page-level variables from the standard doc map.
|
|
func (e *Engine) buildPageContext(ctx context.Context, doc map[string]any) ninjatpl.Context {
|
|
title := "Untitled"
|
|
if t, ok := doc["title"].(string); ok && t != "" {
|
|
title = t
|
|
}
|
|
|
|
slots := make(map[string]string)
|
|
if s, ok := doc["slots"].(map[string]string); ok {
|
|
slots = s
|
|
}
|
|
|
|
themeMode := "dark"
|
|
if tm, ok := doc["theme_mode"].(string); ok && tm != "" {
|
|
themeMode = tm
|
|
}
|
|
|
|
themeCSS := ""
|
|
if tc, ok := doc["theme_css"].(string); ok {
|
|
themeCSS = tc
|
|
}
|
|
|
|
structuredData := ""
|
|
if sd, ok := doc["structured_data"].(string); ok {
|
|
structuredData = sd
|
|
}
|
|
|
|
cssHash := ""
|
|
if ch, ok := doc["css_hash"].(string); ok {
|
|
cssHash = ch
|
|
}
|
|
|
|
pageviewNonce := ""
|
|
if pn, ok := doc["pageview_nonce"].(string); ok {
|
|
pageviewNonce = pn
|
|
}
|
|
|
|
settings := bn.ParseSiteSettings(doc)
|
|
pageMeta := bn.ParsePageMeta(doc)
|
|
engagementConfig := bn.ParseEngagementConfig(doc)
|
|
|
|
headHTML := renderComponent(ctx, bn.Head(bn.HeadData{
|
|
Title: title,
|
|
Settings: settings,
|
|
PageMeta: pageMeta,
|
|
ThemeMode: themeMode,
|
|
ThemeCSS: themeCSS,
|
|
PluginStyles: e.stylePaths,
|
|
StructuredData: structuredData,
|
|
CSSHash: cssHash,
|
|
PageviewNonce: pageviewNonce,
|
|
EngagementConfig: engagementConfig,
|
|
}))
|
|
bodyEndHTML := renderComponent(ctx, bn.BodyEnd(settings))
|
|
bannerHTML := renderComponent(ctx, bn.AdminBypassBanner(settings))
|
|
|
|
slotsAny := make(map[string]any, len(slots))
|
|
for k, v := range slots {
|
|
slotsAny[k] = v
|
|
}
|
|
|
|
return ninjatpl.Context{
|
|
"head_html": headHTML,
|
|
"body_end_html": bodyEndHTML,
|
|
"admin_banner_html": bannerHTML,
|
|
|
|
"title": title,
|
|
"slots": slotsAny,
|
|
"theme_mode": themeMode,
|
|
"theme_css": themeCSS,
|
|
"css_hash": cssHash,
|
|
|
|
"site_settings": settings,
|
|
"page_meta": pageMeta,
|
|
}
|
|
}
|
|
|
|
// buildBlockContext builds a ninjatpl.Context for block rendering.
|
|
// Content fields are available directly; request context is under "ctx".
|
|
func buildBlockContext(ctx context.Context, content map[string]any) ninjatpl.Context {
|
|
pongoCtx := make(ninjatpl.Context, len(content)+1)
|
|
maps.Copy(pongoCtx, content)
|
|
if bc := blocks.GetBlockContext(ctx); bc != nil {
|
|
pongoCtx["ctx"] = bc.ToMap()
|
|
}
|
|
return pongoCtx
|
|
}
|