From b41368462c89dbfc5230350c46629266f03ad9d5 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 16 Feb 2021 19:24:33 +0100 Subject: Use go-embed for templates instead of inline strings. They should also use CRLF (cf issue #46). --- internal/feed/template/html.tpl | 58 +++++++++++++++++++++++++++++++++++ internal/feed/template/html.tpl.go | 63 -------------------------------------- internal/feed/template/template.go | 9 ++++++ internal/feed/template/text.tpl | 37 ++++++++++++++++++++++ internal/feed/template/text.tpl.go | 42 ------------------------- 5 files changed, 104 insertions(+), 105 deletions(-) create mode 100644 internal/feed/template/html.tpl delete mode 100644 internal/feed/template/html.tpl.go create mode 100644 internal/feed/template/text.tpl delete mode 100644 internal/feed/template/text.tpl.go (limited to 'internal/feed') diff --git a/internal/feed/template/html.tpl b/internal/feed/template/html.tpl new file mode 100644 index 0000000..b320ebb --- /dev/null +++ b/internal/feed/template/html.tpl @@ -0,0 +1,58 @@ +{{- /*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 .Body}} + {{html .}} +{{end}} +{{with .Item.Enclosures}} + + + + + {{range .}} + + + + {{end}} +
Files:
+     + {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +
+{{end}} +
+ + {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} + {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} + {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} + {{with .FeedLink}} + {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} + {{end}} +
\ No newline at end of file diff --git a/internal/feed/template/html.tpl.go b/internal/feed/template/html.tpl.go deleted file mode 100644 index be84030..0000000 --- a/internal/feed/template/html.tpl.go +++ /dev/null @@ -1,63 +0,0 @@ -package template - -var Html = fromString("Feed", htmlTpl, true) - -//noinspection HtmlDeprecatedAttribute,HtmlUnknownTarget -const htmlTpl = `{{- /*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 .Body}} - {{html .}} -{{end}} -{{with .Item.Enclosures}} - - - - - {{range .}} - - - - {{end}} -
Files:
-     - {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -
-{{end}} -
- - {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} - {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} - {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} - {{with .FeedLink}} - {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} - {{end}} -
` diff --git a/internal/feed/template/template.go b/internal/feed/template/template.go index d8eb850..09dacf1 100644 --- a/internal/feed/template/template.go +++ b/internal/feed/template/template.go @@ -15,6 +15,15 @@ type Template interface { Execute(wr io.Writer, data interface{}) error } +//go:embed html.tpl +var htmlTpl string + +//go:embed text.tpl +var textTpl string + +var Html = fromString("Feed", htmlTpl, true) +var Text = fromString("Feed", textTpl, false) + func must(t Template, err error) Template { if err != nil { panic(err) diff --git a/internal/feed/template/text.tpl b/internal/feed/template/text.tpl new file mode 100644 index 0000000..57eef18 --- /dev/null +++ b/internal/feed/template/text.tpl @@ -0,0 +1,37 @@ +{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{- with .Item.Link -}} +<{{.}}> + +{{ end -}} +{{- with .TextBody -}} +{{.}} +{{ end -}} +{{- with .Item.Enclosures}} +Files: +{{- range . }} + {{ .URL}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +{{- end -}} +{{- end}} +-- +Feed: {{ with .Feed.Title -}}{{.}}{{- end }} +{{ with .Feed.Link -}} + <{{.}}> +{{end -}} +Item: {{ with .Item.Title -}} + {{.}} +{{- end }} +{{ with .Item.Link -}} + <{{.}}> +{{end -}} +{{ with .Date -}} + Date: {{.}} +{{ end -}} +{{ with .Creator -}} + Author: {{.}} +{{ end -}} +{{ with (join ", " .Categories) -}} + Filed under: {{.}} +{{ end -}} +{{ with .FeedLink -}} + Feed-Link: {{.}} +{{ end -}} \ No newline at end of file diff --git a/internal/feed/template/text.tpl.go b/internal/feed/template/text.tpl.go deleted file mode 100644 index 19aa9b2..0000000 --- a/internal/feed/template/text.tpl.go +++ /dev/null @@ -1,42 +0,0 @@ -package template - -var Text = fromString("Feed", textTpl, false) - -//noinspection HtmlDeprecatedAttribute,HtmlUnknownTarget -const textTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} -{{- with .Item.Link -}} -<{{.}}> - -{{ end -}} -{{- with .TextBody -}} -{{.}} -{{ end -}} -{{- with .Item.Enclosures}} -Files: -{{- range . }} - {{ .URL}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -{{- end -}} -{{- end}} --- -Feed: {{ with .Feed.Title -}}{{.}}{{- end }} -{{ with .Feed.Link -}} - <{{.}}> -{{end -}} -Item: {{ with .Item.Title -}} - {{.}} -{{- end }} -{{ with .Item.Link -}} - <{{.}}> -{{end -}} -{{ with .Date -}} - Date: {{.}} -{{ end -}} -{{ with .Creator -}} - Author: {{.}} -{{ end -}} -{{ with (join ", " .Categories) -}} - Filed under: {{.}} -{{ end -}} -{{ with .FeedLink -}} - Feed-Link: {{.}} -{{ end -}}` -- cgit v1.2.3-70-g09d2 From 44d52ca74fabfecc3b47a31ccdcbdded5300170f Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 16 Feb 2021 19:35:14 +0100 Subject: Fix CRLF ending --- internal/feed/template/html.tpl | 114 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'internal/feed') diff --git a/internal/feed/template/html.tpl b/internal/feed/template/html.tpl index b320ebb..aa7d341 100644 --- a/internal/feed/template/html.tpl +++ b/internal/feed/template/html.tpl @@ -1,58 +1,58 @@ -{{- /*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 .Body}} - {{html .}} -{{end}} -{{with .Item.Enclosures}} - - - - - {{range .}} - - - - {{end}} -
Files:
-     - {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -
-{{end}} -
- - {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} - {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} - {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} - {{with .FeedLink}} - {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} - {{end}} +{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{define "bottomLine"}} + {{if .content}} + + + + + {{end}} +{{end}} +
+ {{.descr}}   + + {{.content}} +
+ + + + + + + + +
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 .Body}} + {{html .}} +{{end}} +{{with .Item.Enclosures}} + + + + + {{range .}} + + + + {{end}} +
Files:
+     + {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +
+{{end}} +
+ + {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} + {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} + {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} + {{with .FeedLink}} + {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} + {{end}}
\ No newline at end of file -- cgit v1.2.3-70-g09d2 From 2df7f561b6a4977051499731740aae2138c9d001 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 18 Feb 2021 09:47:23 +0100 Subject: Import 'embed' package --- internal/feed/template/template.go | 1 + 1 file changed, 1 insertion(+) (limited to 'internal/feed') diff --git a/internal/feed/template/template.go b/internal/feed/template/template.go index 09dacf1..9804190 100644 --- a/internal/feed/template/template.go +++ b/internal/feed/template/template.go @@ -1,6 +1,7 @@ package template import ( + _ "embed" "fmt" html "html/template" "io" -- cgit v1.2.3-70-g09d2