From 756d3851547a4cf45000d3597e716ede7b92296e Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Wed, 17 Feb 2021 21:00:28 +0000 Subject: [PATCH] Extract templates to separate files This allows our users to easily copy the base templates should they wish to make changes to them --- pkg/app/pagewriter/error.html | 100 ++++++++++++++++ pkg/app/pagewriter/sign_in.html | 89 ++++++++++++++ pkg/app/pagewriter/templates.go | 200 ++------------------------------ 3 files changed, 198 insertions(+), 191 deletions(-) create mode 100644 pkg/app/pagewriter/error.html create mode 100644 pkg/app/pagewriter/sign_in.html diff --git a/pkg/app/pagewriter/error.html b/pkg/app/pagewriter/error.html new file mode 100644 index 00000000..56306227 --- /dev/null +++ b/pkg/app/pagewriter/error.html @@ -0,0 +1,100 @@ +{{define "error.html"}} + + + + + + {{.StatusCode}} {{.Title}} + + + + + + + + +
+
+
{{.StatusCode}}
+
+

{{.Title}}

+
+ + {{ if .Message }} +
+
+

More Info

+ + + +
+ +
+ {{ end }} + + {{ if .Redirect }} +
+ +
+
+
+ +
+
+
+
+ + +
+
+
+ {{ end }} + +
+
+ + + + + +{{end}} diff --git a/pkg/app/pagewriter/sign_in.html b/pkg/app/pagewriter/sign_in.html new file mode 100644 index 00000000..e148c2b5 --- /dev/null +++ b/pkg/app/pagewriter/sign_in.html @@ -0,0 +1,89 @@ +{{define "sign_in.html"}} + + + + + + Sign In + + + + + + + +
+ +
+ + + + + +{{end}} diff --git a/pkg/app/pagewriter/templates.go b/pkg/app/pagewriter/templates.go index fbc107f7..66d24ecc 100644 --- a/pkg/app/pagewriter/templates.go +++ b/pkg/app/pagewriter/templates.go @@ -1,6 +1,9 @@ package pagewriter import ( + // Import embed to allow importing default page templates + _ "embed" + "fmt" "html/template" "os" @@ -13,199 +16,14 @@ import ( const ( errorTemplateName = "error.html" signInTemplateName = "sign_in.html" - - defaultErrorTemplate = `{{define "error.html"}} - - - - - - {{.StatusCode}} {{.Title}} - - - - - - - - -
-
-
{{.StatusCode}}
-
-

{{.Title}}

-
- - {{ if .Message }} -
-
-

More Info

- - - -
- -
- {{ end }} - - {{ if .Redirect }} -
- -
-
-
- -
-
-
-
- - -
-
-
- {{ end }} - -
-
- - - - - -{{end}}` - - defaultSignInTemplate = `{{define "sign_in.html"}} - - - - - - Sign In - - - - - - - -
- -
- - - - - -{{end}}` ) +//go:embed error.html +var defaultErrorTemplate string + +//go:embed sign_in.html +var defaultSignInTemplate string + // loadTemplates adds the Sign In and Error templates from the custom template // directory, or uses the defaults if they do not exist or the custom directory // is not provided.