From f316f3553286bf98f974c3229aaba6ecaff2843e Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 23 Mar 2014 11:11:00 -0400 Subject: [PATCH] add wrap --- src/clj_jtwig/standard_functions.clj | 12 +++++++++++- test/clj_jtwig/functions_test.clj | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index ea92861..cc084d4 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -113,4 +113,14 @@ "sort_descending_by" {:fn (fn [coll k] (sort-by #(get % k) #(compare %2 %1) coll)) - :aliases ["sort_desc_by"]}}) + :aliases ["sort_desc_by"]} + + "wrap" + {:fn (fn [s length & [wrap-long-words? new-line-string]] + (WordUtils/wrap + s + length + new-line-string + (if (nil? wrap-long-words?) + false + wrap-long-words?)))}}) diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index ec1406e..4ba3573 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -352,4 +352,14 @@ (testing "sort_descending_by" (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_descending_by(\"a\") }}" nil) - "[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]")))) + "[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]"))) + + (testing "wrap" + (is (= (render "{{ wrap(\"Here is one line of text that is going to be wrapped after 20 columns.\", 20) }}" nil) + "Here is one line of\ntext that is going\nto be wrapped after\n20 columns.")) + (is (= (render "{{ wrap(\"Here is one line of text that is going to be wrapped after 20 columns.\", 20, false, \"
\") }}" nil) + "Here is one line of
text that is going
to be wrapped after
20 columns.")) + (is (= (render "{{ wrap(\"Click here to jump to the commons website - http://commons.apache.org\", 20, false) }}" nil) + "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org")) + (is (= (render "{{ wrap(\"Click here to jump to the commons website - http://commons.apache.org\", 20, true) }}" nil) + "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apach\ne.org"))))