diff --git a/project.clj b/project.clj index 2935463..2d10511 100644 --- a/project.clj +++ b/project.clj @@ -3,6 +3,7 @@ :dependencies [[org.clojure/clojure "1.5.1"] [hiccup "1.0.0"] [zeus "0.1.0"] + [iokv "0.1.1"] [cheshire "5.3.1"] [ring/ring-core "1.2.0"] [com.taoensso/carmine "2.4.4"] diff --git a/src/notehub/api.clj b/src/notehub/api.clj index 50bdda9..a8b3be2 100644 --- a/src/notehub/api.clj +++ b/src/notehub/api.clj @@ -2,7 +2,7 @@ (:import [java.util Calendar]) (:use - [notehub.settings] + [iokv.core] [ring.util.codec :only [url-encode]] [clojure.string :rename {replace sreplace} :only [replace blank? trim lower-case split-lines split]]) diff --git a/src/notehub/handler.clj b/src/notehub/handler.clj index f48d40c..ab6904d 100644 --- a/src/notehub/handler.clj +++ b/src/notehub/handler.clj @@ -1,9 +1,10 @@ (ns notehub.handler - (:use compojure.core - [notehub.views] - [notehub.settings] - [clojure.string :rename {replace sreplace} :only [replace]] - [clojure.core.incubator :only [-?>]]) + (:use + compojure.core + iokv.core + notehub.views + [clojure.string :rename {replace sreplace} :only [replace]] + [clojure.core.incubator :only [-?>]]) (:require [hiccup.util :as util] [compojure.handler :as handler] diff --git a/src/notehub/settings.clj b/src/notehub/settings.clj deleted file mode 100644 index f669316..0000000 --- a/src/notehub/settings.clj +++ /dev/null @@ -1,45 +0,0 @@ -(ns notehub.settings - (:use [clojure.string - :rename {replace sreplace} - :only [blank? trim split split-lines replace upper-case]])) - -; Loads and parses any file with each line consisting a key and -; a value separated by a "=", and returns a corresponding key-value map. -(defn- get-pairs-map [file] - (let [file-content (slurp file) - pairs (map #(map trim (split % #"=" 2)) - (remove blank? (split-lines file-content)))] - (apply hash-map - (mapcat #(list (keyword (first %)) (second %)) pairs)))) - -; Loads the setting file to a map -(def settings-map - (get-pairs-map "settings")) - -; Loads the messages file to a map -(def messages-map - (get-pairs-map "messages")) - -(defn get-message [key] - "Returns messages used in layouts. Every key should be a keyword, e.g. (get-message :title)." - (messages-map key)) - -(defn get-setting - "Takes a settings key, a converter function and a default value, and returns a corresponding - setting 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 type. - This function is not applied to the specified default value! - Every specified key should be a keyword, e.g. (get-setting :page-width)." - [key & more] - (let [converter (first more) - default (second more) - value (settings-map key) - ; Through this hack we can read security-critical settings from (previously - ; set) shell variables without commiting their content to CVS - value (if value value - (System/getenv - (upper-case - (sreplace (name key) #"-" ""))))] - (if value - (if (fn? converter) (converter value) value) - default))) diff --git a/src/notehub/storage.clj b/src/notehub/storage.clj index 3dd1d97..82e81d4 100644 --- a/src/notehub/storage.clj +++ b/src/notehub/storage.clj @@ -1,5 +1,5 @@ (ns notehub.storage - (:use [notehub.settings] + (:use [iokv.core] [zeus.core] [clojure.string :only (blank? replace) :rename {replace sreplace}]) (:require [taoensso.carmine :as car :refer (wcar)])) diff --git a/src/notehub/views.clj b/src/notehub/views.clj index c47e009..893f8c6 100644 --- a/src/notehub/views.clj +++ b/src/notehub/views.clj @@ -1,14 +1,17 @@ (ns notehub.views - (:use [notehub.settings] - [clojure.string :rename {replace sreplace} :only [replace]] - [clojure.core.incubator :only [-?>]] - [hiccup.form] - [hiccup.core] - [hiccup.element] - [hiccup.util :only [escape-html]] - [hiccup.page :only [include-js html5]]) + (:use + iokv.core + [clojure.string :rename {replace sreplace} :only [replace]] + [clojure.core.incubator :only [-?>]] + [hiccup.form] + [hiccup.core] + [hiccup.element] + [hiccup.util :only [escape-html]] + [hiccup.page :only [include-js html5]]) (:require [notehub.api :as api])) +(def get-message (get-map "messages")) + ; Creates the main html layout (defn layout [title & content]