Skip to content

Commit

Permalink
drop run task, add session to file ops
Browse files Browse the repository at this point in the history
  • Loading branch information
carbon-hvze committed Sep 18, 2023
1 parent 4317f90 commit 4eead52
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
3 changes: 0 additions & 3 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
:enter (do)
:leave (do)

run {:doc "Run on 3333 port with basic auth"
:task (clojure {:extra-env {}} "-M:run")}

repl {:doc "Run Clojure repl for Emacs with cider"
:task (clojure "-M:nrepl")}

Expand Down
4 changes: 0 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
:jvm-opts ["-XX:-OmitStackTraceInFastThrow"]
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:run
{:jvm-opts ["-XX:-OmitStackTraceInFastThrow"]
:main-opts ["-m" "zd.system"]}

:kaocha
{:extra-deps {lambdaisland/kaocha {:mvn/version "1.77.1236"}}
:extra-paths ["test"]
Expand Down
12 changes: 6 additions & 6 deletions src/zd/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@
:body (hiccup.core/html (view/preview ztx req doc))}))

(defmethod zen/op 'zd/create-doc
[ztx _cfg { body :body} & opts]
[ztx _cfg { body :body session :session} & opts]
(let [content (if (= BytesInputStream (type body)) (slurp body) body)
docname (store/extract-docname content)
doc (store/file-save ztx docname content)]
doc (store/file-save ztx docname content {:session session })]
{:status 200
:body (str "/" (:zd/docname doc))}))


(defmethod zen/op 'zd/save-doc
[ztx _cfg {{id :id} :route-params body :body :as req} & opts]
[ztx _cfg {{id :id} :route-params body :body session :session :as req} & opts]
(let [docname (symbol id)
content (if (= BytesInputStream (type body)) (slurp body) body)
doc (store/file-save ztx docname content)]
doc (store/file-save ztx docname content {:session session })]
{:status 200
:body (str "/" (:zd/docname doc))}))

Expand Down Expand Up @@ -165,9 +165,9 @@
:body (hiccup.core/html [:div "Error: " id " is not found"])})))

(defmethod zen/op 'zd/delete-doc
[ztx _cfg {{:keys [id]} :route-params :as req} & opts]
[ztx _cfg {{:keys [id]} :route-params session :session :as req} & opts]
(let [docname (symbol id)]
(store/file-delete ztx docname)
(store/file-delete ztx docname {:session session})
{:status 200
:body (str (store/parent-name docname))}))

Expand Down
26 changes: 13 additions & 13 deletions src/zd/store.clj
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@

(defn commit-delete
"remove file from git index and push new commit"
[ztx docpath docname]
[ztx session docpath docname]
(when-let [repo (:zd/repo @ztx)]
(git/with-identity ident
(git/git-pull repo {:ff-mode :ff :rebase-mode :none :strategy :ours})
(let [{:keys [missing]} (git/git-status repo)
git-config (git/git-config-load repo)
uname (or (.getString git-config "user" nil "name") "unknown editor")
email (or (.getString git-config "user" nil "email") "[email protected]")]
uname (or (.getString git-config "user" nil "name") (:name session) "unknown editor")
email (or (.getString git-config "user" nil "email") (:email session) "[email protected]")]
(doseq [m missing]
(when (str/includes? docpath m)
(git/git-rm repo m)
Expand All @@ -360,7 +360,7 @@

(defn file-delete
"save document content into file and recalculate databases"
[ztx docname]
[ztx docname & [{session :session}]]
(let [dir (:zd/dir @ztx)
path (docname-to-path docname)
docpath (str dir "/" path)
Expand All @@ -372,10 +372,10 @@
(doc-delete ztx docname)
(clear-menu ztx docname)
(->> (children ztx docname)
(mapv (fn [child] (file-delete ztx child))))
(mapv (fn [child] (file-delete ztx child {:session session }))))
(when (.exists file) (.delete file))
(when (.exists filedir) (.delete filedir))
(commit-delete ztx docpath docname)
(commit-delete ztx session docpath docname)
(->> (backlinked ztx docname)
(mapv (fn [d] (validate-doc ztx d))))
doc))
Expand Down Expand Up @@ -405,7 +405,7 @@

(defn commit-changes
"commit added, changed files and push"
[ztx docpath docname]
[ztx session docpath docname]
(when-let [repo (:zd/repo @ztx)]
(git/with-identity ident
(let [;; TODO sync all untracked docs at gitsync start?
Expand All @@ -421,8 +421,8 @@

(doseq [m (into untracked modified)]
(when (str/includes? docpath m)
(let [uname (or (.getString git-config "user" nil "name") "unknown editor")
email (or (.getString git-config "user" nil "email") "[email protected]")]
(let [uname (or (.getString git-config "user" nil "name") (:name session) "unknown editor")
email (or (.getString git-config "user" nil "email") (:email session) "[email protected]")]
(git/git-add repo m)
(let [msg (if (contains? untracked m)
(str "Create " docname)
Expand All @@ -432,7 +432,7 @@

(defn file-save
"save document content into file and recalculate databases"
[ztx docname content & [{dont-validate :dont-validate rename :rename :as opts}]]
[ztx docname content & [{dont-validate :dont-validate rename :rename session :session :as opts}]]
(let [[new-docname content] (extract-docname content)
new-docname (or new-docname rename docname)
dir (:zd/dir @ztx)
Expand All @@ -446,14 +446,14 @@
(->> (children ztx docname)
(mapv (fn [childname]
(let [new-childname (symbol (str new-docname (subs (str childname) (count (str docname)))))]
(file-save ztx childname (file-content ztx childname) {:rename new-childname})))))
(file-delete ztx docname))
(file-save ztx childname (file-content ztx childname) {:rename new-childname :session session})))))
(file-delete ztx docname {:session session }))
;; calculate removed subdocs
(let [to-remove (clojure.set/difference (into #{} (:zd/subdocs old-doc)) (into #{} (:zd/subdocs doc')))]
(->> to-remove (mapv #(doc-delete ztx %))))))
(.mkdirs (io/file (parent-dir docpath)))
(spit docpath content)
(commit-changes ztx docpath new-docname)
(commit-changes ztx session docpath new-docname)
(doc-save ztx doc' opts)
(->> (:zd/subdocs doc)
(mapv (fn [subdoc]
Expand Down

0 comments on commit 4eead52

Please sign in to comment.