| 282 | } |
| 283 | |
| 284 | func (f *Functions) node(writer io.Writer, prefix string, node semantic.Node, arguments ...interface{}) error { |
| 285 | // Collect the arguments to the template |
| 286 | args, err := f.buildArgs(arguments...) |
| 287 | if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | args["Node"] = node |
| 291 | try := make([]string, 0, 4) |
| 292 | ty, err := f.TypeOf(node) |
| 293 | if node != nil && err == nil { |
| 294 | args["Type"] = ty |
| 295 | try = append(try, |
| 296 | prefix+"#"+ty.Name(), |
| 297 | prefix+"."+nodename(ty), |
| 298 | ) |
| 299 | } |
| 300 | if node != ty { |
| 301 | try = append(try, prefix+"."+nodename(node)) |
| 302 | } |
| 303 | try = append(try, prefix+"_Default") |
| 304 | for _, name := range try { |
| 305 | if tmpl := f.templates.Lookup(name); tmpl != nil { |
| 306 | return f.execute(tmpl, writer, args) |
| 307 | } |
| 308 | } |
| 309 | return fmt.Errorf(`Cannot find templates "%s"`, strings.Join(try, `","`)) |
| 310 | } |
| 311 | |
| 312 | // Node dispatches to the template that matches the node best, writing the |
| 313 | // result to the current output writer. |