MCPcopy Create free account
hub / github.com/abiosoft/mold / parseLayout

Function parseLayout

engine.go:168–204  ·  view source on GitHub ↗
(root templateSet, layoutRaw string, funcMap template.FuncMap)

Source from the content-addressed store, hash-verified

166}
167
168func parseLayout(root templateSet, layoutRaw string, funcMap template.FuncMap) (*templateFile, error) {
169 t, err := template.New("layout").Funcs(funcMap).Parse(layoutRaw)
170 if err != nil {
171 return nil, err
172 }
173
174 layout := &templateFile{
175 Template: t,
176 typ: layoutType,
177 body: layoutRaw,
178 }
179
180 // process template tree for layout
181 refs, err := processTree(layout)
182 if err != nil {
183 return nil, fmt.Errorf("error processing layout: %w", err)
184 }
185 for _, ref := range refs {
186 t := root[ref.name]
187 if t == nil {
188 if ref.typ == partialFunc {
189 return nil, fmt.Errorf("error parsing template '%s': %w", ref.name, ErrNotFound)
190 }
191 tpl, _ := template.New(ref.name).Parse("") // safe to ignore the err
192 t = &templateFile{Template: tpl}
193 }
194
195 t.typ = partialType
196 if err := parsePartial(t); err != nil {
197 return nil, fmt.Errorf("error parsing partial: '%s': %w", ref.name, err)
198 }
199
200 layout.AddParseTree(ref.name, t.Tree)
201 }
202
203 return layout, nil
204}
205
206func parseView(set templateSet, layout *templateFile, name string) (*template.Template, error) {
207 view := template.Must(layout.Clone()) // safe

Callers 1

newEngineFunction · 0.85

Calls 2

processTreeFunction · 0.85
parsePartialFunction · 0.85

Tested by

no test coverage detected