From 80fef0061bc199fbd807d8796ef59a6c2c685612 Mon Sep 17 00:00:00 2001 From: early Date: Sun, 24 Nov 2024 17:10:01 -0700 Subject: [PATCH] Support multiple results from compile --- web/internal/compile/compile.go | 17 ++++++++--------- web/page/page.go | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/web/internal/compile/compile.go b/web/internal/compile/compile.go index b6f1a86..5149dbf 100644 --- a/web/internal/compile/compile.go +++ b/web/internal/compile/compile.go @@ -42,15 +42,14 @@ type Result struct { TemplateDataLoader render.Loader } -func Compile(root TemplateSource, transform ...func(root *html.Node)) (Result, error) { - var result Result +func Compile(root TemplateSource, transform ...func(root *html.Node)) ([]Result, error) { reader, err := root.Source().Open() if err != nil { - return result, err + return nil, err } document, err := html.Parse(reader) if err != nil { - return result, err + return nil, err } fullDependencies := Sources{root.Name(): root} @@ -82,7 +81,7 @@ func Compile(root TemplateSource, transform ...func(root *html.Node)) (Result, e } err := insertComponentSource(subSource, document) if err != nil { - return result, err + return nil, err } delete(fullDependencies, name) } @@ -129,7 +128,7 @@ func Compile(root TemplateSource, transform ...func(root *html.Node)) (Result, e } err = process(document, computeRoot) if err != nil { - return result, err + return nil, err } // POSTPROCESSING @@ -157,14 +156,14 @@ func Compile(root TemplateSource, transform ...func(root *html.Node)) (Result, e raw, err := renderDocument(document) if err != nil { - return result, err + return nil, err } - result = Result{ + result := Result{ TemplateRaw: raw, TemplateFuncs: templateFuncs, TemplateDataLoader: computeRoot, } - return result, err + return []Result{result}, nil } func renderDocument(document *html.Node) (string, error) { diff --git a/web/page/page.go b/web/page/page.go index da7607a..2674eb2 100644 --- a/web/page/page.go +++ b/web/page/page.go @@ -96,11 +96,12 @@ func New(name string, source string, optional ...Config) *Page { if p.indent != "" { sourceTransform = htmltree.Prettify(p.indent) } - result, err := compile.Compile(p, sourceTransform) + results, err := compile.Compile(p, sourceTransform) if err != nil { p.err = err return p } + result := results[0] p.raw = result.TemplateRaw p.templateLoad = result.TemplateDataLoader -- 2.39.5