add load-clj and load-json functions (based on load-config)

This commit is contained in:
Gered 2013-05-20 20:06:35 -04:00
parent 72b277439d
commit 88ce5616e0
3 changed files with 22 additions and 6 deletions

View file

@ -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

View file

@ -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"

View file

@ -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