From 9ec7bfaffdae66e8f9ec25c16752e424ff5b1591 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 14 Jun 2014 23:43:48 -0400 Subject: [PATCH] casting functions --- src/clj_jtwig/standard_functions.clj | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index 1e1a958..bacfe2e 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -164,6 +164,34 @@ (sort-by #(get % sort-key) #(compare %2 %1) coll))) :aliases ["sort_desc_by"]} + "to_double" + {:fn (fn [x] + (Double/parseDouble x))} + + "to_float" + {:fn (fn [x] + (Float/parseFloat x))} + + "to_int" + {:fn (fn [x] + (Integer/parseInt x))} + + "to_keyword" + {:fn (fn [x] + (keyword x))} + + "to_long" + {:fn (fn [x] + (Long/parseLong x))} + + "to_string" + {:fn (fn [x] + (cond + (keyword? x) (name x) + (instance? clojure.lang.LazySeq x) (str (seq x)) + (coll? x) (str x) + :else (.toString x)))} + "wrap" {:fn (fn [s length & [wrap-long-words? new-line-string]] (WordUtils/wrap