From f2c84ff8e9a0a7d6cf5b7fb63f2a138cccf10dd7 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Thu, 19 Dec 2019 13:00:42 -0500 Subject: feat: make templates overridable compile-time fixes #5 --- http/get.go | 3 +-- http/index.go | 3 +-- http/templates.go | 12 ++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 http/templates.go diff --git a/http/get.go b/http/get.go index 903b5b2..8d3c523 100644 --- a/http/get.go +++ b/http/get.go @@ -3,7 +3,6 @@ package http import ( "github.com/valyala/fasthttp" "toast.cafe/x/brpaste/v2/storage" - "toast.cafe/x/brpaste/v2/template" ) // Get generates a handler for the /:key[/:lang] endpoint @@ -26,7 +25,7 @@ func Get(store storage.CHR) handler { if lang == "raw" { ctx.SuccessString("text/plain", res) } else { - ctx.SuccessString("text/html", template.Code(lang, res)) // render template + ctx.SuccessString("text/html", CodeTemplate(lang, res)) // render template } default: ctx.NotFound() diff --git a/http/index.go b/http/index.go index 792e64a..d9c42f2 100644 --- a/http/index.go +++ b/http/index.go @@ -2,10 +2,9 @@ package http import ( "github.com/valyala/fasthttp" - "toast.cafe/x/brpaste/v2/template" ) // Index handles the / endpoint func Index(ctx *fasthttp.RequestCtx) { - ctx.SuccessString("text/html", template.Index()) // render template + ctx.SuccessString("text/html", IndexTemplate()) // render template } diff --git a/http/templates.go b/http/templates.go new file mode 100644 index 0000000..de5d3dd --- /dev/null +++ b/http/templates.go @@ -0,0 +1,12 @@ +package http + +import "toast.cafe/x/brpaste/v2/template" + +var ( + // CodeTemplate is the function to be used as the template for the code viewer + // overwrite it before calling GenHandler + CodeTemplate = template.Code + // IndexTemplate is the function to be used as the template for the index page + // overwrite it before calling GenHandler + IndexTemplate = template.Index +) -- cgit v1.2.3