hodur-org / hodur-engine

Hodur is a domain modeling approach and collection of libraries to Clojure. By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API or use one of the many plugins to help you achieve mechanical results faster and in a purely functional manner.
MIT License
282 stars 13 forks source link

Fix `init-path` for ClojureScript #3

Open luchiniatwork opened 5 years ago

luchiniatwork commented 5 years ago

This will be particularly useful for plugins such as the Visualizer for now.

The trick might involve something along the lines of a macro somewhat like this:

(defmacro inline-resource [resource-path]
  (slurp (io/resource resource-path)))

Combined with ClojureScript's reader, i.e:

(cljs.reader/read-string
  (inline-all-edns "schemas/editorial.edn"))
pkpkpk commented 5 years ago

You can skip the read-string and inline the edn itself. You can change init-path to a macro

(defmacro init-path [path & others]
  (let [paths (-> others flatten (conj path) flatten)
        data (->> paths
                  schema-files
                  slurp-files
                  vec)]
   `(apply init-schema (quote ~data))))