Skip to content

Instantly share code, notes, and snippets.

@rodnaph
Forked from owainlewis/lcss.clj
Last active December 22, 2015 17:59
Show Gist options
  • Save rodnaph/6510339 to your computer and use it in GitHub Desktop.
Save rodnaph/6510339 to your computer and use it in GitHub Desktop.
(ns sexp-css.core)
(defn- wrap [forms] (str "{" forms "}"))
(defn map-to-form [m] (let [outer-forms (reduce (fn [out-vec [k v]] (conj out-vec (str (name k) " : " v))) [] m) inner-forms (->> outer-forms (interpose ";") (apply str))] (wrap inner-forms)))
(defmacro defrule [selector & forms] `(str ~selector (apply map-to-form (vector ~@forms))))
(defn px [n] (when (number? n) (str n "px")))
(defn mixin [rule & forms] (merge rule (into {} forms)))
(def my-mixin
{:height "20px"
:width "100px"})
(def sample
(defrule "h2"
(let [line-height 24
font-size 16]
(mixin
{:font-size (px (* font-size line-height))
:color "#FFF"} my-mixin))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment