diff --git a/project.clj b/project.clj index a8e1e59..98d7091 100644 --- a/project.clj +++ b/project.clj @@ -13,7 +13,8 @@ [com.ashafa/clutch "0.4.0-RC1"] [slugger "1.0.1"] [clj-time "0.5.0"] - [org.clojure/math.numeric-tower "0.0.2"]] + [org.clojure/math.numeric-tower "0.0.2"] + [cheshire "5.1.2"]] :plugins [[lein-ring "0.8.5"]] :ring {:handler blarg.handler/war-handler :init blarg.handler/init diff --git a/src/blarg/config.clj b/src/blarg/config.clj index 3bb11c5..821dc45 100644 --- a/src/blarg/config.clj +++ b/src/blarg/config.clj @@ -1,12 +1,12 @@ (ns blarg.config + (:use [blarg.util]) (:require [clojure.java.io :as io]) (:import [java.io PushbackReader])) (def site-config (atom nil)) (defn load-config [] - (with-open [r (PushbackReader. (io/reader (io/resource "site.config")))] - (read r))) + (load-clj "site.config")) (defn get-config "returns the entire site configuration" diff --git a/src/blarg/util.clj b/src/blarg/util.clj index 5f8ebbb..93751b8 100644 --- a/src/blarg/util.clj +++ b/src/blarg/util.clj @@ -1,12 +1,27 @@ (ns blarg.util - (:require [noir.io :as io] - [markdown.core :as md])) + (:require [clojure.java.io :as io] + [markdown.core :as md] + [noir.io] + [cheshire.core :refer :all]) + (:import [java.io PushbackReader])) + +(defn load-clj + "loads a file from the resources directory, parses and returns it as clojure" + [file] + (with-open [r (PushbackReader. (io/reader (io/resource file)))] + (read r))) + +(defn load-json + "loads a file from the resources directory, parses it as JSON and returns it + as an equivalent clojure object" + [file] + (parse-stream (io/reader (io/resource file)) true)) (defn md->html "reads a markdown file from public/md and returns an HTML string" [filename] (->> - (io/slurp-resource filename) + (noir.io/slurp-resource filename) (md/md-to-html-string))) (defn string->int