replace all the individual option toggle functions with set-options!
This commit is contained in:
parent
841b15e11d
commit
da0097a100
|
@ -12,37 +12,18 @@
|
||||||
|
|
||||||
(declare flush-template-cache!)
|
(declare flush-template-cache!)
|
||||||
|
|
||||||
(defn toggle-compiled-template-caching!
|
(defn set-options!
|
||||||
"toggle caching of compiled templates on/off. if off, every time a template is rendered from a file
|
"sets global options. can specify values for all options or just the ones you care about. changing some
|
||||||
it will be re-loaded from disk and re-compiled before being rendered. caching is turned on by default."
|
options via this function can trigger various important 'house-keeping' operations, so you should
|
||||||
[enable?]
|
always use this function rather then manually updating clj-jtwig.options/options.
|
||||||
; always clear the cache when toggling. this will help ensure that any possiblity of weird behaviour from
|
see clj-jtwig.options for the option keys you can specify here."
|
||||||
; leftover stuff being stuck in the cache pre-toggle-on/off won't happen
|
[& opts]
|
||||||
(flush-template-cache!)
|
(doseq [[k v] (apply hash-map opts)]
|
||||||
(swap! options assoc :cache-compiled-templates enable?))
|
(if (= :cache-compiled-templates k)
|
||||||
|
; always clear the cache when toggling. this will help ensure that any possiblity of weird behaviour from
|
||||||
(defn toggle-file-status-check-skipping!
|
; leftover stuff being stuck in the cache pre-toggle-on/off won't happen
|
||||||
"toggle file status checks on/off. if enabled, after a template is compiled and cached then the source file
|
(flush-template-cache!))
|
||||||
on disk is not rechecked for modifications, skipping any file I/O that would otherwise occur. the default
|
(swap! options assoc k v)))
|
||||||
for this option is false, meaning that normal file status checks will always be performed. this is probably
|
|
||||||
what you want unless performance is critical and you know your template files will not be modified while
|
|
||||||
the application is running."
|
|
||||||
[enable?]
|
|
||||||
(swap! options assoc :skip-file-status-checks enable?))
|
|
||||||
|
|
||||||
(defn toggle-check-for-minified-web-resources!
|
|
||||||
"toggle a check for minified equivalents of css/js files when using the web functions 'stylesheet' and
|
|
||||||
'javascript'. when this is enabled, if a '.min.js' or '.min.css' equivalent file exists for the url
|
|
||||||
passed to these two functions, then it will be used instead of the original file specified."
|
|
||||||
[enable?]
|
|
||||||
(swap! options assoc :check-for-minified-web-resources enable?))
|
|
||||||
|
|
||||||
(defn toggle-auto-stringify-keys!
|
|
||||||
[enable?]
|
|
||||||
"toggle whether model-maps passed to the render functions will have their keys recursively converted
|
|
||||||
from keywords to strings. Jtwig requires that all the keys in model maps are strings. this is turned
|
|
||||||
off by default."
|
|
||||||
(swap! options assoc :stringify-keys enable?))
|
|
||||||
|
|
||||||
; cache of compiled templates. key is the file path. value is a map with :last-modified which is the source file's
|
; cache of compiled templates. key is the file path. value is a map with :last-modified which is the source file's
|
||||||
; last modification timestamp and :template which is a com.lyncode.jtwig.tree.api.Content object which has been
|
; last modification timestamp and :template which is a com.lyncode.jtwig.tree.api.Content object which has been
|
||||||
|
|
Reference in a new issue