From a84ea1c7ec566205235a5cd597830b386f651fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 3 Mar 2016 20:15:55 +0100 Subject: [PATCH] Add support for the other html template types --- cast_test.go | 3 +++ caste.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/cast_test.go b/cast_test.go index e08887b..cfd3289 100644 --- a/cast_test.go +++ b/cast_test.go @@ -38,6 +38,9 @@ func TestToString(t *testing.T) { assert.Equal(t, ToString([]byte("one time")), "one time") assert.Equal(t, ToString(template.HTML("one time")), "one time") assert.Equal(t, ToString(template.URL("http://somehost.foo")), "http://somehost.foo") + assert.Equal(t, ToString(template.JS("(1+2)")), "(1+2)") + assert.Equal(t, ToString(template.CSS("a")), "a") + assert.Equal(t, ToString(template.HTMLAttr("a")), "a") assert.Equal(t, ToString(foo), "one more time") assert.Equal(t, ToString(nil), "") assert.Equal(t, ToString(true), "true") diff --git a/caste.go b/caste.go index 3ac4cb7..8f0993f 100644 --- a/caste.go +++ b/caste.go @@ -206,6 +206,12 @@ func ToStringE(i interface{}) (string, error) { return string(s), nil case template.URL: return string(s), nil + case template.JS: + return string(s), nil + case template.CSS: + return string(s), nil + case template.HTMLAttr: + return string(s), nil case nil: return "", nil case fmt.Stringer: