feat(html): Metadata alias on Context + Responsive.Add with media-query hint
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Brings the portable pieces of mini's feat/main-session-work onto dev:

- context.go: Context.Metadata field — alias for Data, references the same
  underlying map. Both fields interchangeable at read/write sites.
- responsive.go: responsiveVariant gains an optional media field for CSS
  media-query hints (e.g. "(min-width: 1024px)"); new Responsive.Add(name,
  layout, media...) method. Existing Variant(name, layout) becomes a thin
  alias over Add.
- go.mod: drop stale dappco.re/go/core/{inference,log} indirect requires
  (refreshed by go mod tidy — forge.lthn.ai/core/{go-inference,go-log}).

Mini's local deps/go-i18n/reversal grammar-vector rewrite does not apply to
dev: dev consumes reversal as an external package (dappco.re/go/core/i18n/reversal)
rather than an internal fork. That portion of the branch is left on
feat/main-session-work for future re-integration.

Verified: GOWORK=off go build ./... + go test ./... passes.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-04-14 19:22:17 +01:00
parent 4a924b0be4
commit 286731e398
3 changed files with 24 additions and 4 deletions

View file

@ -11,11 +11,15 @@ type Translator interface {
// Context carries rendering state through the node tree.
// Usage example: ctx := NewContext()
//
// Metadata is an alias for Data — both fields reference the same underlying map.
// Treat them as interchangeable; use whichever reads best in context.
type Context struct {
Identity string
Locale string
Entitlements func(feature string) bool
Data map[string]any
Metadata map[string]any
service Translator
}
@ -39,8 +43,10 @@ func applyLocaleToService(svc Translator, locale string) {
// NewContext creates a new rendering context with sensible defaults.
// Usage example: html := Render(Text("welcome"), NewContext("en-GB"))
func NewContext(locale ...string) *Context {
data := make(map[string]any)
ctx := &Context{
Data: make(map[string]any),
Data: data,
Metadata: data, // alias — same underlying map
}
if len(locale) > 0 {
ctx.SetLocale(locale[0])

4
go.mod
View file

@ -12,8 +12,8 @@ require (
)
require (
dappco.re/go/core/inference v0.1.4 // indirect
dappco.re/go/core/log v0.0.4 // indirect
forge.lthn.ai/core/go-inference v0.1.4 // indirect
forge.lthn.ai/core/go-log v0.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/text v0.35.0 // indirect

View file

@ -18,6 +18,7 @@ type Responsive struct {
type responsiveVariant struct {
name string
layout *Layout
media string // optional CSS media-query hint (e.g. "(min-width: 768px)")
}
// NewResponsive creates a new multi-variant responsive compositor.
@ -29,11 +30,24 @@ func NewResponsive() *Responsive {
// Variant adds a named layout variant (e.g., "desktop", "tablet", "mobile").
// Usage example: NewResponsive().Variant("desktop", NewLayout("HLCRF"))
// Variants render in insertion order.
// Variant is equivalent to Add(name, layout) with no media-query hint.
func (r *Responsive) Variant(name string, layout *Layout) *Responsive {
return r.Add(name, layout)
}
// Add registers a responsive variant. The optional media argument carries a
// CSS media-query hint for downstream CSS generation (e.g. "(min-width: 768px)").
//
// Usage example: NewResponsive().Add("desktop", NewLayout("HLCRF"), "(min-width: 1024px)")
func (r *Responsive) Add(name string, layout *Layout, media ...string) *Responsive {
if r == nil {
r = NewResponsive()
}
r.variants = append(r.variants, responsiveVariant{name: name, layout: layout})
variant := responsiveVariant{name: name, layout: layout}
if len(media) > 0 {
variant.media = media[0]
}
r.variants = append(r.variants, variant)
return r
}