Use strings instead of keywords

This commit is contained in:
Marcus Kammer 2023-07-23 17:55:37 +02:00
parent 4e4671234a
commit 1ecdcc8394
Signed by: marcuskammer
GPG key ID: C374817BE285268F
2 changed files with 20 additions and 20 deletions

View file

@ -53,39 +53,39 @@
(in-package :cl-sbt/utility)
(defparameter *colors* '(:primary :secondary :success :danger :warning :info :light :dark :body :muted :white :transparent))
(defparameter *colors* '("primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "body" "muted" "white" "transparent"))
(defun string-clean (str)
(string-trim " " (string-downcase str)))
(defun background (&key (color :primary) (gradient nil))
(defun background (&key (color "primary") (gradient nil))
"Generates a Bootstrap background class.
COLOR: Specifies the color, should be :primary, :secondary, :success,
:danger, :warning, :info, :light, :dark, :body, :muted, :white, :transparent,
COLOR: Specifies the color, should be 'primary', 'secondary', 'success',
'danger', 'warning', 'info', 'light', 'dark', 'body', 'muted', 'white', 'transparent',
or nil (default color).
GRADIENT: Specifies if the background should have a gradient, should be :t or
:nil. If :t, it will add a 'bg-gradient' to the class string.
GRADIENT: Specifies if the background should have a gradient, should be t or
nil. If t, it will add a 'bg-gradient' to the class string.
Example 1:
(background :color :primary)
(background :color \"primary\")
; This will generate a string 'bg-primary'
Example 2:
(background :color :danger :gradient :t)
(background :color \"danger\" :gradient t)
; This will generate a string 'bg-danger bg-gradient'
Example 3:
(background :color :light)
(background :color \"light\")
; This will generate a string 'bg-light'
Example 4:
(background :color :dark :gradient :t)
(background :color \"dark\" :gradient t)
; This will generate a string 'bg-dark bg-gradient'"
(assert (member color *colors*) nil "Color can't be nil")
(assert (member color *colors* :test #'string=) nil "Color can't be nil")
(let ((color-str (format nil "bg-~a" color))
(gradient-str (if (eq gradient :t) " bg-gradient" "")))
(gradient-str (if (null gradient) "" " bg-gradient")))
(string-clean (concatenate 'string color-str gradient-str))))
(defun color (&key (text nil) (background nil) (emphasis nil) (body nil))

View file

@ -18,17 +18,17 @@
(deftest test-background-color
(testing "Generates correct background class with color"
(ok (string= (background :color :primary) "bg-primary"))
(ok (string= (background :color :danger) "bg-danger"))
(ok (string= (background :color :light) "bg-light"))
(ok (string= (background :color :dark) "bg-dark"))))
(ok (string= (background :color "primary") "bg-primary"))
(ok (string= (background :color "danger") "bg-danger"))
(ok (string= (background :color "light") "bg-light"))
(ok (string= (background :color "dark") "bg-dark"))))
(deftest test-background-gradient
(testing "Generates correct background class with gradient"
(ok (string= (background :color :primary :gradient :t) "bg-primary bg-gradient"))
(ok (string= (background :color :danger :gradient :t) "bg-danger bg-gradient"))
(ok (string= (background :color :light :gradient :t) "bg-light bg-gradient"))
(ok (string= (background :color :dark :gradient :t) "bg-dark bg-gradient"))))
(ok (string= (background :color "primary" :gradient t) "bg-primary bg-gradient"))
(ok (string= (background :color "danger" :gradient t) "bg-danger bg-gradient"))
(ok (string= (background :color "light" :gradient t) "bg-light bg-gradient"))
(ok (string= (background :color "dark" :gradient t) "bg-dark bg-gradient"))))
(deftest test-background-no-arguments
(testing "Generates correct background class with no arguments"