From 9d1954d70a4931b4d3ee563d512328ee1687d77a Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Tue, 28 Jul 2026 11:58:19 -0400 Subject: [PATCH] feat: page prop now falls through (implicit access). --- it/it.odin | 28 ++++++++++++++++++++++++++++ mustache/mustache.odin | 17 ++++++++++++++++- render.odin | 11 +++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 it/it.odin diff --git a/it/it.odin b/it/it.odin new file mode 100644 index 0000000..c53ce09 --- /dev/null +++ b/it/it.odin @@ -0,0 +1,28 @@ +package main + +import "core:fmt" + +Ctx :: struct { + title: string, + using page: Page, + site: Site, +} + +Page :: struct { + title: string, +} + +Site :: struct { + title: string, +} + +main :: proc() { + site := Ctx { + site = Site{title = "foo"}, + page = Page{title = "bar"}, + } + + fmt.printfln("%+v", site) + fmt.printf("%+v", site) +} + diff --git a/mustache/mustache.odin b/mustache/mustache.odin index a306c53..93930e2 100644 --- a/mustache/mustache.odin +++ b/mustache/mustache.odin @@ -1,5 +1,6 @@ package mustache +import "base:runtime" import "core:fmt" import "core:log" import "core:reflect" @@ -147,7 +148,21 @@ render :: proc( ctx := make([dynamic]any, 0, 4, allocator) defer delete(ctx) - append(&ctx, data) + + // If data is a []any, expand into individual context frames. + // Otherwise, push as a single frame. + elem_info, count, slice_data := list_info(data) + if elem_info != nil { + if _, is_any := elem_info.variant.(runtime.Type_Info_Any); is_any { + for j in 0 ..< count { + append(&ctx, extract_list_element(elem_info, slice_data, j)) + } + } else { + append(&ctx, data) + } + } else { + append(&ctx, data) + } all_nodes := tmpl.nodes[:] err = render_nodes(tmpl, all_nodes, &ctx, partials, &builder) diff --git a/render.odin b/render.odin index 38a2d89..c6a6d0e 100644 --- a/render.odin +++ b/render.odin @@ -103,10 +103,17 @@ capitalize :: proc(s: string) -> string { render_template :: proc( content_tpl: mustache.Template, - data: Template_Context, + ctx: Template_Context, partials: map[string]mustache.Template, ) -> string { - result, err := mustache.render(content_tpl, data, partials) + result, err := mustache.render( + content_tpl, + []any { /*ctx.site,*/ + ctx.page, + ctx, + }, + partials, + ) if err != nil { log.errorf( "%s",