func RenderTemplateFile(filename string, data interface{}, out io.Writer) error { rootNode, err := parseFile(filename) if err != nil { return err } cont := makeContext(data, nil) template := goquery.NewDocumentFromNode(rootNode).Find("html") // wrap goquery around the DOM handleGatsRemoves(template) // take out everything that definitely won't be shown err = handleGatsTranscludes(template) // transclude in all the sub-templates if err != nil { return err } err = fillInTemplate(template, cont) // process the template handleGatsOmitTag(template) // make sure this one comes last, it can interfere with other attributes if err == nil { html.Render(out, rootNode) // render the DOM back to html and send it off } return err }
func handleGatsTranscludes(scope *goquery.Selection) (result error) { for scope.Find("[gatstransclude]").Length() > 0 && result == nil { handleGats(scope, "[gatstransclude]", func(ts string, sel *goquery.Selection) { if result != nil { return } filename, selector, res := splitString(ts) if res != nil { result = res return } rootNode, res := parseFile(filename) if res != nil { result = res return } newKids := goquery.NewDocumentFromNode(rootNode).Find(selector) sel.Empty().Append(newKids) }) } return result }