use different profile resource-paths to include dev/prod site.configs
this also necessitated a change to how the couchdb table defs are defined as aot-ing the prod profile caused code to get evaluated which triggered at-compile-time-loading of site.config, which at that point the prod resources-paths would not have been merged in causing compilation errors
This commit is contained in:
parent
95540f0e72
commit
a055c6e2ef
2
env-resources/dev/site.config
Normal file
2
env-resources/dev/site.config
Normal file
|
@ -0,0 +1,2 @@
|
|||
{:env "DEV"
|
||||
:database {:url "http://couchdb:5984/"}}
|
14
project.clj
14
project.clj
|
@ -25,10 +25,12 @@
|
|||
:destroy blarg.handler/destroy}
|
||||
:profiles
|
||||
{:uberjar {:aot :all}
|
||||
:production {:ring {:open-browser? false
|
||||
:stacktraces? false
|
||||
:auto-reload? false}}
|
||||
:dev {:dependencies [[ring-mock "0.1.5"]
|
||||
[ring/ring-devel "1.2.1"]]
|
||||
:source-paths ["dev"]}}
|
||||
:production {:ring {:open-browser? false
|
||||
:stacktraces? false
|
||||
:auto-reload? false}
|
||||
:resource-paths ["env-resources/prod"]}
|
||||
:dev {:dependencies [[ring-mock "0.1.5"]
|
||||
[ring/ring-devel "1.2.1"]]
|
||||
:source-paths ["dev"]
|
||||
:resource-paths ["env-resources/dev"]}}
|
||||
:min-lein-version "2.0.0")
|
||||
|
|
|
@ -47,10 +47,10 @@
|
|||
:params {:errorInfo e}
|
||||
:status 500)))))
|
||||
|
||||
(defonce routes (find-routes "blarg.routes." app-routes))
|
||||
(def routes (find-routes "blarg.routes." app-routes))
|
||||
|
||||
(defonce app (app-handler
|
||||
routes
|
||||
:middleware [wrap-exceptions wrap-servlet-context-path]
|
||||
:access-rules [{:redirect "/unauthorized" :rule auth-required}]
|
||||
:formats [:json-kw :edn]))
|
||||
(def app (app-handler
|
||||
routes
|
||||
:middleware [wrap-exceptions wrap-servlet-context-path]
|
||||
:access-rules [{:redirect "/unauthorized" :rule auth-required}]
|
||||
:formats [:json-kw :edn]))
|
||||
|
|
|
@ -14,9 +14,24 @@
|
|||
:password pass)
|
||||
(cemerick.url/url url db))))
|
||||
|
||||
(def users (db-url "blarg_users"))
|
||||
(def posts (db-url "blarg_posts"))
|
||||
(def files (db-url "blarg_files"))
|
||||
(defmacro with-db [url & body]
|
||||
`(couch/with-db
|
||||
~url
|
||||
~@body))
|
||||
|
||||
(defn get-users-db []
|
||||
(db-url "blarg_users"))
|
||||
(defn get-posts-db []
|
||||
(db-url "blarg_posts"))
|
||||
(defn get-files-db []
|
||||
(db-url "blarg_files"))
|
||||
|
||||
(defmacro with-users-db [& body]
|
||||
`(with-db (get-users-db) ~@body))
|
||||
(defmacro with-posts-db [& body]
|
||||
`(with-db (get-posts-db) ~@body))
|
||||
(defmacro with-files-db [& body]
|
||||
`(with-db (get-files-db) ~@body))
|
||||
|
||||
(defmacro ->view-keys
|
||||
"returns a sequence of only the keys returned by running a view"
|
||||
|
@ -48,8 +63,8 @@
|
|||
"verifies that the required databases are present, creating them if they
|
||||
are not there (including the views)."
|
||||
[]
|
||||
(couch/get-database users)
|
||||
(when (couch/get-database files)
|
||||
(touch-design-doc files "_design/files" "couchdb/design_docs/files.js"))
|
||||
(when (couch/get-database posts)
|
||||
(touch-design-doc posts "_design/posts" "couchdb/design_docs/posts.js")))
|
||||
(couch/get-database (get-users-db))
|
||||
(when (couch/get-database (get-files-db))
|
||||
(touch-design-doc (get-files-db) "_design/files" "couchdb/design_docs/files.js"))
|
||||
(when (couch/get-database (get-posts-db))
|
||||
(touch-design-doc (get-posts-db) "_design/posts" "couchdb/design_docs/posts.js")))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
(defn file-exists? [file]
|
||||
(let [f (ensure-prefix file "/")]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(not (zero? (count (couch/get-view "files" "listPublished" {:key f})))))))
|
||||
|
||||
(defn get-file
|
||||
|
@ -15,7 +15,7 @@
|
|||
([file allow-unpublished?]
|
||||
(let [f (ensure-prefix file "/")
|
||||
view-name (if allow-unpublished? "listAll" "listPublished")]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(if-let [file-info (->first-view-value
|
||||
(couch/get-view "files" view-name {:key f}))]
|
||||
(let [id (:_id file-info)
|
||||
|
@ -30,7 +30,7 @@
|
|||
(defn list-files [path]
|
||||
(let [p (ensure-prefix-suffix path "/")]
|
||||
(if-let [file-list (->view-values
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(couch/get-view "files" "listAllByPath" {:key p})))]
|
||||
(map
|
||||
(fn [f]
|
||||
|
@ -45,11 +45,11 @@
|
|||
|
||||
(defn get-tree []
|
||||
(->view-keys
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(couch/get-view "files" "listPaths" {:group true}))))
|
||||
|
||||
(defn add-file [path filename file content-type]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(let [p (ensure-prefix-suffix path "/")
|
||||
id (str p filename)]
|
||||
(if-let [doc (couch/put-document {:_id id
|
||||
|
@ -60,7 +60,7 @@
|
|||
(couch/put-attachment doc file :filename filename :mime-type content-type)))))
|
||||
|
||||
(defn update-file [id file content-type]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(if-let [doc (couch/get-document id)]
|
||||
(let [filename (:filename doc)
|
||||
attachment (second (first (:_attachments doc)))]
|
||||
|
@ -70,13 +70,13 @@
|
|||
|
||||
(defn delete-file [id]
|
||||
(let [safe-id (ensure-prefix id "/")]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(if-let [doc (couch/get-document safe-id)]
|
||||
(couch/delete-document doc)))))
|
||||
|
||||
(defn publish-file [id publish?]
|
||||
(let [safe-id (ensure-prefix id "/")]
|
||||
(couch/with-db files
|
||||
(with-files-db
|
||||
(if-let [doc (couch/get-document safe-id)]
|
||||
(couch/update-document (-> doc
|
||||
(assoc :last_modified_at (get-timestamp))
|
||||
|
|
|
@ -48,19 +48,19 @@
|
|||
(defn get-post [id]
|
||||
(merge-cached-post-md!
|
||||
(->single-post
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-document id)))))
|
||||
|
||||
(defn get-post-by-date-slug [date slug]
|
||||
(merge-cached-post-md!
|
||||
(->single-post
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view "posts" "listPostsBySlug" {:key [date, slug]})))))
|
||||
|
||||
(defn add-post [title body user tags]
|
||||
(merge-cached-post-md!
|
||||
(->single-post
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/put-document
|
||||
{:title title
|
||||
:slug (->slug title)
|
||||
|
@ -76,7 +76,7 @@
|
|||
(if-let [post (get-post id)]
|
||||
(merge-cached-post-md!
|
||||
(->single-post
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/update-document
|
||||
(-> (date->string post timestamp-fields)
|
||||
(merge (if title {:title title :slug (->slug title)}))
|
||||
|
@ -89,7 +89,7 @@
|
|||
|
||||
(defn delete-post [id]
|
||||
(when-let [post (get-post id)]
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/delete-document post))
|
||||
(remove-cached-post! post)
|
||||
post))
|
||||
|
@ -99,7 +99,7 @@
|
|||
|
||||
(defn list-tags []
|
||||
(->view-keys
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view "posts" "listTags" {:group true}))))
|
||||
|
||||
(defn list-posts
|
||||
|
@ -114,13 +114,13 @@
|
|||
(map
|
||||
merge-cached-post-md!
|
||||
(->post-list
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view "posts" viewName params)))))))
|
||||
|
||||
(defn list-posts-by-tag [unpublished? tag]
|
||||
(let [view-name (if unpublished? "listPostsByTag" "listPublishedPostsByTag")]
|
||||
(if-let [posts (->post-list
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view "posts" view-name {:key tag
|
||||
:descending true})))]
|
||||
;TODO: look into couchdb partial key matching to do this sort at the DB
|
||||
|
@ -129,7 +129,7 @@
|
|||
(defn list-posts-archive [unpublished?]
|
||||
(let [view-name (if unpublished? "listPostsArchive" "listPublishedPostsArchive")]
|
||||
(if-let [posts (->post-list
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view "posts" view-name {:descending true})))]
|
||||
(map
|
||||
#(assoc % :mmyyyy (->nicer-month-year-str (:mmyyyy %)))
|
||||
|
@ -138,7 +138,7 @@
|
|||
(defn count-posts
|
||||
[unpublished?]
|
||||
(->first-view-value
|
||||
(couch/with-db posts
|
||||
(with-posts-db
|
||||
(couch/get-view
|
||||
"posts"
|
||||
(if unpublished? "countPosts" "countPublishedPosts")
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
(defn get-user
|
||||
([id]
|
||||
(couch/with-db users
|
||||
(with-users-db
|
||||
(couch/get-document id)))
|
||||
([id pass]
|
||||
(if-let [user (get-user id)]
|
||||
|
@ -18,10 +18,10 @@
|
|||
:password (crypt/encrypt pass)
|
||||
:email email
|
||||
:created_at (get-timestamp)}]
|
||||
(couch/with-db users
|
||||
(with-users-db
|
||||
(couch/put-document user))))
|
||||
|
||||
(defn delete-user [id]
|
||||
(couch/with-db users
|
||||
(with-users-db
|
||||
(if-let [user (get-user id)]
|
||||
(couch/delete-document user))))
|
||||
|
|
Reference in a new issue