Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ulysses.env, google analytics setup, autotrack setup
- Loading branch information
Showing
8 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns ulysses.env) | ||
|
||
;; adapted from https://github.com/adzerk-oss/env/blob/master/src/adzerk/env.clj | ||
;; (added ^:export metadata to def'd vars) | ||
|
||
(defmacro env [] | ||
(if (:js-globals &env) | ||
(throw (IllegalStateException. | ||
"macro not available in CLJS: see https://github.com/adzerk-oss/env/issues/1")) | ||
(->> (merge {} (System/getenv) (System/getProperties)) | ||
(reduce #(into %1 (when-not (re-find #"\." (first %2)) [%2])) {})))) | ||
|
||
(defn- setenv [k v] | ||
(when v (assert (string? v)) (System/setProperty k v) v)) | ||
|
||
(defmacro def [& ks] | ||
(let [cljs? (:js-globals &env)] | ||
(loop [[[k v] & ks] (partition 2 ks), err [], ret []] | ||
(let [ex `(throw (ex-info ~(str "Required env vars: " err) {:missing-vars '~err}))] | ||
(when (and cljs? (not k) (seq err)) (eval ex)) | ||
(cond (not k) `(do ~@ret ~(when (seq err) ex)) | ||
:else (let [k' (name k) | ||
v' (get (env) k') | ||
v'' (or v' (when-not (= :required v) | ||
(if cljs? v `(#'setenv ~k' ~v)))) | ||
err (into err (when (and (not v') (= :required v)) [k]))] | ||
(recur ks err (conj ret `(do (~'def ^:export ~k ~v'') | ||
~(when-not cljs? | ||
`(add-watch (var ~k) :ulysses.env/w | ||
#(when %4 (#'setenv ~k' %4))))))))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters