File tree Expand file tree Collapse file tree 4 files changed +51
-11
lines changed Expand file tree Collapse file tree 4 files changed +51
-11
lines changed Original file line number Diff line number Diff line change 89
89
90
90
(defmethod zen /op 'zd /new-doc
91
91
[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 " " ))}))
96
98
97
99
(defmethod zen /op 'zd /new-preview
98
100
[ztx _cfg {body :body :as req} & opts]
192
194
(swap! ztx dissoc :zdb :zd/backlinks ))
193
195
194
196
(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])
197
205
198
206
(defn start [& [dir gitsync]]
199
207
(let [ztx (zen/new-context {:zd/dir dir :zd/gitsync gitsync})]
211
219
212
220
(stop ztx)
213
221
222
+ (:zd/props @ztx)
223
+
214
224
(:zd/backlinks @ztx)
215
225
216
226
(git/exec {:dir (:zd/dir @ztx) :exec [" git" " log" " -1" ]})
Original file line number Diff line number Diff line change 1
1
(ns zd.schema
2
2
(:require [clojure.string :as str]))
3
3
4
-
5
4
(defn to-keyname [docname]
6
5
(let [parts (str/split (str docname) #"\. " )
7
6
ns (str/join " ." (butlast parts))]
7
+ ; ; TODO rename to _schema.zd ?
8
8
(if (= ns " _" )
9
9
(keyword (last parts))
10
10
(keyword ns (last parts)))))
18
18
(swap! ztx update :zd/classes dissoc docname)
19
19
docname )
20
20
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
+
21
47
(defn get-class [ztx docname]
22
48
(or (get-in @ztx [:zd/classes docname])
23
49
(get-in @ztx [:zdb docname])))
Original file line number Diff line number Diff line change 26
26
(layout/layout-with-menu ztx ctx doc (view ztx ctx doc)))
27
27
28
28
(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)))
30
30
31
31
(defn timeline [ztx ctx data]
32
32
(layout/layout-with-menu ztx ctx {:zd/docname 'git} (timeline/view ztx data)))
Original file line number Diff line number Diff line change 1
1
(ns zd.view.editor
2
2
(:require [cheshire.core :as json]
3
+ [clojure.string :as str]
3
4
[hiccup.core]
4
5
[hiccup.util]
6
+ [zd.schema :as sch]
5
7
[zd.view.icons :as icons]
6
8
[zd.store :as store]))
7
9
8
-
9
- ; ; TODO: templates
10
10
(defn editor [ztx ctx {docname :zd/docname :as doc} content]
11
11
(let [header (str " :zd/docname " (:zd/docname doc) " \n " )
12
12
text (str header content)
13
+ template (when (str/blank? content)
14
+ (sch/get-class-template ztx (:zd/parent doc)))
13
15
symbols (store/symbols ztx)
14
16
anns (store/annotations ztx)
15
- zendoc {:text text
17
+ zendoc {:text (if (str/blank? content)
18
+ (str text " \n " template)
19
+ text)
16
20
:symbols symbols
17
21
:keys (store/props ztx)
18
22
:icons icons/icons
You can’t perform that action at this time.
0 commit comments