From ac448b8e2f3db853b0dd851b91f9961f9eb6d26c Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Tue, 8 Jan 2019 19:07:39 +0100 Subject: [PATCH] some easing on parameters, rendering of markdown --- project.clj | 4 +++- src/wanijo/framework/auth.clj | 8 ++++---- src/wanijo/instance/routes.clj | 4 +--- src/wanijo/instance/view.clj | 28 ++++++++++++++++++---------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/project.clj b/project.clj index 1efe706..cf33ed4 100644 --- a/project.clj +++ b/project.clj @@ -16,7 +16,9 @@ com.github.ben-manes.caffeine/caffeine]] [buddy/buddy-hashers "1.3.0" :exclusions [commons-codec]] - [clj-time "0.15.1"]] + + [clj-time "0.15.1"] + [markdown-clj "1.0.5"]] :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] [ring/ring-mock "0.3.2"]] diff --git a/src/wanijo/framework/auth.clj b/src/wanijo/framework/auth.clj index 6cc3347..a0030a4 100644 --- a/src/wanijo/framework/auth.clj +++ b/src/wanijo/framework/auth.clj @@ -23,18 +23,18 @@ (defn login! [req] (view/layout! :content - [[:h1 "Kama ken"] + [[:h1 "Login"] (hform/form-to [:post (path :auth-login-check)] (when (:flash req) [:section.flash (:flash req)]) ;; - (hform/label "uname" "Nimi") + (hform/label "uname" "Name") (hform/text-field {:required "required"} "uname") ;; - (hform/label "pw" "Toki Pimeja") + (hform/label "pw" "Password") (hform/password-field {:required "required"} "pw") ;; - (hform/submit-button "Kama") + (hform/submit-button "Login") (anti-forgery-field))])) (defroutes routes diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index da3763b..2f0acbe 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -44,9 +44,7 @@ (domain/find-properties! uuid))) (defn show! [uuid req] - (view/show! (instance! uuid) - (domain-attr/find-by-instance! uuid) - req)) + (view/show! (instance! uuid) req)) (defn edit-form! [uuid req] (let [instance (instance! uuid) diff --git a/src/wanijo/instance/view.clj b/src/wanijo/instance/view.clj index 8c08058..a64cd45 100644 --- a/src/wanijo/instance/view.clj +++ b/src/wanijo/instance/view.clj @@ -3,11 +3,13 @@ [form :as hform] [core :refer [h]]] [ring.util.anti-forgery :refer [anti-forgery-field]] + [markdown.core :as md] [formulare.core :as form] [wanijo.instance.domain :as domain] - [wanijo.framework.view :as view] - [wanijo.framework.routing :refer [path]] - [wanijo.framework.time :refer [prettify-dt]])) + [wanijo.framework + [view :as view] + [routing :refer [path]] + [time :refer [prettify-dt]]])) (defn list! [schema instances new-form req] (view/layout! @@ -36,7 +38,7 @@ (:uuid schema)) (hform/submit-button "Create!"))])) -(defn show! [instance attrs req] +(defn show! [instance req] (view/layout! :request req :content @@ -47,12 +49,18 @@ [:p [:small [:a {:href (path :instance-edit-form instance)} "Edit Instance"]]] - (for [attr attrs - :let [auuid (:uuid attr) - prop (first (filter #(= auuid (-> % :attribute :uuid)) - (:properties instance)))]] - (list [:em (h (:name attr))] - [:p (h (:value prop))]))])) + [:h2 "Properties"] + (for [prop (:properties instance) + :let [attr (:attribute prop) + type (:type attr) + render-fn (case type + "date" #(str (prettify-dt %)) + "markdown" md/md-to-html-string + :else #(str "

" % "

"))]] + (list [:h3 (h (:name attr))] + [:div {:class (str "instance-content " + "attr-type-" type)} + (render-fn (:value prop))]))])) (defn edit! [instance form form-data req] (view/layout!