add repeat
This commit is contained in:
parent
f316f35532
commit
6b8889752c
|
@ -1,7 +1,8 @@
|
|||
(ns clj-jtwig.standard-functions
|
||||
"standard function definitions. these are functions that are not yet included in JTwig's standard function
|
||||
library and are just here to fill in the gaps for now."
|
||||
(:import (org.apache.commons.lang3.text WordUtils))
|
||||
(:import (org.apache.commons.lang3.text WordUtils)
|
||||
(org.apache.commons.lang3 StringUtils))
|
||||
(:use [clojure.pprint]))
|
||||
|
||||
; we are using a separate map to hold the standard functions instead of using deftwigfn, etc. because doing it this
|
||||
|
@ -83,6 +84,10 @@
|
|||
{:fn (fn [low high & [step]]
|
||||
(range low high (or step 1)))}
|
||||
|
||||
"repeat"
|
||||
{:fn (fn [s n]
|
||||
(StringUtils/repeat s n))}
|
||||
|
||||
"rest"
|
||||
{:fn (fn [sequence]
|
||||
; matching behaviour of jtwig's first/last implementation
|
||||
|
|
|
@ -330,6 +330,12 @@
|
|||
(is (= (render "{{ range(1, 5, 2) }}" nil)
|
||||
"[1, 3]")))
|
||||
|
||||
(testing "repeat"
|
||||
(is (= (render "{{ repeat('x', 10) }}" nil)
|
||||
"xxxxxxxxxx"))
|
||||
(is (= (render "{{ repeat('x', 0) }}" nil)
|
||||
"")))
|
||||
|
||||
(testing "rest"
|
||||
(is (= (render "{{ [1, 2, 3, 4, 5]|rest }}" nil)
|
||||
"[2, 3, 4, 5]")))
|
||||
|
|
Reference in a new issue