some minor cleanups
This commit is contained in:
parent
e1a08429bb
commit
97281d6648
|
@ -1,5 +1,5 @@
|
||||||
(defproject clj-jtwig "0.5.1"
|
(defproject clj-jtwig "0.5.1"
|
||||||
:description "Clojure wrapper for JTwig"
|
:description "Clojure wrapper for Jtwig"
|
||||||
:url "https://github.com/gered/clj-jtwig"
|
:url "https://github.com/gered/clj-jtwig"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
:url "http://www.apache.org/licenses/LICENSE-2.0"}
|
:url "http://www.apache.org/licenses/LICENSE-2.0"}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(ns clj-jtwig.core
|
(ns clj-jtwig.core
|
||||||
"wrapper functions for working with JTwig from clojure"
|
"wrapper functions for working with Jtwig from clojure"
|
||||||
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap)
|
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap)
|
||||||
(com.lyncode.jtwig.content.api Renderable)
|
(com.lyncode.jtwig.content.api Renderable)
|
||||||
(com.lyncode.jtwig.configuration JtwigConfiguration)
|
(com.lyncode.jtwig.configuration JtwigConfiguration)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
(ns clj-jtwig.function-utils
|
(ns clj-jtwig.function-utils
|
||||||
|
"utility macros for creating Jtwig function handlers. intended for internal clj-jtwig use only."
|
||||||
(:import (com.lyncode.jtwig.functions.exceptions FunctionException)
|
(:import (com.lyncode.jtwig.functions.exceptions FunctionException)
|
||||||
(com.lyncode.jtwig.functions.annotations JtwigFunction Parameter)
|
(com.lyncode.jtwig.functions.annotations JtwigFunction Parameter)
|
||||||
(clj_jtwig TemplateFunction))
|
(clj_jtwig TemplateFunction))
|
||||||
|
|
|
@ -10,9 +10,10 @@
|
||||||
(:use [clj-jtwig.standard-functions]
|
(:use [clj-jtwig.standard-functions]
|
||||||
[clj-jtwig.web.web-functions]))
|
[clj-jtwig.web.web-functions]))
|
||||||
|
|
||||||
(def object-array-type (Class/forName "[Ljava.lang.Object;"))
|
(def ^:private object-array-type (Class/forName "[Ljava.lang.Object;"))
|
||||||
(def function-parameters (doto (GivenParameters.)
|
|
||||||
(.add (to-array [object-array-type]))))
|
(def ^:private function-parameters (doto (GivenParameters.)
|
||||||
|
(.add (to-array [object-array-type]))))
|
||||||
|
|
||||||
(defn- add-function-library! [repository functions]
|
(defn- add-function-library! [repository functions]
|
||||||
(doseq [fn-obj functions]
|
(doseq [fn-obj functions]
|
||||||
|
@ -33,11 +34,13 @@
|
||||||
[]
|
[]
|
||||||
(reset! functions (create-function-repository)))
|
(reset! functions (create-function-repository)))
|
||||||
|
|
||||||
|
; intended for internal-use only. mainly exists for use in unit tests
|
||||||
(defn get-function [^String name]
|
(defn get-function [^String name]
|
||||||
(try
|
(try
|
||||||
(.get @functions name function-parameters)
|
(.get @functions name function-parameters)
|
||||||
(catch FunctionNotFoundException ex)))
|
(catch FunctionNotFoundException ex)))
|
||||||
|
|
||||||
|
; intended for internal-use only. mainly exists for use in unit tests
|
||||||
(defn function-exists? [^String name]
|
(defn function-exists? [^String name]
|
||||||
(not (nil? (get-function name))))
|
(not (nil? (get-function name))))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(ns clj-jtwig.standard-functions
|
(ns clj-jtwig.standard-functions
|
||||||
"standard function definitions. these are functions that are not yet included in JTwig's standard function
|
"standard function definitions. these are functions that are not yet included in Jtwig's standard function
|
||||||
library and are just here to fill in the gaps for now."
|
library and are just here to fill in the gaps for now."
|
||||||
(:import (org.apache.commons.lang3.text WordUtils)
|
(:import (org.apache.commons.lang3.text WordUtils)
|
||||||
(org.apache.commons.lang3 StringUtils))
|
(org.apache.commons.lang3 StringUtils))
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
[clj-jtwig.core :refer :all]
|
[clj-jtwig.core :refer :all]
|
||||||
[clj-jtwig.functions :refer :all]))
|
[clj-jtwig.functions :refer :all]))
|
||||||
|
|
||||||
; The purpose of these tests is to establish that our wrapper around JTwig works. That is,
|
; The purpose of these tests is to establish that our wrapper around Jtwig works. That is,
|
||||||
; we will be focusing on stuff like making sure that passing Clojure data structures
|
; we will be focusing on stuff like making sure that passing Clojure data structures
|
||||||
; (e.g. maps, vectors, lists) over to JTwig works fine.
|
; (e.g. maps, vectors, lists) over to Jtwig works fine.
|
||||||
; JTwig includes its own test suite which tests actual template parsing and evaluation
|
; Jtwig includes its own test suite which tests actual template parsing and evaluation
|
||||||
; functionality, so there's no point in duplicating that kind of testing here once we
|
; functionality, so there's no point in duplicating that kind of testing here once we
|
||||||
; establish that the above mentioned stuff works fine.
|
; establish that the above mentioned stuff works fine.
|
||||||
;
|
;
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
(set-options! :auto-convert-map-keywords true))))
|
(set-options! :auto-convert-map-keywords true))))
|
||||||
|
|
||||||
(deftest passing-model-map-data
|
(deftest passing-model-map-data
|
||||||
(testing "Passing Clojure data structures to JTwigContext's"
|
(testing "Passing Clojure data structures to JtwigContext's"
|
||||||
(is (= (render "float {{ x }}"
|
(is (= (render "float {{ x }}"
|
||||||
{:x 3.14})
|
{:x 3.14})
|
||||||
"float 3.14")
|
"float 3.14")
|
||||||
|
|
Reference in a new issue