diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index bce8534..4301477 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -29,6 +29,10 @@ {:fn (fn [s] (WordUtils/capitalize s))} + "center" + {:fn (fn [s size & [padding-string]] + (StringUtils/center s size (or padding-string " ")))} + "dump" {:fn (fn [x] (with-out-str diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index 7091303..8295128 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -288,6 +288,14 @@ (is (= (render "{{ capitalize_all('hello world') }}" nil) "Hello World"))) + (testing "center" + (is (= (render "{{ center('bat', 5) }}" nil) + " bat ")) + (is (= (render "{{ center('bat', 3) }}" nil) + "bat")) + (is (= (render "{{ center('bat', 5, 'x') }}" nil) + "xbatx"))) + (testing "dump" (is (= (render "{{ a|dump }}" {:a [{:foo "bar"} [1, 2, 3] "hello"]}) "({\"foo\" \"bar\"} (1 2 3) \"hello\")\n")))