This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-07
Channels
- # adventofcode (38)
- # aleph (1)
- # bangalore-clj (3)
- # beginners (126)
- # boot (165)
- # boulder-clojurians (5)
- # cider (42)
- # cljsrn (11)
- # clojure (203)
- # clojure-greece (6)
- # clojure-hk (1)
- # clojure-italy (11)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (112)
- # clojure-spec (86)
- # clojure-uk (176)
- # clojurescript (38)
- # code-reviews (2)
- # core-async (2)
- # cryogen (2)
- # cursive (16)
- # datascript (2)
- # datomic (80)
- # events (2)
- # garden (28)
- # hoplon (115)
- # jobs (1)
- # jobs-discuss (7)
- # klipse (50)
- # lein-figwheel (15)
- # liberator (17)
- # luminus (6)
- # off-topic (8)
- # om (31)
- # onyx (26)
- # parinfer (4)
- # planck (35)
- # protorepl (26)
- # quil (2)
- # re-frame (50)
- # reagent (21)
- # ring (5)
- # rum (2)
- # schema (1)
- # untangled (29)
- # vim (10)
- # yada (40)
How do I pass in an arguement to a task that operates on the fileset
?
(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!)))))
I want to call (generate-page :community)
@grounded_sage tasks have custom syntax for params, check https://github.com/boot-clj/boot/wiki/Task-Options-DSL and https://github.com/Lambda-X/boot-pack-source/blob/master/src/replumb/boot_pack_source.clj#L41
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
.
@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
I successfully implemented the task options btw. So thanks for that 🙂
oh cool now problem 😄
@tmtwd iirc yes
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
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")))
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.
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 😕
@tmtwd equivalent functionality is achieved by chaining together 3 tasks, pom
, jar
, and install
ie boot pom -p foo/bar -v 1.2.3-SNAPSHOT jar install
also, I see this in built_in.clj
: "Checkout dependencies task. DEPRECATED. (Use -c, --checkouts Boot option.)
oh yeah, it's not a task anymore, you access it now with flags to boot
ie boot -c foo/bar:1.2.3 ...
are you familiar with the checkouts concept?
that it requires 2 boots etc?
ok its a little different
first thing is, set up a boot watch pom -p foo/bar jar install
situation in the project you want to be the checkout
then in the project you want to use it from, do boot -c foo/bar ...
an even easier thing is, add the library's source-paths to your project's temporarily
@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.
i believe so
@grounded_sage np, perhaps can you gist the latest version of your task that doesnt' do what you want? i can look at it
I posted it above just a little earlier.
It's 16 messages up or so
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
i.e. n instances of the template, with some slightly different text inside?
Yes I would like to map some task that replaces text and the file name over all the routes of the site.
how would you like to store the information about the routes and the content that should be in the file at that route?
like, would you want that information in a file in the fileset too? or are ther not that many
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.
ok i think i'm tracking
If there was a way to sift :copy ...
I think that would solve the problem.
i was just thrown off a bit by :community
, is that analagous to /community
? not familiar with bidi
ah yes it is sorry.
(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)))))))
ok cool man
i will whip up a task for you here :knife: 🍅
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.
i will try to make something a little mor direct
i am personally perpetually confused by sift
Haha I hope I explained it alright. I'm pretty noobie with all of this and feel in way over my head haha.
jealous!
you can only learn clojure once
you're super close, this will be only slightly different than what yuo have
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 -
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
...
)@grounded_sage https://gist.github.com/alandipert/edab7814ec866ac8037ca790bb45bb55
i made a kinda generic string-template
which i specialize by wrapping with tasks
and i invented the route-content
function as a substitute for your rum render function
Thanks I will take a look at that now.
@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.
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.
Actually looks like I could just add another task options for head content and that would do that trick. THANKS HEAPS.
awesome, no prob
does it make more sense to you than the approach involving sift etc?
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.
i do:
(set-env!
:resource-paths #{"src"}
:dependencies '[[org.clojure/clojure "1.8.0"]
[tim/epsilon "1.1"]])
@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
@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.
(def routes #{:veganism :consulting :community :about-us})
(core/deftask build
"Does every last thing"
[]
(reduce comp (map #(make-page :route %) routes)))
should do itMan 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 🙂
@alandipert is that only 2.0?
hmm, not sure
i'm pretty sure the 2013 code is 1.0
yeah - 1.0 included, the first "cohort" in 2013
@alandipert that’s really cool! how 2 doit()?
I’m trying to get boot checkouts to work, does this project work as expected for other people? https://github.com/tmtwd/2modules
Hi, how do i pass in all the dependencies that i have in the current repl to a new pod
if i add some dependencies in the pod, does that mean that they will get added outside of pod?
with-invoke-in
is a lower-level interface, it lets you call functions and pass in java objects that are unprintable
most of the time you want to create a pod that has the dependencies from the core pod plus some extra ones
(def p
(make-pod
(update-in boot.pod/env [:dependencies] into '[[my/dep "1.2.3"] [other/dep "4.5.6"]])))
@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?
(with-eval-in mypod
(boot.pod/add-dependencies
(update-in boot.pod/env [:dependencies] ...
@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
but i assume that you can do (boot.pod/add-dependencies {:dependencies '[foo/bar "1.2.3"]})