mirror of https://github.com/mickael-menu/zk
Add the {{list}} template helper
parent
08e09d94ae
commit
7c2ca2c62e
@ -0,0 +1,29 @@
|
|||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aymerick/raymond"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterList registers a {{list}} template helper which formats a slice of
|
||||||
|
// strings into a bulleted list.
|
||||||
|
func RegisterList() {
|
||||||
|
itemify := func(text string) string {
|
||||||
|
lines := strings.SplitAfter(strings.TrimRight(text, "\n"), "\n")
|
||||||
|
return " ‣ " + strings.Join(lines, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
raymond.RegisterHelper("list", func(items []string) string {
|
||||||
|
res := ""
|
||||||
|
for _, item := range items {
|
||||||
|
if item == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
res += itemify(item) + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue