(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])) (defn- render [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 (cutils/category-path (->> {:select [:*] :from [:categories] :where [:= :id (:recipes/category recipe)]} sql/format (jdbc/execute! @cdb/db) first))]] [: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 [:*] :from [:recipes] :where [:= :id (get-in req [:path-params :id])]} sql/format (jdbc/execute! @cdb/db) first render html/html str ruresp/response))