diff --git a/common/templates/context.go b/common/templates/context.go new file mode 100644 index 00000000..08202f86 --- /dev/null +++ b/common/templates/context.go @@ -0,0 +1,56 @@ +package tmpl + +import ( + "errors" + "reflect" +) + +type OutBufferFrame struct { + Body string + Type string + TemplateName string +} + +type CContext struct { + VarHolder string + HoldReflect reflect.Value + TemplateName string + OutBuf *[]OutBufferFrame +} + +func (con *CContext) Push(nType string, body string) { + *con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, nType, con.TemplateName}) +} + +func (con *CContext) GetLastType() string { + outBuf := *con.OutBuf + if len(outBuf) == 0 { + return "" + } + return outBuf[len(outBuf)-1].Type +} + +func (con *CContext) GetLastBody() string { + outBuf := *con.OutBuf + if len(outBuf) == 0 { + return "" + } + return outBuf[len(outBuf)-1].Body +} + +func (con *CContext) SetLastBody(newBody string) error { + outBuf := *con.OutBuf + if len(outBuf) == 0 { + return errors.New("outbuf is empty") + } + outBuf[len(outBuf)-1].Body = newBody + return nil +} + +func (con *CContext) GetLastTemplate() string { + outBuf := *con.OutBuf + if len(outBuf) == 0 { + return "" + } + return outBuf[len(outBuf)-1].TemplateName +} diff --git a/common/templates/templates.go b/common/templates/templates.go index c3e93436..ddf5d3b9 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -2,7 +2,6 @@ package tmpl import ( "bytes" - "errors" "fmt" "io/ioutil" "log" @@ -41,56 +40,6 @@ type CTemplateConfig struct { PackageName string } -type OutBufferFrame struct { - Body string - Type string - TemplateName string -} - -type CContext struct { - VarHolder string - HoldReflect reflect.Value - TemplateName string - OutBuf *[]OutBufferFrame -} - -func (con *CContext) Push(nType string, body string) { - *con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, nType, con.TemplateName}) -} - -func (con *CContext) GetLastType() string { - outBuf := *con.OutBuf - if len(outBuf) == 0 { - return "" - } - return outBuf[len(outBuf)-1].Type -} - -func (con *CContext) GetLastBody() string { - outBuf := *con.OutBuf - if len(outBuf) == 0 { - return "" - } - return outBuf[len(outBuf)-1].Body -} - -func (con *CContext) SetLastBody(newBody string) error { - outBuf := *con.OutBuf - if len(outBuf) == 0 { - return errors.New("outbuf is empty") - } - outBuf[len(outBuf)-1].Body = newBody - return nil -} - -func (con *CContext) GetLastTemplate() string { - outBuf := *con.OutBuf - if len(outBuf) == 0 { - return "" - } - return outBuf[len(outBuf)-1].TemplateName -} - type Fragment struct { Body string TemplateName string @@ -1106,7 +1055,7 @@ func (c *CTemplateSet) compileVarSub(con CContext, varname string, val reflect.V } func (c *CTemplateSet) compileSubTemplate(pcon CContext, node *parse.TemplateNode) { - c.detail("in compileSubTemplate") + c.debugCall("compileSubTemplate", pcon, node) c.detail("Template Node: ", node.Name) fname := strings.TrimSuffix(node.Name, filepath.Ext(node.Name))