diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index cc084d4..062fcab 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -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 diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index 4ba3573..3241a0b 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -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]")))