This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-11
Channels
- # architecture (11)
- # bangalore-clj (1)
- # beginners (42)
- # boot (28)
- # chestnut (1)
- # cider (1)
- # cljs-dev (28)
- # cljsrn (7)
- # clojure (124)
- # clojure-austin (1)
- # clojure-italy (10)
- # clojure-russia (3)
- # clojure-spec (29)
- # clojure-uk (32)
- # clojurescript (62)
- # core-async (22)
- # data-science (7)
- # datascript (5)
- # datomic (8)
- # events (1)
- # fulcro (15)
- # funcool (1)
- # jobs (1)
- # keechma (10)
- # lein-figwheel (4)
- # lumo (4)
- # mental-health (1)
- # off-topic (21)
- # om (10)
- # onyx (8)
- # parinfer (29)
- # pedestal (1)
- # planck (4)
- # portkey (2)
- # protorepl (1)
- # random (1)
- # re-frame (12)
- # ring (3)
- # spacemacs (6)
- # uncomplicate (63)
https://github.com/martinklepsch/boot-garden/blob/master/src/org/martinklepsch/boot_garden.clj#L39-L54 I'm trying to understand how boot-garden works. I don't get why we are eval-ing twice, and defining this 'cns (line 41).
@martinklepsch : ^^ 🙂 // please help with above boot-garden question
I have defined a boot task of my own. How do I run it directly from the repl? I have done
(deftask my-task .... )
now, I know how to chain it / composte it into the main tasks, but I want to run the task directly from a cider repl (for interactive development) -- is that possible?this is my first attempt at a non-trivial boot task, so please be patient (but also point out all mistakes); I'm trying to create a boot-html analogue to boot-garden; this is what I haveso far:
(deftask gen-html
[o output-to PATH str "output"
v hiccup-var SYM sym "hiccup-var"]
(let [output-path (or output-to "foobar.html")
hiccup-var hiccup-var
ns-sym (symbol (namespace hiccup-var))
tmp (boot.core/tmp-dir!)
out ( tmp output-path)
src-paths (vec (boot.core/get-env :source-paths))
ns-pod (boot.pod/make-pod (boot.core/get-env))]
(boot.core/with-pre-wrap fileset
(require '~ns-sym)
(spit output-path (hiccup.core/html ~hiccup-var))
(-> fileset (boot.core/add-resource tmp) boot.core/commit!))))
#_
(boot (gen-html :hiccup-var 'c.static.main/index))
unfortunately, this doesn't generate a foobar.html anywhere -- what am I doing wrong?https://github.com/boot-clj/boot/wiki/Pods <-- are existing source paths auto added to the default pods? if not, how do I add them?
@qqq you probably want (spit out ...)
so that the file is added to the tmp dir which you later add to the fileset
@qqq when you say eval-ing twice you mean line 41 / 44? in 41 we define the ns-tracker function, and in line 44 we obtain changed namespaces by calling the previously defined cns
function.
@qqq to test your task in the repl you can do something like:
(boot (gen-html :hiccup-var 'my.ns/hiccup) (target))
(target is used so you can see the result of the task in the filesystem, in other words: the fileset is written to target/
)@martinklepsch : are you still around? if so, could you explain to me why we have lines 39-54 ?
intuitively, we just need to call garden.core/css on the css-var, and dump it out -- but there's lots of other magic going on, and I'm not sure what they're needed for
(defn ns-tracker-pod []
(->> '[[ns-tracker "0.3.0"] [org.clojure/tools.namespace "0.2.11"]]
(assoc (boot/get-env) :dependencies)
pod/make-pod))
(deftask gen-html
[o output-to PATH str "output"
v hiccup-var SYM sym "hiccup-var"]
(let [output-path (or output-to "foobar.html")
hiccup-var hiccup-var
ns-sym (symbol (namespace hiccup-var))
_ (println ns-sym)
tmp (boot.core/tmp-dir!)
out ( tmp output-path)
src-paths (vec (boot.core/get-env :source-paths))
ns-pod (ns-tracker-pod) #_ (boot.pod/make-pod (boot.core/get-env))]
(boot.pod/with-eval-in ns-pod
(require 'ns-tracker.core)
(def cns (ns-tracker.core/ns-tracker ~src-paths)))
(boot.core/with-pre-wrap fileset
(boot.pod/with-eval-in ns-pod
(cns)
(require '~ns-sym)
(spit ~output-path (hiccup.core/html ~hiccup-var)))
(-> fileset (boot.core/add-resource tmp) boot.core/commit!))))
#_
(boot (gen-html :hiccup-var 'c.static.html/index) (target))
@qqq I would suggest first getting this to work without pods,and without any sort of caching. Then I would add the caching convention with fileset-diff
fileset query, then I would look into pods.
In reality all you want is 1) make a tmp dir 2) generate html from given hiccup 3) spit that html into a file that’s inside the path of the tmp dir 4) add the tmp dir as a resource to the fileset 5) commit the new fileset
remember that you cannot change project files, and anything inside the fileset is just a copy of your project files.you query those copies using the fileset api / filters, then you make changes / add / remove files (in the relative scope of a tmp dir), then sync those changes back to the fileset
most of the time you don’t need target, but rather what you might want is (show :fileset true)
(in a task) or show -f
(in a repl) to see the result of your task on the fileset
@lwhorton : I agree with you on all of these points. Is there sample code I can copy/paste? I did not start out trying to build the most complicated example -- boot-garden just happened to bethe "closest" to what I need (just change css generation to html generation). Is there a closer starting example ?
(deftask gen-html
[o output-to PATH str "output"
v hiccup-var SYM sym "hiccup-var"]
(let [output-path (or output-to "foobar.html")
hiccup-var hiccup-var
ns-sym (symbol (namespace hiccup-var))
_ (println ns-sym)
tmp (boot.core/tmp-dir!)
out ( tmp output-path)
src-paths (vec (boot.core/get-env :source-paths))
ns-pod (boot.pod/make-pod (boot.core/get-env))]
(boot.core/with-pre-wrap fileset
(require ns-sym)
(spit out (hiccup.core/html ~hiccup-var))
fileset)))
(boot (gen-html :hiccup-var 'c.static.html/index) (target))
okay, this is what I have so farone problem -- how do I 'resolve' hiccup-var (which is a symbol) to the actual variable that we want
okay, I have a small working example:
(deftask gen-html
[o output-to PATH str "output"
v hiccup-var SYM sym "hiccup-var"]
(let [output-path (or output-to "foobar.html")
hiccup-var hiccup-var
ns-sym (symbol (namespace hiccup-var))
_ (println ns-sym)
tmp (boot.core/tmp-dir!)
out ( tmp output-path)
src-paths (vec (boot.core/get-env :source-paths))
ns-pod (boot.pod/make-pod (boot.core/get-env))]
(boot.core/with-pre-wrap fileset
(require ns-sym)
(spit out (hiccup.core/html (var-get (ns-resolve ns-sym hiccup-var))))
(-> fileset (boot.core/add-resource tmp) boot.core/commit!))))
(boot (gen-html :hiccup-var 'c.static.html/index) (target))
I have a function that does a lot of stuff to a fileset; how can I get a diff of what was there before and what is there after? I've tried using fileset-diff
but obviously that doesn't work if I am effectively comparing the same fileset, since it's mutable
(deftask learning-dev []
(comp
(repl :port 3000)
(fn [next]
(fn [fileset]
(require 's.web)
(println (resolve 's.web/launch-dev))
(println (var-get (resolve 's.web/launch-dev)))
((var-get (resolve 's.web/launch-dev)))
(next fileset)))
(watch)
(fn [next]
(fn [fileset]
(require 's.web :reload)))))
I'm getting
"Attempting to call unbound launch-dev"
Yet I can run (launch-dev) fine from s.web