From 0e2260421e40c97d9d210724fb44cfdc15ea7855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 1 May 2017 09:06:42 +0200 Subject: tpl: Fix the remaining template funcs namespace issues See #3042 --- tpl/transform/init.go | 21 +++++++++++++++++++++ tpl/transform/transform.go | 5 ----- tpl/transform/transform_test.go | 8 -------- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'tpl/transform') diff --git a/tpl/transform/init.go b/tpl/transform/init.go index 3057cf068..98994c0e6 100644 --- a/tpl/transform/init.go +++ b/tpl/transform/init.go @@ -28,6 +28,27 @@ func init() { {`{{ "I :heart: Hugo" | emojify }}`, `I ❤️ Hugo`}, {`{{ .Title | markdownify}}`, `BatMan`}, {`{{ plainify "Hello world, gophers!" }}`, `Hello world, gophers!`}, + { + `htmlEscape 1: {{ htmlEscape "Cathal Garvey & The Sunshine Band " | safeHTML}}`, + `htmlEscape 1: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`}, + { + `htmlEscape 2: {{ htmlEscape "Cathal Garvey & The Sunshine Band "}}`, + `htmlEscape 2: Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`}, + { + `htmlUnescape 1: {{htmlUnescape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | safeHTML}}`, + `htmlUnescape 1: Cathal Garvey & The Sunshine Band `}, + { + `htmlUnescape 2: {{"Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | htmlUnescape | htmlUnescape | safeHTML}}`, + `htmlUnescape 2: Cathal Garvey & The Sunshine Band `}, + { + `htmlUnescape 3: {{"Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | htmlUnescape | htmlUnescape }}`, + `htmlUnescape 3: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`}, + { + `htmlUnescape 4: {{ htmlEscape "Cathal Garvey & The Sunshine Band " | htmlUnescape | safeHTML }}`, + `htmlUnescape 4: Cathal Garvey & The Sunshine Band `}, + { + `htmlUnescape 5: {{ htmlUnescape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | htmlEscape | safeHTML }}`, + `htmlUnescape 5: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`}, } return &internal.TemplateFuncsNamespace{ diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go index 7e3b81bed..e44abe6cb 100644 --- a/tpl/transform/transform.go +++ b/tpl/transform/transform.go @@ -35,11 +35,6 @@ type Namespace struct { deps *deps.Deps } -// Namespace returns a pointer to the current namespace instance. -func (ns *Namespace) Namespace() *Namespace { - return ns -} - // Emojify returns a copy of s with all emoji codes replaced with actual emojis. // // See http://www.emoji-cheat-sheet.com/ diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go index 528697469..45ed5fc1e 100644 --- a/tpl/transform/transform_test.go +++ b/tpl/transform/transform_test.go @@ -29,14 +29,6 @@ import ( type tstNoStringer struct{} -func TestNamespace(t *testing.T) { - t.Parallel() - - ns := New(newDeps(viper.New())) - - assert.Equal(t, ns, ns.Namespace(), "object pointers should match") -} - func TestEmojify(t *testing.T) { t.Parallel() -- cgit v1.2.3