summaryrefslogtreecommitdiff
path: root/src/chef/frontend/visitor/recipe.clj
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
committerTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
commit8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e (patch)
treec0f5b6587b6f9f0b591b395c69ad7da08717a30b /src/chef/frontend/visitor/recipe.clj
parent229299146376a2b847f4fe3f331efbd26c0abc70 (diff)
downloadchef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.tar.xz
chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.zip
Refactor project structure
Diffstat (limited to 'src/chef/frontend/visitor/recipe.clj')
-rw-r--r--src/chef/frontend/visitor/recipe.clj55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/chef/frontend/visitor/recipe.clj b/src/chef/frontend/visitor/recipe.clj
new file mode 100644
index 0000000..e3dbf97
--- /dev/null
+++ b/src/chef/frontend/visitor/recipe.clj
@@ -0,0 +1,55 @@
+(ns chef.frontend.visitor.recipe
+ (:require [chef.utils :as cutils]
+ [clojure.string :as cstr]
+ [hiccup2.core :as html]
+ [ring.util.response :as ruresp]
+
+ [chef.logic.recipes :as clrecipes]
+ [chef.logic.categories :as clcategories]))
+
+(defn- render [portions recipe]
+ (cutils/gen-page (str "chef - " (:recipes/title recipe))
+ [:div {:style {:margin-left "1em"}}
+ [:div
+ [:h1 {:style {:display :inline-block
+ :margin-right "0.5em"}}
+ (:recipes/title recipe)]
+ [:i (str "(" (-> (:recipes/category recipe)
+ clcategories/get-category
+ clcategories/generate-path) ")")]]
+ (when (some? (clrecipes/get-recipe-thumbnail (:recipes/id recipe)))
+ [:img {:src (str "/recipes/" (:recipes/id recipe) "/thumbnail")
+ :width "50%"}])
+ [:h2
+ "Zutaten pro "
+ [:input {:type :number
+ :value portions
+ :style {:width "3em"
+ :display :inline-block}
+ "_" "on change go to url `?portions=${value of me}`"}]
+ (condp = (:recipes/unit recipe)
+ 0 " Portion(en)"
+ 1 " Person(en)"
+ "")
+ ":"]
+ [:ul (for [ingredient (-> recipe
+ :recipes/ingredients
+ cutils/parse-ingredients)]
+ [:li
+ [:b (:description ingredient)] ": "
+ (* (:amount ingredient) portions)
+ (:unit ingredient)])]
+ [:h2 "Zubereitung"]
+ (->> (:recipes/preparation recipe)
+ cstr/split-lines
+ (map #(if (cstr/blank? %)
+ [:br]
+ [:p %])))]))
+
+(defn handler [req]
+ (->> (clrecipes/get-recipe (get-in req [:path-params :id]))
+ (render (or (cutils/s->int-or-nil (get-in req [:params "portions"]))
+ 1))
+ html/html
+ str
+ ruresp/response))