add support for adding custom template tests
This commit is contained in:
parent
bf68239b90
commit
543e1e27c6
|
@ -4,7 +4,7 @@
|
||||||
(com.mitchellbosecke.pebble PebbleEngine)
|
(com.mitchellbosecke.pebble PebbleEngine)
|
||||||
(com.mitchellbosecke.pebble.loader ClasspathLoader FileLoader StringLoader)
|
(com.mitchellbosecke.pebble.loader ClasspathLoader FileLoader StringLoader)
|
||||||
(com.mitchellbosecke.pebble.template PebbleTemplate)
|
(com.mitchellbosecke.pebble.template PebbleTemplate)
|
||||||
(com.mitchellbosecke.pebble.extension Function Filter))
|
(com.mitchellbosecke.pebble.extension Function Filter Test))
|
||||||
(:require [clojure.walk :refer [stringify-keys]]))
|
(:require [clojure.walk :refer [stringify-keys]]))
|
||||||
|
|
||||||
(defonce classpath-loader (ClasspathLoader.))
|
(defonce classpath-loader (ClasspathLoader.))
|
||||||
|
@ -39,6 +39,12 @@
|
||||||
(apply [_ input args]
|
(apply [_ input args]
|
||||||
(apply f (concat [input] (get-sorted-args args))))))
|
(apply f (concat [input] (get-sorted-args args))))))
|
||||||
|
|
||||||
|
(defn make-test [f]
|
||||||
|
(reify Test
|
||||||
|
(getArgumentNames [_] nil)
|
||||||
|
(apply [_ input args]
|
||||||
|
(boolean (apply f (concat [input] (get-sorted-args args)))))))
|
||||||
|
|
||||||
(defmacro defpebblefn [fn-name args & body]
|
(defmacro defpebblefn [fn-name args & body]
|
||||||
`(let [f# (fn ~args ~@body)
|
`(let [f# (fn ~args ~@body)
|
||||||
pebble-fn# (make-function f#)]
|
pebble-fn# (make-function f#)]
|
||||||
|
@ -49,6 +55,11 @@
|
||||||
pebble-fn# (make-filter f#)]
|
pebble-fn# (make-filter f#)]
|
||||||
(.put (.getFilters @engine) ~filter-name pebble-fn#)))
|
(.put (.getFilters @engine) ~filter-name pebble-fn#)))
|
||||||
|
|
||||||
|
(defmacro defpebbletest [test-name args & body]
|
||||||
|
`(let [f# (fn ~args ~@body)
|
||||||
|
pebble-fn# (make-test f#)]
|
||||||
|
(.put (.getTests @engine) ~test-name pebble-fn#)))
|
||||||
|
|
||||||
(defn- prepare-context-map [context]
|
(defn- prepare-context-map [context]
|
||||||
(if context
|
(if context
|
||||||
(stringify-keys context)
|
(stringify-keys context)
|
||||||
|
|
Loading…
Reference in a new issue