Fork me on GitHub
#garden
<
2016-08-24
>
michael.heuberger02:08:02

has anyone a good example to demonstrate how useful defcssfn is?

michael.heuberger02:08:50

trying to make use of it in conjunction of @font-face, building the :src attribute, containing urls

michael.heuberger02:08:50

at the moment have something like this

(defn font-url
  [family weight type]
  (let [file-name (str weight "." type)
        url       (wrap-quotes (str "/fonts/" family "/" file-name))
        type      (wrap-quotes type)]
    (str "url(" url ") format(" type ")")))

(defn font-face
  [family weight weight-n]
  (let [woff2 (font-url family weight "woff2")
        woff  (font-url family weight "woff")]
    (at-font-face {:font-family (string/capitalize family)
                   :font-weight weight-n
                   :src         (comma-join [woff2 woff])})))

;; usage: 
;; let [light-font-face  (font-face "roboto" "light" 300)]
;; produces
;; @font-face {
;;   font-family: Roboto;
;;   font-weight: 300;
;;   src: url("/fonts/roboto/light.woff2") format("woff2"), url("/fonts/roboto/light.woff") format("woff");
;; }

michael.heuberger02:08:03

but i think this can be tidier and better. mabye with defcssfn? cc @niamu

niamu02:08:28

I haven’t used defcssfn before. I’m also in the habit of base64 encoding all my fonts and embedding them directly into the CSS file, so I generate some very different looking code than what you have typically.

niamu02:08:16

I like what you have so far though. There is definitely a point that you can reach where writing macros only hinders others from seeing what is going on. Expressive code (even if it takes up a few more lines) is usually my preference. Easier to maintain as well.

niamu02:08:44

Sorry that doesn’t really answer your question...

michael.heuberger02:08:00

np, your comments are good

niamu02:08:03

You might consider producing a map of the weights using the string as a key and the corresponding number as the value. That would eliminate the need for one argument in your font-face function and will likely work well for most fonts.

niamu02:08:58

(def weight
  {“light” 300
   “bold” 600})

niamu02:08:02

Something like that.

michael.heuberger02:08:15

right … will do that

michael.heuberger02:08:40

and regarding defcssfn, is there a good example that demonstrates its usefulness?

niamu02:08:31

This is just the first one that I came across, but it seems to demonstrate a few different cases for it: https://github.com/linuccio/site/blob/c174d5d13d4bd3118f11a7e967ac9c38a626c55f/src/site/core/stylesheet/prefix.clj

michael.heuberger02:08:05

thanks heaps - maybe add these to the garden documentation?

niamu02:08:03

maybe. Not really sure where the maintainer would like to draw the line with documentation and examples. I could see the argument being made that garden is already well documented and it seems that defcssfn has some decent documentation already and even a sample use case.

michael.heuberger02:08:47

hmmm, garden already documents defcssfn well? can you link me?

michael.heuberger03:08:24

i think i read them before but somehow it didn’t make “click” in my head ...

niamu03:08:21

Yeah, a lot of things don’t click for me until I’ve used it or seen many more examples for myself. 🙂