include web-functions in the standard set of repository functions
This commit is contained in:
parent
32a03b3507
commit
57bb442808
|
@ -4,7 +4,8 @@
|
||||||
(com.lyncode.jtwig.functions.repository DefaultFunctionRepository)
|
(com.lyncode.jtwig.functions.repository DefaultFunctionRepository)
|
||||||
(com.lyncode.jtwig.functions.exceptions FunctionNotFoundException FunctionException))
|
(com.lyncode.jtwig.functions.exceptions FunctionNotFoundException FunctionException))
|
||||||
(:require [clj-jtwig.convert :refer [java->clojure clojure->java]])
|
(:require [clj-jtwig.convert :refer [java->clojure clojure->java]])
|
||||||
(:use [clj-jtwig.standard-functions]))
|
(:use [clj-jtwig.standard-functions]
|
||||||
|
[clj-jtwig.web.web-functions]))
|
||||||
|
|
||||||
(defn- make-function-handler [f]
|
(defn- make-function-handler [f]
|
||||||
(reify JtwigFunction
|
(reify JtwigFunction
|
||||||
|
@ -21,15 +22,18 @@
|
||||||
(aset array index (nth aliases index)))
|
(aset array index (nth aliases index)))
|
||||||
array))
|
array))
|
||||||
|
|
||||||
|
(defn- add-function-library! [repository functions]
|
||||||
|
(doseq [[name {:keys [aliases fn]}] functions]
|
||||||
|
(.add repository
|
||||||
|
(make-function-handler fn)
|
||||||
|
name
|
||||||
|
(make-aliased-array aliases)))
|
||||||
|
repository)
|
||||||
|
|
||||||
(defn- create-function-repository []
|
(defn- create-function-repository []
|
||||||
(let [repository (new DefaultFunctionRepository (make-array JtwigFunction 0))]
|
(doto (new DefaultFunctionRepository (make-array JtwigFunction 0))
|
||||||
; always add our standard functions to new repository objects
|
(add-function-library! standard-functions)
|
||||||
(doseq [[name {:keys [aliases fn]}] standard-functions]
|
(add-function-library! web-functions)))
|
||||||
(.add repository
|
|
||||||
(make-function-handler fn)
|
|
||||||
name
|
|
||||||
(make-aliased-array aliases)))
|
|
||||||
repository))
|
|
||||||
|
|
||||||
; we'll be reusing the same function repository object for all contexts created when rendering templates.
|
; we'll be reusing the same function repository object for all contexts created when rendering templates.
|
||||||
; any custom functions added will be added to this instance
|
; any custom functions added will be added to this instance
|
||||||
|
|
Reference in a new issue