From a45bb27479b7e41969654e19dbfc50dc63d55c9a Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 23 Mar 2014 11:27:08 -0400 Subject: [PATCH] add center --- src/clj_jtwig/standard_functions.clj | 4 ++++ test/clj_jtwig/functions_test.clj | 8 ++++++++ 2 files changed, 12 insertions(+) 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")))