Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
Created December 13, 2016 21:18
Show Gist options
  • Save jebberjeb/a2ff384a02bee1289cc673f657c9a2a0 to your computer and use it in GitHub Desktop.
Save jebberjeb/a2ff384a02bee1289cc673f657c9a2a0 to your computer and use it in GitHub Desktop.
(ns user)
(require '[twou.centralpark.model.publish :as publish])
(require '[clojure.string :as string])
(require '[datomic.api :as d])
;; Get all attributes
(def all-attrs (d/q '[:find [?name ...]
:where [?eid :db/ident ?name]]
(dev/db)))
;; Returns false if not a domain attribute
(defn bad-prefix
[kw]
(let [bad-prefixes ["db" "tx"]]
((apply every-pred (map (fn [prefix] #(not (.startsWith (namespace %) prefix)))
bad-prefixes))
kw)))
;; Returns the Datomic reverse attribute
(defn to-reverse-attr
[kw]
(let [x (namespace kw)
y (name kw)]
(keyword x (str "_" y))))
;; Calculate all reverse attributes, filter out non-domain attributes
(def filtered-attrs
(->> (d/q '[:find [?name ...]
:where
[?eid :db/ident ?name]
[?eid :db/cardinality ?cardinality]
[?cardinality :db/ident :db.cardinality/many]]
(dev/db))
(filter bad-prefix)
(map to-reverse-attr)
(concat (filter bad-prefix all-attrs))))
(map #(.getCanonicalPath %) (.listFiles (java.io.File. (System/getProperty "user.home"))))
;; The files we care about
(def files (mapv #(str "/home/jeb/source/centralpark/src/twou/centralpark/client/" %)
["client_state.cljc"
"command_client.cljc"
"dev.cljs"
"diagram_query.cljc"
"diagram_ui.cljs"
"event.cljs"
"event_query.cljc"
"exec.cljs"
"home_query.cljc"
"home_ui.cljs"
"main.cljs"
"normalize.cljc"
"overdue_query.cljc"
"overdue_ui.cljs"
"param_query.cljc"
"param_ui.cljs"
"task_list_query.cljc"
"task_list_ui.cljs"
"task_query.cljc"
"task_ui.cljs"
"ui.cljs"
"ui_query.cljc"]))
;; Synthesized attributes
(def synth-attrs {:form-url :centralpark.taskexec/form-url
:param-value :centralpark.taskexec/param-value
:depends-on :centralpark.taskexec/depends-on
:depended-on-by :centralpark.taskexec/depended-on-by})
;; Externalize a keyword
(defn externalize*
[kw]
(get synth-attrs kw (publish/externalize-key kw)))
;; Externalize all keywords in a string
(defn replace-kw
[s]
(reduce (fn [s attr]
(string/replace s (str attr) (str (externalize* attr))))
s
(concat filtered-attrs
(keys synth-attrs))))
;; Update all files w/ externalized keywords
(defn replace-file
[filename]
(spit filename (replace-kw (slurp filename))))
(comment (doall (map replace-file files)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment