-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.clj
32 lines (28 loc) · 993 Bytes
/
plugin.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
31
32
(ns lein-interpolate.plugin
(:require
[clojure.walk :as walk]))
(defn interpolate-tokens [project]
(let [interpolations (get project :interpolations {})
interpolatable-project (dissoc project :interpolations)
interpolated-project
(walk/postwalk
(fn [node]
(if (keyword? node)
(let [kns (keyword (namespace node))
k (keyword (name node))]
(cond
(= kns :project)
(k project)
(contains? interpolations node)
(let [interpolation (node interpolations)]
(if (fn? interpolation)
(interpolation project)
interpolation))
:else
node))
node))
interpolatable-project)]
(merge interpolated-project
{:interpolations interpolations})))
(defn middleware [project]
(interpolate-tokens project))