add :tag-symbols option
This commit is contained in:
parent
5a644a92d2
commit
ba78333c28
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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}))
|
||||
: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}))
|
|
@ -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"))))
|
||||
"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))))
|
Reference in a new issue