Hi all,
Quick question about how to access resources from git deps downloaded via tools.deps. Specifically a dependency that is NOT a Clojure dependency.
I've got it working, I guess I just want a reality check on my method!
I want to be able to download this repo to make the vanilla SVG files contained therein available in my app: https://github.com/Templarian/MaterialDesign
So, step one, put it in deps.edn:
{:deps
{io.github.Templarian/MaterialDesign {:git/url ""
:git/sha "b734fae81135a7ace8b7708ba720fef90ecd1805"
:deps/manifest :deps}}}
Step two, use tools.gitlibs to get the path on disk of the file that I want to pull into my app. Let's say it's /svg/ab-testing.svg
(ns app.core
(:require
[clojure.tools.gitlibs :as gl]))
(as-> "" $
(gl/procure $ 'org.Templarian/MaterialDesign "b734fae81135a7ace8b7708ba720fef90ecd1805")
(fs/path $ "svg" "ab-testing.svg")
(str $)
(slurp $))
And I'm good. Right? Is there an easier or better way to do this?
This also seems like a nice, programmatic, tool-oriented way to install things like CSS sheets without having to link to them via CDN or copy/paste them into your web server's resources directory. Anybody had any experience with that?If it is on your classpath, just io/resource should be enough.
Also, -> is all you need in that threading pipeline (`as->` is intended for use inside ->).
What would be the recommended way to add it to the classpath? I could specify it manually with a string in deps.edn
{
:paths ["/Users/afry/.gitlibs/libs/io.github.TrioMRR/MaterialDesign/b734fae81135a7ace8b7708ba720fef90ecd1805/svg"]
}
But the home directory is going to be different in the deployment environment.
Maybe using pomegranate? https://github.com/clj-commons/pomegranate/tree/master? Or is there an easier way?I see you've also essentially asked this in #beginners and you're getting help there too. I hadn't looked at the repo earlier but now I see how it is structured, you can't easily get at the SVG files via the classpath. You could walk your classpath -- (System/getProperty "java.class.path") -- and find the io.github.TrioMRR/MaterialDesign entry and then use that to construct a path and then slurp it. You could also just slurp directly from GitHub:
(slurp "")
depending on exactly what you're trying to do and whether you need to fetch a lot of those icons...Thanks Sean! Between this thread and the thread over in #beginners I think I've got what I need. Basically I'm trying to consume that repo of SVGs as a library: 1. Install the library via deps.edn, much in the same way I'd install a Clojure dependency or library 2. When I need an icon, read the SVG from the disk, and write it into my HTML template as an inline SVG
Clever idea... Leveraging tools.deps / tools.gitlibs for non-Clojure resources... I'd never considered that before!
Very possible! Even easy once you get the pieces in place to read the contents of the dependencies you've downloaded. I've been working a lot with Clojure and HTMX while writing a server-rendered application. My start in the web-development world was writing SPAs in React. This is the first time I'm making a really "traditional" RESTful website, and it's kind of blowing my mind. It's helping me to see HTML as a data structure, one that can be read from disk, manipulated, parsed, split apart and put back together like any other. And hey, if it's data, why not download it like a dependency? Why can't I use the tool that I download my other dependencies to download this one?