summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/templates/templates.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-06-18 15:17:48 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-06-18 15:17:48 -0600
commit2663dd176d38dfb929bcc478cac3913827f1246e (patch)
tree2b5da588e9ae5eb2e0e13d223aeda7c0922eed35 /modules/caddyhttp/templates/templates.go
parent6706c9225a8dcb976785bdf2c35eb151d54ac18c (diff)
Refactor templates execution; add sprig functions
Diffstat (limited to 'modules/caddyhttp/templates/templates.go')
-rw-r--r--modules/caddyhttp/templates/templates.go17
1 files changed, 3 insertions, 14 deletions
diff --git a/modules/caddyhttp/templates/templates.go b/modules/caddyhttp/templates/templates.go
index 56c3b66..a0fb87f 100644
--- a/modules/caddyhttp/templates/templates.go
+++ b/modules/caddyhttp/templates/templates.go
@@ -6,7 +6,6 @@ import (
"io"
"net/http"
"strconv"
- "text/template"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy/modules/caddyhttp"
@@ -67,29 +66,19 @@ func (t *Templates) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
// executeTemplate executes the template contianed
// in wb.buf and replaces it with the results.
func (t *Templates) executeTemplate(wb *responseBuffer, r *http.Request) error {
- tpl := template.New(r.URL.Path)
-
- if len(t.Delimiters) == 2 {
- tpl.Delims(t.Delimiters[0], t.Delimiters[1])
- }
-
- parsedTpl, err := tpl.Parse(wb.buf.String())
- if err != nil {
- return caddyhttp.Error(http.StatusInternalServerError, err)
- }
-
var fs http.FileSystem
if t.FileRoot != "" {
fs = http.Dir(t.FileRoot)
}
+
ctx := &templateContext{
Root: fs,
Req: r,
RespHeader: tplWrappedHeader{wb.Header()},
+ config: t,
}
- wb.buf.Reset() // reuse buffer for output
- err = parsedTpl.Execute(wb.buf, ctx)
+ err := ctx.executeTemplateInBuffer(r.URL.Path, wb.buf)
if err != nil {
return caddyhttp.Error(http.StatusInternalServerError, err)
}