template render with BBP

This commit is contained in:
spf13 2015-01-30 11:25:54 -08:00
parent 2f2297bdb3
commit 5441fc5dfc

View file

@ -17,11 +17,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/eknkc/amber"
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
"github.com/yosssi/ace"
"html" "html"
"html/template" "html/template"
"io" "io"
@ -32,6 +27,13 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"github.com/eknkc/amber"
"github.com/spf13/cast"
bp "github.com/spf13/hugo/bufferpool"
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
"github.com/yosssi/ace"
) )
var localTemplates *template.Template var localTemplates *template.Template
@ -1101,8 +1103,7 @@ func Partial(name string, context_list ...interface{}) template.HTML {
return ExecuteTemplateToHTML(context, "partials/"+name, "theme/partials/"+name) return ExecuteTemplateToHTML(context, "partials/"+name, "theme/partials/"+name)
} }
func ExecuteTemplate(context interface{}, layouts ...string) *bytes.Buffer { func ExecuteTemplate(context interface{}, buffer *bytes.Buffer, layouts ...string) {
buffer := new(bytes.Buffer)
worked := false worked := false
for _, layout := range layouts { for _, layout := range layouts {
@ -1125,13 +1126,13 @@ func ExecuteTemplate(context interface{}, layouts ...string) *bytes.Buffer {
jww.ERROR.Println("Unable to render", layouts) jww.ERROR.Println("Unable to render", layouts)
jww.ERROR.Println("Expecting to find a template in either the theme/layouts or /layouts in one of the following relative locations", layouts) jww.ERROR.Println("Expecting to find a template in either the theme/layouts or /layouts in one of the following relative locations", layouts)
} }
return buffer
} }
func ExecuteTemplateToHTML(context interface{}, layouts ...string) template.HTML { func ExecuteTemplateToHTML(context interface{}, layouts ...string) template.HTML {
b := ExecuteTemplate(context, layouts...) b := bp.GetBuffer()
return template.HTML(string(b.Bytes())) defer bp.PutBuffer(b)
ExecuteTemplate(context, b, layouts...)
return template.HTML(b.String())
} }
func (t *GoHtmlTemplate) LoadEmbedded() { func (t *GoHtmlTemplate) LoadEmbedded() {