Fork me on GitHub
#boot
<
2016-12-07
>
grounded_sage00:12:13

How do I pass in an arguement to a task that operates on the fileset?

grounded_sage00:12:00

(deftask generate-page []
  (let [tmp (tmp-dir!)]
    (with-pre-wrap [fileset]
      (empty-dir! tmp)
      (let [in-files (input-files fileset)
            template (by-name ["template.html"] in-files)]
        (doseq [in template
                route route]
          (let [in-file (tmp-file in)
                in-path (tmp-path in)
                out-path in-path
                out-file (io/file tmp out-path)
                route route]
            (render-template in-file out-file route)))
        (-> fileset
            (add-resource tmp)
            commit!)))))

grounded_sage00:12:55

I want to call (generate-page :community)

grounded_sage00:12:34

Ah yes I see task options. Thank you. Whilst I have some attention is there an example of how I can pass an old fileset onwards or retrieve it anywhere. I am currently changing the filename as I generate .html files based on routes. So I am looking to continually reuse the template.html from the original fileset.

richiardiandrea01:12:47

@grounded_sage if you check boot-reload it should be clear how to retrieve things from the fileset (check boot_reload.clj) and how to diff them

grounded_sage01:12:26

I successfully implemented the task options btw. So thanks for that πŸ™‚

richiardiandrea01:12:52

oh cool now problem πŸ˜„

tmtwd01:12:31

is each task implicitly passed a fileset, even if not using with-pre-wrap?

tmtwd01:12:16

ok, that makes sense

richiardiandrea01:12:04

Actually it is not that implicit, even if you use the macro you will see it, the macro avoids you to call the next handler manually

grounded_sage03:12:45

So it seems the best way is to use an atom from my understanding. This is my current code where I am getting an error java.util.concurrent.Future .

(deftask generate-page
  "Takes a page route as a keyword."
  [r route VALUE kw "The route in the form of a keyword"
   o template VALUE code "An atom containing the original template"]
  (let [tmp (tmp-dir!)]
    (with-pre-wrap [fileset]
      (empty-dir! tmp)
      (let [in-files (input-files fileset) ;; Currently ignored
            template-old (by-name ["template.html"] in-files) ;;Currently ignored
            template-new @template]
        (doseq [in template-new]
          (let [in-file (tmp-file in)
                in-path (tmp-path in)
                out-path in-path
                out-file (io/file tmp out-path)]
            (render-template in-file out-file route)))
        (-> fileset
            (add-resource tmp)
            commit!)))))

(deftask get-template
  "Extracts the template.html from the fileset and places it inside an atom"
  []
  (with-pre-wrap [fileset]
    (let [in-files (input-files fileset)
          template (by-name ["template.html"] in-files)
          original-template (atom template)]
      original-template)))

(deftask build []
  (comp (speak)
        (cljs)

        (let [original-template (get-template)]
          (generate-page :route :community
                         :template original-template))

        ;(sift :move{#"template.html" "community.html"})
        (garden :styles-var 'vbn.styles/screen :output-to "css/garden.css")))

grounded_sage03:12:39

I'm using the get-template to extract the original template.html and attaching it to an atom. Then using a let binding inside the build task as I pass it into the generate-page. Seems all find until I want to deref the atom.

grounded_sage03:12:53

I also tried calling the next-handler inside get-template like (next-handler fileset :template original-template) but it kept saying I was passing too many arguments. I'm still new to handlers πŸ˜•

tmtwd05:12:31

is there an equivalent to lein install that installs a jar into .m2?

alandipert05:12:21

@tmtwd equivalent functionality is achieved by chaining together 3 tasks, pom, jar, and install

tmtwd05:12:53

ok thanks

alandipert05:12:11

ie boot pom -p foo/bar -v 1.2.3-SNAPSHOT jar install

tmtwd05:12:46

excellent

tmtwd05:12:49

thank you

tmtwd05:12:20

also, I see this in built_in.clj: "Checkout dependencies task. DEPRECATED. (Use -c, --checkouts Boot option.)

tmtwd05:12:29

but I don't see a checkouts task

alandipert05:12:54

oh yeah, it's not a task anymore, you access it now with flags to boot

alandipert05:12:12

ie boot -c foo/bar:1.2.3 ...

alandipert05:12:31

are you familiar with the checkouts concept?

alandipert05:12:36

that it requires 2 boots etc?

tmtwd05:12:38

from lein yes

tmtwd05:12:41

not from boot

alandipert05:12:46

ok its a little different

tmtwd05:12:59

do they have similar purposes?

alandipert05:12:02

first thing is, set up a boot watch pom -p foo/bar jar install situation in the project you want to be the checkout

alandipert05:12:57

then in the project you want to use it from, do boot -c foo/bar ...

alandipert05:12:14

an even easier thing is, add the library's source-paths to your project's temporarily

grounded_sage05:12:32

@alandipert sorry to bother you. Is there a way to hold onto a fileset going into the next fileset. I'm trying to generate multiple html files off a single template without much success.

tmtwd05:12:36

can I do boot -c foo/bar repl?

alandipert05:12:04

i believe so

alandipert05:12:29

@grounded_sage np, perhaps can you gist the latest version of your task that doesnt' do what you want? i can look at it

grounded_sage05:12:21

I posted it above just a little earlier.

grounded_sage05:12:10

It's 16 messages up or so

alandipert05:12:06

can you give me a brief refresher on generally what yuo want to do? iirc you have a template.html file that yuo want to be parametrically exploded into n other .html files

alandipert05:12:35

i.e. n instances of the template, with some slightly different text inside?

grounded_sage05:12:59

Yes I would like to map some task that replaces text and the file name over all the routes of the site.

alandipert05:12:01

how would you like to store the information about the routes and the content that should be in the file at that route?

alandipert05:12:35

like, would you want that information in a file in the fileset too? or are ther not that many

grounded_sage05:12:41

Well they are bidi routes and I am rendering the site with rum serverside. Not quite sure what you mean with putting that information in a file in the fileset. I think the best way to do it is to have a reference to the template which I can do the string replace on for content and the sift :move .. to change the file name then put it in the fileset and repeat.

alandipert06:12:18

ok i think i'm tracking

grounded_sage06:12:21

If there was a way to sift :copy ... I think that would solve the problem.

alandipert06:12:37

i was just thrown off a bit by :community, is that analagous to /community? not familiar with bidi

grounded_sage06:12:59

ah yes it is sorry.

grounded_sage06:12:10

(defn render-template
  [in-file out-file route]
  (doto out-file
    io/make-parents
    (spit (str/replace (slurp in-file) "{{CONTENT}}"
                       (case route
                         :veganism   (rum/render-static-markup (app/veganism))
                         :consulting (rum/render-static-markup (app/consulting))
                         :community  (rum/render-static-markup (app/community))
                         :about-us   (rum/render-static-markup (app/about-us)))))))

alandipert06:12:55

i will whip up a task for you here :knife: πŸ… pizzaspin

grounded_sage06:12:56

awesome haha. The only other solution I was thinking would be to pull in the file in a separate folder during each iteration of the task. But having the sift copy should solve it easy.

alandipert06:12:17

i will try to make something a little mor direct

alandipert06:12:31

i am personally perpetually confused by sift

grounded_sage06:12:09

Haha I hope I explained it alright. I'm pretty noobie with all of this and feel in way over my head haha.

alandipert06:12:36

you can only learn clojure once

alandipert06:12:56

you're super close, this will be only slightly different than what yuo have

tmtwd06:12:43

I do this:

$ boot --checkouts tim/epsilon  repl
Adding checkout dependency tim/epsilon...
nREPL server started on port 55888 on host 127.0.0.1 - 

tmtwd06:12:59

and this in another pane: $ boot watch pom -p tim/epsilon -v 1.1 jar install

tmtwd06:12:04

the jar updates (ie

Writing pom.xml and pom.properties...
Writing epsilon.jar...
Installing epsilon.jar...
Elapsed time: 0.029 sec

Writing pom.xml and pom.properties...
Writing epsilon.jar...
Installing epsilon.jar...
Elapsed time: 0.027 sec

...
)

tmtwd06:12:15

but I have to restart $ boot --checkouts tim/epsilon repl to access the changes

alandipert06:12:06

i made a kinda generic string-template which i specialize by wrapping with tasks

alandipert06:12:52

and i invented the route-content function as a substitute for your rum render function

grounded_sage06:12:06

Thanks I will take a look at that now.

grounded_sage06:12:21

@alandipert this is the full project btw. https://github.com/CommonCreative/vbn-redesign . Basically building a static site generator that turns into a web app client side.

grounded_sage06:12:17

Just reading the Gist now. I'm guessing the placeholder only works for one placeholder? And same for content. My thoughts are at some point I will be changing the <link>'s in the head as different pages would be requiring different css and js etc.

tmtwd06:12:58

also tried this : boot -c tim/epsilon:1.1 repl

tmtwd06:12:04

doesn’t seem to work either

grounded_sage06:12:36

Actually looks like I could just add another task options for head content and that would do that trick. THANKS HEAPS.

alandipert06:12:29

awesome, no prob

alandipert06:12:55

does it make more sense to you than the approach involving sift etc?

grounded_sage07:12:31

Yes though I will probs have to read it several times to grok it. The things that jump out are the first inside the if-let of string-template and the java.util.regex.Pattern/quote. Not quite sure what they are doing but everything else makes perfect sense. Just about to run a build to test it out actually.

micha07:12:52

@tmtwd you need to have tim/epsilon as a dependency, as well

tmtwd07:12:12

i do:

(set-env!
 :resource-paths #{"src"}
 :dependencies '[[org.clojure/clojure "1.8.0"]
                 [tim/epsilon "1.1"]])

tmtwd07:12:29

the dependency works fine statically

tmtwd07:12:36

just won’t reload when using checkouts

alandipert07:12:28

@grounded_sage the first is necessary because the by-name function can return a seq... we only want 1st "result". the quote business is because i'm using java.util.String's replaceAll method, which takes a regex as an arg. and the {{}} chars have special regex meaning, so i quote them out using that method

micha07:12:52

@tmtwd which version of boot?

tmtwd07:12:10

BOOT_VERSION=2.6.0

grounded_sage07:12:59

@alandipert thanks for the explanation. Everything works fine except now I am trying to map over all the routes πŸ˜› I'm sure I will figure that one out with some poking at it.

alandipert07:12:17

(def routes #{:veganism :consulting :community :about-us})

(core/deftask build
  "Does every last thing"
  []
  (reduce comp (map #(make-page :route %) routes)))
should do it

micha07:12:20

@tmtwd i can't reproduce this

micha07:12:10

checkouts seem to be working for me

tmtwd08:12:53

hm, ok, thanks. will try this on a different computer, I suppose.

grounded_sage09:12:24

Man thanks so much aye. Legit has been the biggest issue I have had was rendering the pages. I just actually read the values you attached to the keys. Good laugh πŸ™‚

martinklepsch16:12:10

@alandipert is that only 2.0?

alandipert16:12:00

hmm, not sure

alandipert16:12:35

i'm pretty sure the 2013 code is 1.0

alandipert16:12:41

yeah - 1.0 included, the first "cohort" in 2013

dave16:12:46

@alandipert that’s really cool! how 2 doit()?

micha16:12:53

lol up and to the right

tmtwd17:12:21

I’m trying to get boot checkouts to work, does this project work as expected for other people? https://github.com/tmtwd/2modules

nux19:12:48

Hi, how do i pass in all the dependencies that i have in the current repl to a new pod

micha19:12:40

you can do that two different ways

micha19:12:54

the first and best way is to create a pod with those dependencies, like this:

micha19:12:19

(def p (boot.pod/make-pod boot.pod/env))

micha19:12:37

the second way is if you must add dependencies to a pod that already exists

micha19:12:42

in which case you can do this

micha19:12:22

ah right, that's because the boot.core namespace is only available in the core pod

micha19:12:30

this is because it's stateful and must be a singleton

micha19:12:49

however, you can do what you want, just in a different way

nux19:12:13

@micha how do i do that

micha19:12:21

first, with-invoke-in is probably not what you want, you want with-eval-in

micha19:12:23

like this:

micha19:12:37

(with-eval-in mypod boot.pod/env)

micha19:12:49

the boot.pod namespace is available in any pod

micha19:12:08

and the boot.pod/env var contains the same info as (get-env) does

nux19:12:50

if i add some dependencies in the pod, does that mean that they will get added outside of pod?

micha19:12:53

with-invoke-in is a lower-level interface, it lets you call functions and pass in java objects that are unprintable

micha19:12:03

no, pods are isolated from each other

micha19:12:13

so adding dependencies to one pod doesn't affect any other pod

micha19:12:21

that's the main idea of pods basically

micha19:12:03

most of the time you want to create a pod that has the dependencies from the core pod plus some extra ones

micha19:12:08

you'd do that like this:

micha19:12:18

(def p
  (make-pod
    (update-in boot.pod/env [:dependencies] into '[[my/dep "1.2.3"] [other/dep "4.5.6"]])))

nux19:12:51

@micha thanks, let me try πŸ™‚

micha19:12:39

say hello to larry and barry for me @nux πŸ™‚

micha19:12:52

> Nux: [overjoyed] I've got a boot! > -- fury road script

nux20:12:08

@micha i did not get the reference 😞

micha20:12:27

oh sorry, Nux is a character in the Mad Max Fury Road movie

micha20:12:36

he steals mad max's boot

nux20:12:54

@micha i watched mad max, old and new ones, but did not realize πŸ˜„

nux20:12:19

@micha if the pod is already created and i do update-in inside the pod to set more dependencies, will boot retrieve them and add them in class path?

micha20:12:43

no, you will need to use boot.pod/add-dependencies

micha20:12:26

yeah that won't work

micha20:12:58

you want to do like

micha20:12:32

(with-eval-in mypod
  (boot.pod/add-dependencies
    (update-in boot.pod/env [:dependencies] ...

micha20:12:51

but it's better not to dynamically add dependencies in pods

micha20:12:55

just make a new pod

nux20:12:57

@micha ok, let me try this and see if i can move it to the beginning

nux20:12:49

@micha i was thinking, if i could run gorilla-repl with boot, it would be awesome if we can pull in dependencies right in the gorilla repl , it would help me a lot to learn the language

micha20:12:05

ah yeah you can do it, sure

micha20:12:14

that's what happens in the core repl

micha20:12:28

it's just better to do all the dependency resolution at once if you can

micha20:12:35

but of course that doesn't make sense in a repl

micha20:12:10

i'm not so familiar with gorilla repl

micha20:12:41

but i assume that you can do (boot.pod/add-dependencies {:dependencies '[foo/bar "1.2.3"]})

micha20:12:35

in the repl

nux20:12:51

@micha i don't have to do (update-in boot.pod/env) when using add-dependencies ?

micha20:12:08

actually yeah you want to do that

micha20:12:24

becaus ethe env also contains important configuration like repository settings, things like that

nux20:12:28

ok, i just tried your previous snippet, with update-in and it worked

micha20:12:41

so if you're the user and you have a repl open

micha20:12:51

and you, as the user, want to add a new dependency on the fly

micha20:12:55

you would do this:

nux20:12:56

so add-dependencies 'replaces' instead of merging ?

micha20:12:23

(add-dependencies (assoc boot.pod/env :dependencies '[[foo/bar "1.2.3"]]))

micha20:12:43

no, there is no way to remove classes from the classpath once you load them

micha20:12:52

so it's always additive

micha20:12:03

that's why i did assoc there

nux20:12:07

@micha cool thank you

nux21:12:13

@micha this works good, i can add dependencies from the gorilla repl without restarting πŸ™‚ thank you so much again.. this is really great.. i will start on my clojure adventure now