summaryrefslogtreecommitdiff
path: root/src/chef/pages/recipe.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/pages/recipe.clj')
-rw-r--r--src/chef/pages/recipe.clj50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/chef/pages/recipe.clj b/src/chef/pages/recipe.clj
index 71dd4b2..84f999c 100644
--- a/src/chef/pages/recipe.clj
+++ b/src/chef/pages/recipe.clj
@@ -1,10 +1,12 @@
(ns chef.pages.recipe
(:require [chef.database :as cdb]
[chef.utils :as cutils]
+ [clojure.string :as cstr]
[hiccup2.core :as html]
[honey.sql :as sql]
[next.jdbc :as jdbc]
- [ring.util.response :as ruresp]))
+ [ring.util.response :as ruresp])
+ (:import java.io.File))
(defn- render [recipe]
(cutils/gen-page (str "chef - " (:recipes/title recipe))
@@ -13,13 +15,33 @@
[:h1 {:style {:display :inline-block
:margin-right "0.5em"}}
(:recipes/title recipe)]
- [:i (cutils/category-path (->> {:select [:*]
- :from [:categories]
- :where [:= :id (:recipes/category recipe)]}
- sql/format
- (jdbc/execute! @cdb/db)
- first))]]
- [:b "TODO"]]))
+ [:i (str "(" (cutils/category-path (->> {:select [:*]
+ :from [:categories]
+ :where [:= :id (:recipes/category recipe)]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first)) ")")]]
+ (when (some? (cutils/get-thumbnail-file recipe))
+ [:img {:src (str "/recipes/" (:recipes/id recipe) "/thumbnail")
+ :width "50%"}])
+ [:h2 (str "Zutaten"
+ (condp = (:recipes/unit recipe)
+ 0 " pro Portion"
+ 1 " pro Person"
+ "")
+ ":")]
+ [:ul (for [ingredient (-> recipe
+ :recipes/ingredients
+ cutils/parse-ingredients)]
+ [:li
+ [:b (:description ingredient)] ": "
+ (:amount ingredient) (:unit ingredient)])]
+ [:h2 "Zubereitung"]
+ (->> (:recipes/preparation recipe)
+ cstr/split-lines
+ (map #(if (cstr/blank? %)
+ [:br]
+ [:p %])))]))
(defn handler [req]
(->> {:select [:*]
@@ -32,3 +54,15 @@
html/html
str
ruresp/response))
+
+(defn thumbnail-handler [req]
+ (if-let [id (get-in req [:path-params :id])]
+ (when-let [thumbnail-file (->> {:select [:*]
+ :from [:recipes]
+ :where [:= :id id]}
+ sql/format
+ (jdbc/execute! @cdb/db)
+ first
+ cutils/get-thumbnail-file)]
+ (ruresp/file-response (.getPath ^File thumbnail-file)))
+ (ruresp/bad-request "Bad request.")))