From ceed7a25a0bb6a08b5068dd236aad909c231c3cf Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 14 Jun 2014 22:56:54 -0400 Subject: [PATCH] update 'contains' to allow checking for a substring in a string --- src/clj_jtwig/standard_functions.clj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index 1ba15d2..1e1a958 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -38,10 +38,12 @@ "contains" {:fn (fn [coll value] - (if (map? coll) - (contains? coll (possible-keyword-string value)) + (cond + (map? coll) (contains? coll (possible-keyword-string value)) + (string? coll) (.contains coll value) ; explicit use of '=' to allow testing for falsey values - (some #(= value %) coll)))} + (coll? coll) (not (nil? (some #(= value %) coll))) + :else (throw (new Exception (str "'contains' passed invalid collection type: " (type coll))))))} "dump" {:fn (fn [x]