-
-
Save rodnaph/6510339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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