This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-06
Channels
- # adventofcode (24)
- # aleph (1)
- # bangalore-clj (2)
- # beginners (196)
- # boot (148)
- # cider (18)
- # clara (83)
- # cljsrn (24)
- # clojure (210)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-italy (11)
- # clojure-korea (8)
- # clojure-russia (82)
- # clojure-spec (115)
- # clojure-uk (130)
- # clojurescript (109)
- # core-async (7)
- # cryogen (1)
- # cursive (22)
- # datascript (11)
- # datomic (6)
- # devcards (2)
- # emacs (1)
- # garden (1)
- # hoplon (2)
- # incanter (1)
- # klipse (4)
- # luminus (4)
- # off-topic (89)
- # om (53)
- # onyx (78)
- # parinfer (9)
- # proton (3)
- # protorepl (20)
- # re-frame (107)
- # reagent (52)
- # rum (30)
- # spacemacs (1)
- # testing (3)
- # untangled (31)
- # vim (43)
- # yada (9)
Hey there I am having a little trouble with changing the name of a file. I have tried doing an io/copy and a str/replace but neither seem to work. I'm not sure what the best way to go about it is. I basically want to take a template.html
file and then change it to the path of a bidi route (eventually I will map the task over it..?). Anyways here is the current code.
(def next-route (path-for app/my-routes :community))
(defn render-template
[in-file out-file]
(doto out-file
io/make-parents
(spit (str/replace (slurp in-file) "{{CONTENT}}" "Happy times!"))))
(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]
(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)))
(-> fileset
(add-resource tmp)
commit!)))))
I did the io/copy at
(tmp-file (made-a-copy in one-being copied)
and I tried doing a string replace at out-path (replace-name in-path "/template.html" next-route)
@grounded_sage if I remember correctly there should be a move
in the sift
task
Unfortunately this hasn't seemed to have gotten me much further. I have attempted this
(defn change-name [path]
(sift path :move{#"template.html" next-route}))
But still don't seem to be getting anywhere. I'm completely lost as I there seems to be very little beginner friendly documentation around Regex's and classpath files.@grounded_sage sift
is a task so you'll need to use it in the boot pipeline, like this (sift :move{#"template.html" next-route})
(note there's no path
anymore)
@martinklepsch so is sift
something I use inside of the generate-page
task as I mentioned above? I currently have out-path (change-name in-path
inside the let
.
No you'd use them in the task pipeline like (comp (generate-page) (sift ...))
ok.. So essentially if I want to pick up the template.html
from resources
and map the bidi routes over it with the corresponding rum
rendering. I would do something like map the bidi route handlers over (comp (generate-page (sift ...)))
Sorry if that sounds confusing as I actually don't even know what I am saying xD
generate-page
returns a fileset with a file template.html
in it. sift
is a task that can modify the fileset. if you want template.html
to be copied to multiple places you can do something like (comp (generate-page) (sift :copy {"template.html" "somepath.html"}))
— except there is no :copy
option for the sift
task
He starts to wonder if it was worth building his own static site generator 😆
It seems like I would need to retain the original fileset
with template.html
. Then map over the bidi routes with the original fileset
(generate-page)
and (sift...)
commiting each change. Then deleting template.html
from the fileset
when it is all done so it doesn't end up in the target
folder.
ah yes, there is no option for that, but only files in :resource-paths
will end up in jars
so if you add the source files you want to have on the classpath at build time to :source-paths
they won't be in the jar
well, that’s strange. I’ve boot build
-ed sample project from https://github.com/adzerk-oss/boot-uberjar-example and got all sources in project.jar.
this document explains how it all works: https://github.com/boot-clj/boot/wiki/Filesets#definitions
ah, another question: what does exclude
do in uber
task? I tried to exclude sources with it.
the purpose of the uber task is simply to explode files from dependency jars and add them to the fileset
boot tasks are like unix processes, and the "stuff" that is piped from one to the next is the fileset
So I can write my own task, which modifies fileset
by removing unwanted files from it, and passes to next task.
@armed I think your looking for: https://github.com/boot-clj/boot/wiki/Filesets#edn
yeah i recommend looking at https://github.com/boot-clj/boot/blob/master/doc/boot.core.md for api functions that do what you want
How do I determine the roles that get applied to generated files in a tmp dir (tmp-dir!) when they are are added to the FS via add-resource
?
there is a matrix here: https://github.com/boot-clj/boot/wiki/Filesets#fileset-components
So given that they will have an output role as well, that will mean they will be emitted to the target dir?
if a task creates a file, it's safe to assume that the user wants to include it in the artifact
I was envisaging a "pipeline" of tasks where each sub-task applied a transformation as part of the bigger whole
i like having things decoupled because i don't like spending a lot of time on the build tooling
but I think the answer is that yes, if you add files to FS via add-resource
it will be going in the output
when you have a named place in the filesystem you introduce unmanaged shared global state
and most of the time when a task creates a file that task can't know if it is an intermediate ssource or a final artifact
so just having the default be to add thigns as resources seems at least consistent and easy to fix with sift later
It would be more like that the user would not be interested in the artifact of "task A", if they also ran "task B"