mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: page prop now falls through (implicit access).
This commit is contained in:
+28
@@ -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)
|
||||
}
|
||||
|
||||
+16
-1
@@ -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)
|
||||
|
||||
+9
-2
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user