noprompt / garden

Generate CSS with Clojure
1.34k stars 87 forks source link

Improve at-font-face #37

Open noprompt opened 10 years ago

noprompt commented 10 years ago

This seems like a start.

(defn at-font-face [& {:as kwargs}]
  (let [kwargs (->> (select-keys kwargs [:family :weight :style :eot :woff :svg])
                    (remove (comp nil? second))
                    (into {}))
        font-attrs (select-keys kwargs [:family :weight :style])
        srcs (select-keys kwargs [:eot :woff :svg])
        url (cssfn :url)
        format (cssfn :format)]
    ["@font-face"
     {:font font-attrs}
     (when-not (empty? srcs)
       {:src (for [[fmt uri] srcs]
               [(url uri) (format (name fmt))])})]))

(at-font-face
 :family "Family"
 :weight :normal
 :style :normal
 :eot "/path/to/eot")

Result

@font-face {
  font-style: normal;
  font-weight: normal;
  font-family: Family;
  src: url(/path/to/eot) format(eot);
}

Edit: Add url Edit: Add demonstration

naartjie commented 7 years ago

Does at-font-face work?

I'm trying to use it like so:

(css [(at-font-face :family "Family"
                    :weight :normal
                    :style :normal
                    :eot "/path/to/eot")])

It yields an empty string though.

perkola commented 7 years ago

Any progress on this? I see that at-font-face exists in the source, but I also get an empty string when using it. In src/garden/stylesheet.cljc:

(defn at-font-face
  "Create a CSS @font-face rule."
  [& font-properties]
  ["@font-face" font-properties])
WorldsEndless commented 2 years ago

This seems not to be implemented usefully (the implementation does not have any of the original definition from the first post)