From abc0d93722fe55ed56246cf856a717cc0329c45d Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 1 Mar 2014 10:32:21 -0500 Subject: [PATCH] add simple render function --- src/clj_jtwig/core.clj | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/clj_jtwig/core.clj b/src/clj_jtwig/core.clj index c57e9ac..228bd91 100644 --- a/src/clj_jtwig/core.clj +++ b/src/clj_jtwig/core.clj @@ -1,6 +1,15 @@ -(ns clj-jtwig.core) +(ns clj-jtwig.core + (:require [clojure.walk :refer [stringify-keys]]) + (:import (com.lyncode.jtwig JtwigTemplate JtwigContext))) -(defn foo - "I don't do a whole lot." - [x] - (println x "Hello, World!")) +(defn render + "renders a template contained in the provided string, using the values in model-map + as the model for the template." + [s model-map & [{:keys [skip-model-map-stringify?] :as options}]] + (let [template (new JtwigTemplate s) + context (new JtwigContext)] + (doseq [[k v] (if-not skip-model-map-stringify? + (stringify-keys model-map) + model-map)] + (.set context k v)) + (.output template context)))