From 1845873048e1f2c3499e75a4e5cbbe8d1247170d Mon Sep 17 00:00:00 2001 From: RenĂ© 'Necoro' Neumann Date: Tue, 21 Apr 2020 18:48:06 +0200 Subject: Move HTML template to string --- internal/template/feed.tpl.go | 72 +++++++++++++++++++++++++++++++++++++++++++ internal/template/template.go | 6 ++-- 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 internal/template/feed.tpl.go (limited to 'internal/template') diff --git a/internal/template/feed.tpl.go b/internal/template/feed.tpl.go new file mode 100644 index 0000000..f6862d5 --- /dev/null +++ b/internal/template/feed.tpl.go @@ -0,0 +1,72 @@ +package template + +var Feed = fromString("Feed", feedTpl) + +//noinspection HtmlDeprecatedAttribute,HtmlUnknownTarget +const feedTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{define "bottomLine"}} + {{if .content}} + + + {{.descr}}   + + + {{.content}} + + + {{end}} +{{end}} + + + + +
+ + + + + + + + + +
Feed + {{with .Feed.Link}}{{end}} + {{or .Feed.Title .Feed.Link "Unnammed feed"}} + {{if .Feed.Link}}{{end}} +
Item + {{with .Item.Link}}{{end}} + {{or .Item.Title .Item.Link}} + {{if .Item.Link}}{{end}} +
+
+{{with .Item.Content}} +
+ {{.}} +{{end}} +{{with .Item.Enclosures}} + + + + +
+ + + {{range .}} + + + + {{end}} +
Files:
+     + {{.URL | lastUrlPart}} ({{.Length | byteCount}}, {{.Type}}) +
+
+{{end}} +
+ + {{template "bottomLine" (dict "descr" "Date:" "content" .Item.Published)}} + {{template "bottomLine" (dict "descr" "Author:" "content" .Item.Author.Name)}} + {{template "bottomLine" (dict "descr" "Subject:" "content" .Item.Title)}} + {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Item.Categories))}} +
` diff --git a/internal/template/template.go b/internal/template/template.go index e31ece2..350a0ed 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -3,7 +3,6 @@ package template import ( "fmt" "html/template" - "path/filepath" "strings" ) @@ -50,8 +49,7 @@ var funcMap = template.FuncMap{ "byteCount": byteCount, } -func ForFile(filename string) *template.Template { - name := filepath.Base(filename) +func fromString(name, templateStr string) *template.Template { tpl := template.New(name).Funcs(funcMap) - return template.Must(tpl.ParseFiles(filename)) + return template.Must(tpl.Parse(templateStr)) } -- cgit v1.2.3-70-g09d2