From ba78333c28f910be4e5c07ba9fb2921fb1d5317f Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 2 Jul 2014 17:05:52 -0400 Subject: [PATCH] add :tag-symbols option --- src/clojure/clj_jtwig/core.clj | 10 +++++++++- src/clojure/clj_jtwig/options.clj | 8 +++++++- test/clj_jtwig/core_test.clj | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/clojure/clj_jtwig/core.clj b/src/clojure/clj_jtwig/core.clj index cfc3870..0e0bd7c 100644 --- a/src/clojure/clj_jtwig/core.clj +++ b/src/clojure/clj_jtwig/core.clj @@ -3,6 +3,7 @@ (:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap) (com.lyncode.jtwig.content.api Renderable) (com.lyncode.jtwig.configuration JtwigConfiguration) + (com.lyncode.jtwig.parser.config TagSymbols) (com.lyncode.jtwig.render RenderContext) (com.lyncode.jtwig.render.config RenderConfiguration) (com.lyncode.jtwig.resource ClasspathJtwigResource StringJtwigResource FileJtwigResource) @@ -31,7 +32,14 @@ (flush-template-cache!) (= k :strict-mode) - (-> configuration .render (.strictMode v))) + (-> configuration .render (.strictMode v)) + + (= k :tag-symbols) + (-> configuration + .parse + (.withSymbols (condp = v + :default TagSymbols/DEFAULT + :js TagSymbols/JAVASCRIPT)))) (swap! options assoc k v))) diff --git a/src/clojure/clj_jtwig/options.clj b/src/clojure/clj_jtwig/options.clj index 49a9cfb..8c1c141 100644 --- a/src/clojure/clj_jtwig/options.clj +++ b/src/clojure/clj_jtwig/options.clj @@ -44,4 +44,10 @@ :web-resource-path-root "public" ; when enabled, exceptions will be thrown when attempting to use variables that do not exist - :strict-mode false})) \ No newline at end of file + :strict-mode false + + ; allows for changing the tag symbols used from normal Twig-style to a style more friendly + ; with certain Javascript template engines (e.g. Angular). + ; :default => tag: {% %}, output: {{ }}, comment: {# #} + ; :js => tag: <# #>, output: <@ @>, comment: <$ $> + :tag-symbols :default})) \ No newline at end of file diff --git a/test/clj_jtwig/core_test.clj b/test/clj_jtwig/core_test.clj index ad6f0d6..4fe2f3b 100644 --- a/test/clj_jtwig/core_test.clj +++ b/test/clj_jtwig/core_test.clj @@ -156,4 +156,17 @@ "trying to output a non-existant variable under non-strict-mode") (is (= (render "{{ foo }}" {:foo "bar"}) "bar") - "trying to output an existing variable under non-strict-mode")))) \ No newline at end of file + "trying to output an existing variable under non-strict-mode")) + (do + (set-options! :tag-symbols :js) + (is (= (render "@> 1 <@" {:foo "bar"}) + "1") + "js-style output symbols") + (is (= (render "<# if (foo) #>bar<# endif #>" {:foo true}) + "bar") + "js-style tag symbols") + (is (= (render "<$ this is a comment $>") + "") + "js-style comment symbols") + + (set-options! :tag-symbols :default)))) \ No newline at end of file