Skip to content

Commit a5b56c1

Browse files
committed
filter document body in logger, impl templates in zd schema
1 parent d7835a1 commit a5b56c1

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

src/zd/core.clj

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@
8989

9090
(defmethod zen/op 'zd/new-doc
9191
[ztx _cfg {{docname :docname parent :parent} :params :as req} & opts]
92-
{:status 200
93-
:body (hiccup.core/html (view/editor ztx req {:zd/docname (cond docname (symbol docname)
94-
parent (symbol (str parent ".<>" ))
95-
:else 'new)} ""))})
92+
(let [doc {:zd/parent (symbol parent)
93+
:zd/docname (cond docname (symbol docname)
94+
parent (symbol (str parent ".<>"))
95+
:else 'new)}]
96+
{:status 200
97+
:body (hiccup.core/html (view/editor ztx req doc ""))}))
9698

9799
(defmethod zen/op 'zd/new-preview
98100
[ztx _cfg {body :body :as req} & opts]
@@ -192,8 +194,14 @@
192194
(swap! ztx dissoc :zdb :zd/backlinks))
193195

194196
(defmethod zen/op 'zd.events/logger
195-
[ztx config {ev-name :ev :as ev} & opts]
196-
(println (assoc ev ::ts (str (java.util.Date.)))))
197+
[ztx config {ev-name :ev doc :params :as ev} & opts]
198+
(let [ev (assoc ev ::ts (str (java.util.Date.)))]
199+
(if (= ev-name 'zd.events/on-doc-load)
200+
(println (assoc (dissoc ev :params) :docname (:zd/docname doc)))
201+
(println ev))))
202+
203+
(defmethod zen-web.core/middleware-in 'zd/auth
204+
[ztx config ev & opts])
197205

198206
(defn start [& [dir gitsync]]
199207
(let [ztx (zen/new-context {:zd/dir dir :zd/gitsync gitsync})]
@@ -211,6 +219,8 @@
211219

212220
(stop ztx)
213221

222+
(:zd/props @ztx)
223+
214224
(:zd/backlinks @ztx)
215225

216226
(git/exec {:dir (:zd/dir @ztx) :exec ["git" "log" "-1"]})

src/zd/schema.clj

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(ns zd.schema
22
(:require [clojure.string :as str]))
33

4-
54
(defn to-keyname [docname]
65
(let [parts (str/split (str docname) #"\.")
76
ns (str/join "." (butlast parts))]
7+
;; TODO rename to _schema.zd ?
88
(if (= ns "_")
99
(keyword (last parts))
1010
(keyword ns (last parts)))))
@@ -18,6 +18,32 @@
1818
(swap! ztx update :zd/classes dissoc docname)
1919
docname)
2020

21+
(defn get-class-props [ztx classname]
22+
(into (filter (fn [[k v]]
23+
;; TODO think about different naming for root sch
24+
(= (:zd/parent v) '_))
25+
(:zd/props @ztx))
26+
(filter (fn [[k v]]
27+
(= (:zd/parent v) classname))
28+
(:zd/props @ztx))))
29+
30+
(defn get-class-template [ztx classname]
31+
(->> (get-class-props ztx classname)
32+
(map (fn [[k {df :zd/default dt :zd/data-type}]]
33+
(cond
34+
(and (= dt 'zd.string) (str/blank? df))
35+
(str k " \"\"")
36+
37+
(= 'zd.string dt)
38+
(format (str k " \"%s\"") df)
39+
40+
(= 'zd.zentext dt)
41+
(format (str k " /\n%s") df)
42+
43+
:else
44+
(format (str k " %s") df))))
45+
(str/join "\n")))
46+
2147
(defn get-class [ztx docname]
2248
(or (get-in @ztx [:zd/classes docname])
2349
(get-in @ztx [:zdb docname])))

src/zd/view/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(layout/layout-with-menu ztx ctx doc (view ztx ctx doc)))
2727

2828
(defn editor [ztx ctx doc content]
29-
(layout/layout ztx ctx (zd.view.editor/editor ztx ctx doc content)))
29+
(layout/layout ztx ctx (zd.view.editor/editor ztx ctx doc content)))
3030

3131
(defn timeline [ztx ctx data]
3232
(layout/layout-with-menu ztx ctx {:zd/docname 'git} (timeline/view ztx data)))

src/zd/view/editor.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
(ns zd.view.editor
22
(:require [cheshire.core :as json]
3+
[clojure.string :as str]
34
[hiccup.core]
45
[hiccup.util]
6+
[zd.schema :as sch]
57
[zd.view.icons :as icons]
68
[zd.store :as store]))
79

8-
9-
;; TODO: templates
1010
(defn editor [ztx ctx {docname :zd/docname :as doc} content]
1111
(let [header (str ":zd/docname " (:zd/docname doc) "\n")
1212
text (str header content)
13+
template (when (str/blank? content)
14+
(sch/get-class-template ztx (:zd/parent doc)))
1315
symbols (store/symbols ztx)
1416
anns (store/annotations ztx)
15-
zendoc {:text text
17+
zendoc {:text (if (str/blank? content)
18+
(str text "\n" template)
19+
text)
1620
:symbols symbols
1721
:keys (store/props ztx)
1822
:icons icons/icons

0 commit comments

Comments
 (0)