diff --git a/context.go b/context.go index f5d40e5..91167ef 100644 --- a/context.go +++ b/context.go @@ -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]) diff --git a/go.mod b/go.mod index f9d51e8..ec55646 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/responsive.go b/responsive.go index 896d0ae..fc25af0 100644 --- a/responsive.go +++ b/responsive.go @@ -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 }