diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index b894542..bce8534 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -64,6 +64,10 @@ {:fn (fn [s size & [padding-string]] (StringUtils/leftPad s size (or padding-string " ")))} + "pad_right" + {:fn (fn [s size & [padding-string]] + (StringUtils/rightPad s size (or padding-string " ")))} + "random" {:fn (fn [& values] (let [first-value (first values)] diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index f2b9587..7091303 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -326,6 +326,14 @@ (is (= (render "{{ pad_left('bat', 5, 'x') }}" nil) "xxbat"))) + (testing "pad_right" + (is (= (render "{{ pad_right('bat', 5) }}" nil) + "bat ")) + (is (= (render "{{ pad_right('bat', 3) }}" nil) + "bat")) + (is (= (render "{{ pad_right('bat', 5, 'x') }}" nil) + "batxx"))) + (testing "random" (is (some #{(render "{{ ['apple', 'orange', 'citrus']|random }}" nil)} ["apple" "orange" "citrus"]))