Fork me on GitHub
#boot
<
2017-08-11
>
qqq00:08:05

I'm at at cider repl connected to a boot session.

qqq00:08:11

How do I hot inject the depencency of [hiccup "1.0.5"] ?

qqq03:08:12

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).

qqq03:08:38

@martinklepsch : ^^ 🙂 // please help with above boot-garden question

qqq03:08:45

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?

qqq04:08:32

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?

qqq05:08:22

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?

martinklepsch08:08:07

@qqq you probably want (spit out ...) so that the file is added to the tmp dir which you later add to the fileset

martinklepsch08:08:44

@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.

martinklepsch08:08:22

@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/)

qqq08:08:29

let me try this!

qqq08:08:09

@martinklepsch : are you still around? if so, could you explain to me why we have lines 39-54 ?

qqq08:08:34

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

qqq09:08:08

(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))


qqq09:08:23

this is what I haveso far, I get a complaint of being unable to find c/static/html.clj

lwhorton14:08:17

@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.

lwhorton14:08:03

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

lwhorton14:08:03

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

lwhorton14:08:06

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

qqq16:08:25

@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 ?

qqq16:08:20

(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 far

qqq16:08:33

one problem -- how do I 'resolve' hiccup-var (which is a symbol) to the actual variable that we want

qqq17:08:10

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))


qqq17:08:31

@lwhorton : 1. why do I want to use pods at all ?

pandeiro21:08:25

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

pandeiro21:08:01

Is there a fileset-clone type of function that I could reach for?

qqq22:08:49

(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