From 5734c6690b7506708558da5d849154153a1fe910 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 14 Sep 2018 15:10:36 -0700 Subject: [PATCH] improve css string joins --- core.rkt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core.rkt b/core.rkt index 7c216f7..41089e4 100644 --- a/core.rkt +++ b/core.rkt @@ -4,12 +4,17 @@ (provide (all-defined-out)) -(define (join-css-strings properties) - (define line-ending ";\n") - (define out-string (string-join properties line-ending)) - (if (out-string . ends-with? . line-ending) ; might already have the line ending, so don't duplicate it - out-string - (string-append out-string line-ending))) +(define (join-css-strings prop-strs) + (define prop-terminator ";") + (define newline "\n") + (define full-terminator (string-append prop-terminator newline)) + (string-join + (for/list ([prop-str (in-list prop-strs)]) + (string-append prop-str + (cond + [(prop-str . ends-with? . full-terminator) ""] + [(prop-str . ends-with? . prop-terminator) newline] + [else full-terminator]))) "")) (define (make-css-string p v) (format "~a: ~a;" p v))