Skip to content

Instantly share code, notes, and snippets.

@edw
Created May 4, 2011 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edw/956113 to your computer and use it in GitHub Desktop.
Save edw/956113 to your computer and use it in GitHub Desktop.
SASS-like Thing in Scheme
;; Let's you do this:
;;
;; (make-css
;; '(("body.loading"
;; (font-size "12px")
;; (color "#fff")
;; (" ul#sidenav"
;; (" li"
;; (blah "blah"))))))
;;
;; Returned is a string that looks like this:
;;
;; body.loading { font-size: 12px; color: #fff; }
;; body.loading ul#sidenav li { blah: blah; }
(define (make-css els)
(let outer ((els els) (ctx "") (out ""))
(if (null? els) out
(let* ((el (car els))
(selector (car el)))
(let inner ((rules (cdr el)) (out out) (children-out ""))
(if (null? rules)
(if (zero? (string-length out))
children-out
(string-append ctx selector " { " out "}\n" children-out))
(let* ((rule (car rules)) (label (car rule)))
(if (string? label)
(inner (cdr rules)
out
(string-append children-out
(outer rules
(string-append ctx selector)
"")))
(let ((body (cdr rule)))
(inner (cdr rules)
(string-append out
(symbol->string label)
": "
(car body)
"; ")
children-out))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment