This commit is contained in:
@@ -98,16 +98,19 @@
|
|||||||
(apply merge))
|
(apply merge))
|
||||||
_ nil)))
|
_ nil)))
|
||||||
|
|
||||||
(defn read-string [s])
|
(defn read-string [s]
|
||||||
|
(match (-> s read first)
|
||||||
|
[:string x & props] x
|
||||||
|
:else nil))
|
||||||
|
|
||||||
|
(defn print [x]
|
||||||
|
;; TODO: this is really not how it should be done lol. at the
|
||||||
|
;; moment, `print` is only used in `net.deertopia.publisher.roam`
|
||||||
|
;; and only to serialise uuids, so it's not a /massive/ priority.
|
||||||
|
(cond (string? x) (str \" s \")))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(do (ip/defparser parse* (io/resource "elisp-grammar"))
|
(do (ip/defparser parse* (io/resource "elisp-grammar"))
|
||||||
(parse "#(\"blah\" 0 1 (doge))")
|
(read "#(\"blah\" 0 1 (doge))")
|
||||||
|
(read "\"bla\\nh\"")
|
||||||
(read-alist "((x . y))")))
|
(read-alist "((x . y))")))
|
||||||
|
|
||||||
(defn print-elisp-string [s]
|
|
||||||
(str \" s \"))
|
|
||||||
|
|
||||||
(defn read-elisp-string [s]
|
|
||||||
(let [[_ in] (re-matches #"\"(.*)\"" s)]
|
|
||||||
in))
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
(-> node :id slug/from-uuid))
|
(-> node :id slug/from-uuid))
|
||||||
|
|
||||||
(defn- print-id [node]
|
(defn- print-id [node]
|
||||||
(-> node id print-elisp-string))
|
(-> node id print))
|
||||||
|
|
||||||
|
|
||||||
;;; Node
|
;;; Node
|
||||||
@@ -55,8 +55,8 @@
|
|||||||
(when-some [r (sql/execute-one!
|
(when-some [r (sql/execute-one!
|
||||||
ds
|
ds
|
||||||
["select file from nodes where id = ?"
|
["select file from nodes where id = ?"
|
||||||
(elisp/print-elisp-string (:id node))])]
|
(elisp/print (:id node))])]
|
||||||
(-> r :nodes/file elisp/read-elisp-string)))))
|
(-> r :nodes/file elisp/read-string)))))
|
||||||
|
|
||||||
(defprotocol GetNode
|
(defprotocol GetNode
|
||||||
(get-node [this]
|
(get-node [this]
|
||||||
@@ -66,13 +66,18 @@
|
|||||||
String
|
String
|
||||||
(get-node [this]
|
(get-node [this]
|
||||||
(or (some-> this slug/from-string get-node)
|
(or (some-> this slug/from-string get-node)
|
||||||
(some-> this parse-uuid get-node)))
|
(some-> this parse-uuid get-node)
|
||||||
|
(throw (IllegalArgumentException.
|
||||||
|
"Give `get-node` a UUID or slug string plz. }:)"))))
|
||||||
java.util.UUID
|
java.util.UUID
|
||||||
(get-node [this]
|
(get-node [this]
|
||||||
(make-node this))
|
(make-node this))
|
||||||
net.deertopia.publisher.slug.Slug
|
net.deertopia.publisher.slug.Slug
|
||||||
(get-node [this]
|
(get-node [this]
|
||||||
(-> this slug/to-uuid make-node)))
|
(-> this slug/to-uuid make-node))
|
||||||
|
Node
|
||||||
|
(get-node [this]
|
||||||
|
this))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(def node (get-node "68XqhHerTWCbE--RYLEdHw"))
|
(def node (get-node "68XqhHerTWCbE--RYLEdHw"))
|
||||||
@@ -80,7 +85,7 @@
|
|||||||
node :title
|
node :title
|
||||||
#(do (println "fetch")
|
#(do (println "fetch")
|
||||||
(sql/execute-one! ds ["select title from nodes where id = ?"
|
(sql/execute-one! ds ["select title from nodes where id = ?"
|
||||||
(elisp/print-elisp-string (:id %))]))))
|
(elisp/print (:id %))]))))
|
||||||
|
|
||||||
|
|
||||||
;;; Node operations
|
;;; Node operations
|
||||||
@@ -103,7 +108,7 @@
|
|||||||
ds ["select file from nodes where id = ?"
|
ds ["select file from nodes where id = ?"
|
||||||
(print-id %)])
|
(print-id %)])
|
||||||
:nodes/file
|
:nodes/file
|
||||||
elisp/read-elisp-string)))
|
elisp/read-string)))
|
||||||
|
|
||||||
(defn properties [node]
|
(defn properties [node]
|
||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
@@ -129,17 +134,17 @@
|
|||||||
inner join nodes
|
inner join nodes
|
||||||
on nodes.id = links.source
|
on nodes.id = links.source
|
||||||
where links.dest = ?"
|
where links.dest = ?"
|
||||||
(elisp/print-elisp-string (:id node))])
|
(elisp/print (:id node))])
|
||||||
:let [id (elisp/read-elisp-string id)]
|
:let [id (elisp/read-string id)]
|
||||||
:when (graph-visible? (get-node (UUID/fromString id)))]
|
:when (graph-visible? (get-node (UUID/fromString id)))]
|
||||||
{:id id
|
{:id id
|
||||||
:title (elisp/read-elisp-string title)}))
|
:title (elisp/read-string title)}))
|
||||||
|
|
||||||
|
|
||||||
;;; Graph support
|
;;; Graph support
|
||||||
|
|
||||||
(defn- read-string-field [n field]
|
(defn- read-string-field [n field]
|
||||||
(-> n (get field) elisp/read-elisp-string))
|
(-> n (get field) elisp/read-string))
|
||||||
|
|
||||||
(defn- uuid-graph-visible? [uuid]
|
(defn- uuid-graph-visible? [uuid]
|
||||||
(-> uuid parse-uuid get-node graph-visible?))
|
(-> uuid parse-uuid get-node graph-visible?))
|
||||||
@@ -160,7 +165,7 @@
|
|||||||
:links (for [l links
|
:links (for [l links
|
||||||
:let [source (read-string-field l :nodes/source)
|
:let [source (read-string-field l :nodes/source)
|
||||||
target (read-string-field l :nodes/target)]
|
target (read-string-field l :nodes/target)]
|
||||||
:when (and (-> source uuid-graph-visible?)
|
:when (and (uuid-graph-visible? source)
|
||||||
(-> target uuid-graph-visible?))]
|
(uuid-graph-visible? target))]
|
||||||
{:source source
|
{:source source
|
||||||
:target target})}))
|
:target target})}))
|
||||||
|
|||||||
Reference in New Issue
Block a user