-
Notifications
You must be signed in to change notification settings - Fork 10
/
freemarker.clj
30 lines (24 loc) · 958 Bytes
/
freemarker.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns leiningen.polylith.freemarker
(:require [leiningen.polylith.file :as file]
[leiningen.polylith.cmd.shared :as shared])
(:import (freemarker.template TemplateNotFoundException)
(freemarker.cache ClassTemplateLoader)))
(defn ->column [[k v]]
[(name k) v])
(defn ->entity [entity]
(into {} (map ->column entity)))
(defn ->row [row]
(map ->entity row))
(defn ->map [m]
(map ->row m))
(defn configuration []
(doto (freemarker.template.Configuration.)
(.setClassForTemplateLoading (.getClass (ClassTemplateLoader.)) "/templates")))
(defn write-file [config templates-root-dir template-file out-file-path table]
(try
(let [template (.getTemplate config template-file)
out (file/writer out-file-path)]
(.process template table out)
[true])
(catch TemplateNotFoundException _
[false (str "Could not find template '" template-file "' in directory '" templates-root-dir "'.")])))