diff --git a/pkg/renderer/html5/_macros/hello b/pkg/renderer/html5/_macros/hello
deleted file mode 100644
index dd00a076..00000000
--- a/pkg/renderer/html5/_macros/hello
+++ /dev/null
@@ -1,13 +0,0 @@
-{{- if eq .Kind "block" -}}
-
-
-{{end -}}
-
-{{- if .Attributes.Has "prefix"}}{{escape (.Attributes.GetAsString "prefix")}} {{else}}hello {{end -}}
-{{- if ne .Value ""}}{{escape .Value}}{{else}}world{{- end -}}
-{{- escape (.Attributes.GetAsString "suffix") -}}
-
-{{- if eq .Kind "block"}}
-
-
-{{- end -}}
diff --git a/pkg/renderer/html5/user_macro_test.go b/pkg/renderer/html5/user_macro_test.go
index f11fc3f0..4544a97a 100644
--- a/pkg/renderer/html5/user_macro_test.go
+++ b/pkg/renderer/html5/user_macro_test.go
@@ -8,26 +8,12 @@ import (
. "github.com/onsi/ginkgo"
)
-// an example for find and define user macro
-func findMacroTemplate() []renderer.Option {
- t := texttemplate.New("user macro")
- t.Funcs(texttemplate.FuncMap{
- "escape": html.EscapeString,
- })
- tmpl := texttemplate.Must(t.ParseGlob("_macros/*"))
- tmpls := tmpl.Templates()
- opts := make([]renderer.Option, len(tmpls))
- for i, tt := range tmpls {
- opts[i] = renderer.DefineMacro(tt.Name(), tt)
- }
- return opts
-}
+var macroOption renderer.Option
+var helloMacroTmpl *texttemplate.Template
var _ = Describe("user macros", func() {
Context("user macros", func() {
- opts := findMacroTemplate()
-
It("undefined macro block", func() {
actualContent := "hello::[]"
@@ -45,7 +31,7 @@ var _ = Describe("user macros", func() {
hello world
`
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("user macro block with attribute", func() {
@@ -56,7 +42,7 @@ var _ = Describe("user macros", func() {
hello world!!!!
`
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("user macro block with value", func() {
@@ -67,7 +53,7 @@ var _ = Describe("user macros", func() {
hello John Doe
`
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("user macro block with value and attributes", func() {
@@ -78,7 +64,7 @@ var _ = Describe("user macros", func() {
Hi John Doe!!
`
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("undefined inline macro", func() {
@@ -96,7 +82,7 @@ var _ = Describe("user macros", func() {
expectedResult := ``
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("inline macro with attribute", func() {
@@ -105,7 +91,7 @@ var _ = Describe("user macros", func() {
expectedResult := ``
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("inline macro with value", func() {
@@ -114,7 +100,7 @@ var _ = Describe("user macros", func() {
expectedResult := ``
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
It("inline macro with value and attributes", func() {
@@ -123,8 +109,28 @@ var _ = Describe("user macros", func() {
expectedResult := ``
- verify(GinkgoT(), expectedResult, actualContent, opts...)
+ verify(GinkgoT(), expectedResult, actualContent, renderer.DefineMacro(helloMacroTmpl.Name(), helloMacroTmpl))
})
})
})
+
+func init() {
+ t := texttemplate.New("hello")
+ t.Funcs(texttemplate.FuncMap{
+ "escape": html.EscapeString,
+ })
+ helloMacroTmpl = texttemplate.Must(t.Parse(`{{- if eq .Kind "block" -}}
+
+
+{{end -}}
+
+{{- if .Attributes.Has "prefix"}}{{escape (.Attributes.GetAsString "prefix")}} {{else}}hello {{end -}}
+{{- if ne .Value ""}}{{escape .Value}}{{else}}world{{- end -}}
+{{- escape (.Attributes.GetAsString "suffix") -}}
+
+{{- if eq .Kind "block"}}
+
+
+{{- end -}}`))
+}