Add basic pipeline plumbing
This commit is contained in:
parent
ef6922ab83
commit
eea6a1e858
|
@ -18,3 +18,4 @@ profiles.clj
|
|||
resources/posts/
|
||||
/resources/author/
|
||||
resources/index/
|
||||
.eastwood
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
"Userspace functions you can run by default in your local REPL."
|
||||
(:require
|
||||
[shapey-shifty.config :refer [env]]
|
||||
[clojure.pprint]
|
||||
[clojure.spec.alpha :as s]
|
||||
[expound.alpha :as expound]
|
||||
[mount.core :as mount]
|
||||
[shapey-shifty.core :refer [start-app]]))
|
||||
[clojure.pprint]
|
||||
[clojure.spec.alpha :as s]
|
||||
[expound.alpha :as expound]
|
||||
[mount.core :as mount]
|
||||
[shapey-shifty.core :refer [start-app]]))
|
||||
|
||||
(alter-var-root #'s/*explain-out* (constantly expound/printer))
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
(def base-path "resources/author")
|
||||
|
||||
(defn create-author []
|
||||
(defn create-author []
|
||||
{:card nil :password-hash nil})
|
||||
|
||||
(defn load-author [author-name]
|
||||
(defn load-author [author-name]
|
||||
(let [path (format "%s/%s" base-path author-name)
|
||||
file (io/file path)]
|
||||
(when (.exists file)
|
||||
|
@ -16,9 +16,9 @@
|
|||
edn/read-string))))
|
||||
|
||||
(defn load-all-authors []
|
||||
(->> base-path
|
||||
io/file
|
||||
file-seq
|
||||
(filter #(.isFile %))
|
||||
(map #(->> % slurp edn/read-string))))
|
||||
(->> base-path
|
||||
io/file
|
||||
file-seq
|
||||
(filter #(.isFile %))
|
||||
(map #(->> % slurp edn/read-string))))
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
(ns shapey-shifty.core
|
||||
(:require
|
||||
[shapey-shifty.handler :as handler]
|
||||
[shapey-shifty.nrepl :as nrepl]
|
||||
[luminus.http-server :as http]
|
||||
[shapey-shifty.config :refer [env]]
|
||||
[clojure.tools.cli :refer [parse-opts]]
|
||||
[clojure.tools.logging :as log]
|
||||
[mount.core :as mount])
|
||||
[shapey-shifty.handler :as handler]
|
||||
[shapey-shifty.nrepl :as nrepl]
|
||||
[luminus.http-server :as http]
|
||||
[shapey-shifty.config :refer [env]]
|
||||
[clojure.tools.cli :refer [parse-opts]]
|
||||
[clojure.tools.logging :as log]
|
||||
[mount.core :as mount])
|
||||
(:gen-class))
|
||||
|
||||
;; log uncaught exceptions in threads
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns shapey-shifty.index.index
|
||||
(:require [clucy.core :as clucy]
|
||||
[shapey-shifty.posts.posts-io :as post-io]
|
||||
))
|
||||
[shapey-shifty.posts.posts-io :as post-io]))
|
||||
|
||||
(def index-path (atom "resources/index"))
|
||||
|
||||
|
@ -13,7 +12,7 @@
|
|||
(defn crawl-posts!
|
||||
([path]
|
||||
(crawl-posts! path post-io/read-post))
|
||||
([path parsing-fn]
|
||||
([path parsing-fn]
|
||||
(->> path
|
||||
clojure.java.io/file
|
||||
file-seq
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
(ns shapey-shifty.pipeline.core)
|
||||
|
||||
(def pipelines (atom {:load-post []
|
||||
:render-post []
|
||||
:write-post []}))
|
||||
|
||||
(defn update-pipeline [k f]
|
||||
(swap! pipelines #(update % k conj f)))
|
||||
|
||||
(defn add-load-post-step [f]
|
||||
(update-pipeline :load-post f))
|
||||
|
||||
(defn add-render-post-step [f]
|
||||
(update-pipeline :render-post f))
|
||||
|
||||
(defn add-write-post-step [f]
|
||||
(update-pipeline :write-post f))
|
||||
|
||||
(defn execute-pipeline [k params]
|
||||
(let [p (k @pipelines)]
|
||||
((apply comp p) params)))
|
||||
|
||||
(defn add-pipeline [k v]
|
||||
(swap! pipelines #(assoc % k v)))
|
|
@ -1,7 +1,7 @@
|
|||
(ns shapey-shifty.posts.posts-io
|
||||
(:require
|
||||
[shapey-shifty.posts.core :as core]
|
||||
[shapey-shifty.authors.author-core :as author]))
|
||||
[shapey-shifty.posts.core :as core]
|
||||
[shapey-shifty.authors.author-core :as author]))
|
||||
|
||||
(def post-filename "post.json")
|
||||
(def base-posts-path "resources/posts")
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
(ns shapey-shifty.routes.home
|
||||
(:require
|
||||
[shapey-shifty.layout :as layout]
|
||||
[clojure.java.io :as io]
|
||||
[shapey-shifty.middleware :as middleware]
|
||||
[ring.util.response]
|
||||
[shapey-shifty.posts.core :as posts]
|
||||
[shapey-shifty.posts.posts-io :as post-io]
|
||||
[shapey-shifty.routes.post-router :as post-router]
|
||||
[shapey-shifty.authors.author-core :as author]
|
||||
[ring.util.http-response :as response]))
|
||||
[shapey-shifty.layout :as layout]
|
||||
[clojure.java.io :as io]
|
||||
[shapey-shifty.middleware :as mid]
|
||||
[ring.util.response]
|
||||
[shapey-shifty.posts.core :as posts]
|
||||
[shapey-shifty.posts.posts-io :as post-io]
|
||||
[shapey-shifty.routes.post-router :as post-router]
|
||||
[shapey-shifty.authors.author-core :as author]
|
||||
[ring.util.http-response :as response]))
|
||||
|
||||
(def middleware (atom [mid/wrap-csrf mid/wrap-formats]))
|
||||
|
||||
(defn home-page [request]
|
||||
(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
|
||||
|
||||
(defn test-view [request]
|
||||
(layout/render request "post.html" {:post (-> (posts/create-empty-post) (posts/set-content "Hey there everyone!") (posts/set-name "Yolo") :properties)}))
|
||||
|
||||
(defn post-view [request]
|
||||
(let [{:keys [path-params query-params body-params]} request
|
||||
{:keys [year month day n]} path-params
|
||||
|
@ -24,16 +23,13 @@
|
|||
:card (:author post)})))
|
||||
|
||||
(defn about-page [request]
|
||||
(layout/render request "h_card.html"
|
||||
{
|
||||
:card (:card (author/load-author (get-in request [:path-params :name])))
|
||||
}))
|
||||
(layout/render request "h_card.html"
|
||||
{:card (:card (author/load-author (get-in request [:path-params :name])))}))
|
||||
|
||||
(defn home-routes []
|
||||
[""
|
||||
{:middleware [middleware/wrap-csrf
|
||||
middleware/wrap-formats]}
|
||||
{:middleware @middleware}
|
||||
["/" {:get home-page}]
|
||||
["/blog/:year/:month/:day/:n" {:get post-view}]
|
||||
["/about/:name" {:get about-page}]])
|
||||
["/about/:name" {:get about-page}]
|
||||
["/:year/:month/:day/:n" {:get post-view}]])
|
||||
|
||||
|
|
Loading…
Reference in New Issue