A pastebin for markdown pages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
789 B

(ns NoteHub.settings
(:require [clojure.string :as cs]))
(defn get-setting
"Takes a settings key, a default value and a converter function and returns a corresponding
settings value. The default value is returned back when no setting value was found.
The converter function can be provided to convert the setting from string to a needed format."
[key & more]
(let [default (first more)
converter (second more)
file-content (slurp "settings")
lines (cs/split file-content #"\n")
pairs (map #(map cs/trim %) (map #(cs/split % #"=") lines))
config-map (apply hash-map (mapcat #(list (keyword (first %)) (second %)) pairs))
value (config-map key)]
(if value
(if (fn? converter) (converter value) value)
default)))