From b8c938b2eac79301b52661bc037850bfe7b12583 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 23 Mar 2014 10:28:40 -0400 Subject: [PATCH] add capitalize_all --- project.clj | 3 ++- src/clj_jtwig/standard_functions.clj | 5 +++++ test/clj_jtwig/functions_test.clj | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 2fd6b6d..70cbca8 100644 --- a/project.clj +++ b/project.clj @@ -6,4 +6,5 @@ :repositories [["sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" :snapshots false}]] :dependencies [[org.clojure/clojure "1.5.1"] - [com.lyncode/jtwig-core "2.1.2"]]) + [com.lyncode/jtwig-core "2.1.2"] + [org.apache.commons/commons-lang3 "3.1"]]) diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index 1817f99..ea92861 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -1,6 +1,7 @@ (ns clj-jtwig.standard-functions "standard function definitions. these are functions that are not yet included in JTwig's standard function library and are just here to fill in the gaps for now." + (:import (org.apache.commons.lang3.text WordUtils)) (:use [clojure.pprint])) ; we are using a separate map to hold the standard functions instead of using deftwigfn, etc. because doing it this @@ -23,6 +24,10 @@ (-> sequence vals butlast) (butlast sequence)))} + "capitalize_all" + {:fn (fn [s] + (WordUtils/capitalize s))} + "dump" {:fn (fn [x] (with-out-str diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index c6a7408..ec1406e 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -284,6 +284,10 @@ (is (= (render "{{ [1, 2, 3, 4, 5]|butlast }}" nil) "[1, 2, 3, 4]"))) + (testing "capitalize_all" + (is (= (render "{{ capitalize_all('hello world') }}" nil) + "Hello World"))) + (testing "dump" (is (= (render "{{ a|dump }}" {:a [{:foo "bar"} [1, 2, 3] "hello"]}) "({\"foo\" \"bar\"} (1 2 3) \"hello\")\n")))