fix(html): preserve responsive block paths
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
e8d2a7f7e7
commit
0fcffb029d
2 changed files with 18 additions and 1 deletions
13
path_test.go
13
path_test.go
|
|
@ -121,6 +121,19 @@ func TestNestedLayout_ThroughElementWrapper(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNestedLayout_ThroughResponsiveWrapper(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
inner := NewLayout("C").C(Raw("wrapped"))
|
||||
wrapped := NewResponsive().
|
||||
Variant("desktop", inner)
|
||||
got := NewLayout("C").C(wrapped).Render(ctx)
|
||||
|
||||
if !strings.Contains(got, `data-block="C-0-C-0"`) {
|
||||
t.Fatalf("responsive wrapper should preserve nested block path, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedLayout_NilChild(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,10 @@ func (r *Responsive) Variant(name string, layout *Layout) *Responsive {
|
|||
// responsive.go: Render produces HTML with each variant in a data-variant container.
|
||||
// Example: NewResponsive().Variant("desktop", NewLayout("C")).Render(NewContext()).
|
||||
func (r *Responsive) Render(ctx *Context) string {
|
||||
return r.renderWithPath(ctx, "")
|
||||
}
|
||||
|
||||
func (r *Responsive) renderWithPath(ctx *Context, path string) string {
|
||||
if r == nil {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -125,7 +129,7 @@ func (r *Responsive) Render(ctx *Context) string {
|
|||
b.WriteString(` data-variant="`)
|
||||
b.WriteString(escapeAttr(v.name))
|
||||
b.WriteString(`">`)
|
||||
b.WriteString(Render(v.layout, ctx))
|
||||
b.WriteString(renderNodeWithPath(v.layout, ctx, path))
|
||||
b.WriteString(`</div>`)
|
||||
}
|
||||
return b.String()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue