garden

2016-08-24T02:22:41.000016Z

hello folks

2016-08-24T02:23:02.000017Z

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

2016-08-24T02:23:50.000018Z

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

2016-08-24T02:24:50.000019Z

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");
;; }

2016-08-24T02:27:03.000021Z

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

niamu 2016-08-24T02:47:28.000022Z

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.

niamu 2016-08-24T02:49:16.000023Z

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.

niamu 2016-08-24T02:49:44.000024Z

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

2016-08-24T02:50:00.000025Z

np, your comments are good

niamu 2016-08-24T02:52:03.000026Z

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.

niamu 2016-08-24T02:52:58.000027Z

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

niamu 2016-08-24T02:53:02.000028Z

Something like that.

2016-08-24T02:53:15.000029Z

right … will do that

2016-08-24T02:53:40.000030Z

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

niamu 2016-08-24T02:56:31.000031Z

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

2016-08-24T02:57:05.000033Z

thanks heaps - maybe add these to the garden documentation?

niamu 2016-08-24T02:59:03.000034Z

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.

2016-08-24T02:59:47.000035Z

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

2016-08-24T03:03:24.000038Z

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

niamu 2016-08-24T03:34:21.000039Z

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