Fix naming of arguments to better fit their meaning
This commit is contained in:
parent
f4ed6a4456
commit
a2e65b7767
5 changed files with 50 additions and 47 deletions
|
@ -57,49 +57,52 @@
|
|||
:data-bs-dismiss "alert"
|
||||
:aria-label "Close")))
|
||||
|
||||
(defmacro alert ((&key (type "primary") (dismissible nil)) &body body)
|
||||
(defmacro alert ((&key (color "primary") (dismissible nil)) &body body)
|
||||
"This macro generates a Bootstrap alert component.
|
||||
|
||||
TYPE: Specifies the alert type. Can be 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', or 'dark'. Defaults to 'primary'.
|
||||
COLOR: Specifies the alert type. Can be 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', or 'dark'. Defaults to 'primary'.
|
||||
|
||||
DISMISSIBLE: Specifies whether the alert is dismissible. If true, the alert includes a close button.
|
||||
|
||||
BODY: Specifies the content of the alert.
|
||||
|
||||
Example usage:
|
||||
To create a basic alert of type 'danger':
|
||||
(alert (:type \"danger\") \"This is a dangerous alert. Be careful!\")
|
||||
(alert (:role \"danger\") \"This is a dangerous alert. Be careful!\")
|
||||
|
||||
To create a dismissible alert of type 'success':
|
||||
(alert (:type \"success\" :dismissible t) \"Congratulations! You've successfully created a dismissible alert.\")"
|
||||
`(spinneret:with-html
|
||||
(:div :role "alert"
|
||||
:class ,(concatenate 'string (format nil "alert alert-~a" type)
|
||||
:class ,(concatenate 'string (format nil "alert alert-~a" color)
|
||||
(if (null dismissible) nil " alert-dismissible"))
|
||||
,(if (null dismissible) nil `(btn))
|
||||
,@body)))
|
||||
|
||||
(defmacro define-alert (type &optional (dismissible nil))
|
||||
(defmacro define-alert (color &optional (dismissible nil))
|
||||
"This macro defines a new macro for creating a Bootstrap alert of a specific type.
|
||||
|
||||
TYPE: The type of the alert (like 'primary', 'secondary', 'success', etc.).
|
||||
COLOR: The color of the alert (like 'primary', 'secondary', 'success', etc.).
|
||||
|
||||
DISMISSIBLE: (optional) Whether the alert should be dismissible.
|
||||
|
||||
The newly defined macro, when called, will generate HTML for a Bootstrap
|
||||
alert of the specified type and dismissibility."
|
||||
(let* ((macro-name (intern (string-upcase (concatenate 'string "ALERT-" (if (null dismissible) "" "DISMISS-") type)))))
|
||||
(let* ((macro-name (intern (string-upcase (concatenate 'string "ALERT-" (if (null dismissible) "" "DISMISS-") color)))))
|
||||
`(defmacro ,macro-name (&body body)
|
||||
`(alert (:type ,,type :dismissible ,,dismissible) ,@body))))
|
||||
`(alert (:color ,,color :dismissible ,,dismissible) ,@body))))
|
||||
|
||||
(defmacro define-alerts (names)
|
||||
(defmacro define-alerts (colors)
|
||||
"This macro generates specific alert macros based on the provided names.
|
||||
|
||||
NAMES: A list of alert type names. For each name in this list, a macro will
|
||||
COLORS: A list of alert type names. For each name in this list, a macro will
|
||||
be generated: a non-dismissible alert and a dismissible alert of the
|
||||
specified type."
|
||||
`(progn
|
||||
,@(loop for item in names
|
||||
for type-name = (string-downcase (string item))
|
||||
,@(loop for color in colors
|
||||
for color-name = (string-downcase (string color))
|
||||
collect `(progn
|
||||
(define-alert ,type-name)
|
||||
(define-alert ,type-name t)))))
|
||||
(define-alert ,color-name)
|
||||
(define-alert ,color-name t)))))
|
||||
|
||||
(define-alerts (primary secondary success danger warning info light dark))
|
||||
|
|
|
@ -54,44 +54,44 @@
|
|||
|
||||
(in-package :cl-sbt/badge)
|
||||
|
||||
(defmacro badge ((&key (role "primary") (pill nil)) &body body)
|
||||
(defmacro badge ((&key (color "primary") (pill nil)) &body body)
|
||||
"This macro generates a Bootstrap badge.
|
||||
|
||||
ROLE: (optional) The type of the badge (like 'primary', 'secondary', 'success', etc.). Defaults to 'primary'.
|
||||
COLOR: (optional) The type of the badge (like 'primary', 'secondary', 'success', etc.). Defaults to 'primary'.
|
||||
|
||||
BODY: The contents of the badge.
|
||||
|
||||
Example:
|
||||
(badge (:role \"success\" :pill t) \"New\")"
|
||||
(badge (:color \"success\" :pill t) \"New\")"
|
||||
`(spinneret:with-html
|
||||
(:span :class ,(concatenate 'string
|
||||
(format nil "badge text-bg-~a" role)
|
||||
(format nil "badge text-bg-~a" color)
|
||||
(if (null pill) "" " rounded-pill"))
|
||||
,@body)))
|
||||
|
||||
(defmacro define-badge (role &optional (pill nil))
|
||||
(defmacro define-badge (color &optional (pill nil))
|
||||
"This macro defines a new macro for creating a Bootstrap badge of a specific type.
|
||||
|
||||
ROLE: The role of the badge (like 'primary', 'secondary', 'success', etc.).
|
||||
COLOR: The color of the badge (like 'primary', 'secondary', 'success', etc.).
|
||||
|
||||
PILL: (optional) If true, the badge will have 'rounded-pill' style.
|
||||
|
||||
The newly defined macro, when called, will generate HTML for a Bootstrap
|
||||
badge of the specified type."
|
||||
(let* ((macro-name (intern (string-upcase (concatenate 'string "BADGE-" (if (null pill) "" "PILL-") role)))))
|
||||
(let* ((macro-name (intern (string-upcase (concatenate 'string "BADGE-" (if (null pill) "" "PILL-") color)))))
|
||||
`(defmacro ,macro-name (&body body)
|
||||
`(badge (:role ,,role :pill ,,pill) ,@body))))
|
||||
`(badge (:color ,,color :pill ,,pill) ,@body))))
|
||||
|
||||
(defmacro define-badges (roles)
|
||||
(defmacro define-badges (colors)
|
||||
"This macro generates specific badge macros based on the provided names.
|
||||
|
||||
NAMES: A list of badge role names. For each name in this list, a macro will
|
||||
COLORS: A list of badge color names. For each name in this list, a macro will
|
||||
be generated: a badge of the specified type."
|
||||
`(progn
|
||||
,@(loop for role in roles
|
||||
for role-name = (string-downcase (string role))
|
||||
,@(loop for color in colors
|
||||
for color-name = (string-downcase (string color))
|
||||
collect `(progn
|
||||
(define-badge ,role-name)
|
||||
(define-badge ,role-name t)))))
|
||||
(define-badge ,color-name)
|
||||
(define-badge ,color-name t)))))
|
||||
|
||||
(define-badges (primary secondary success danger warning info light dark link))
|
||||
|
|
|
@ -88,10 +88,10 @@
|
|||
|
||||
(in-package :cl-sbt/btn)
|
||||
|
||||
(defmacro btn ((&key (type "primary") (size "")) &body body)
|
||||
(defmacro btn ((&key (color "primary") (size "")) &body body)
|
||||
"This macro generates a Bootstrap button.
|
||||
|
||||
TYPE: The type of the button (like 'primary', 'secondary', 'success', etc.).
|
||||
COLOR: The color of the button (like 'primary', 'secondary', 'success', etc.).
|
||||
|
||||
SIZE: (optional) The size of the button ('lg' for large, 'sm' for small).
|
||||
|
||||
|
@ -103,14 +103,14 @@ Example:
|
|||
(:button :type "button"
|
||||
:class (concatenate 'string
|
||||
"btn"
|
||||
(format nil " btn-~a" ,type)
|
||||
(format nil " btn-~a" ,color)
|
||||
(if (string-equal ,size "") nil (format nil " btn~a" ,size)))
|
||||
,@body)))
|
||||
|
||||
(defmacro define-btn (role &optional (outline nil) (size nil))
|
||||
(defmacro define-btn (color &optional (outline nil) (size nil))
|
||||
"This macro defines a new macro for creating a Bootstrap button of a specific type, size, and outline style.
|
||||
|
||||
TYPE: The type of the button (like 'primary', 'secondary', 'success', etc.).
|
||||
COLOR: The color of the button (like 'primary', 'secondary', 'success', etc.).
|
||||
|
||||
OUTLINE: (optional) Whether the button should be of the outline style.
|
||||
|
||||
|
@ -120,12 +120,12 @@ The newly defined macro, when called, will generate HTML for a Bootstrap
|
|||
button of the specified type and size."
|
||||
(let* ((size-name (if (null size) "" (format nil "-~a" size)))
|
||||
(outline-name (if (null outline) "" "outline-"))
|
||||
(role-name (concatenate 'string outline-name role))
|
||||
(macro-name (intern (string-upcase (concatenate 'string "BTN-" outline-name role size-name)))))
|
||||
(color-name (concatenate 'string outline-name color))
|
||||
(macro-name (intern (string-upcase (concatenate 'string "BTN-" outline-name color size-name)))))
|
||||
`(defmacro ,macro-name (&body body)
|
||||
`(btn (:type ,,role-name :size ,,size-name) ,@body))))
|
||||
`(btn (:color ,,color-name :size ,,size-name) ,@body))))
|
||||
|
||||
(defmacro define-btns (roles)
|
||||
(defmacro define-btns (colors)
|
||||
"This macro generates a suite of button-creating macros for each provided button type.
|
||||
|
||||
NAMES: A list of button type names. Each name should be a string
|
||||
|
@ -139,14 +139,14 @@ button, and a small outline button.
|
|||
The newly defined macros, when called, will generate HTML for a Bootstrap
|
||||
button of the corresponding type, size, and outline style."
|
||||
`(progn
|
||||
,@(loop for role in roles
|
||||
for role-name = (string-downcase (string role))
|
||||
,@(loop for color in colors
|
||||
for color-name = (string-downcase (string color))
|
||||
collect `(progn
|
||||
(define-btn ,role-name)
|
||||
(define-btn ,role-name t)
|
||||
(define-btn ,role-name t "lg")
|
||||
(define-btn ,role-name t "sm")
|
||||
(define-btn ,role-name nil "lg")
|
||||
(define-btn ,role-name nil "sm")))))
|
||||
(define-btn ,color-name)
|
||||
(define-btn ,color-name t)
|
||||
(define-btn ,color-name t "lg")
|
||||
(define-btn ,color-name t "sm")
|
||||
(define-btn ,color-name nil "lg")
|
||||
(define-btn ,color-name nil "sm")))))
|
||||
|
||||
(define-btns (primary secondary success danger warning info light dark link))
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
(deftest test-badge-macro
|
||||
(testing "Testing badge macro"
|
||||
(let ((result (spinneret:with-html-string (badge (:role "primary")))))
|
||||
(let ((result (spinneret:with-html-string (badge (:color "primary")))))
|
||||
(ok (search "class=\"badge text-bg-primary\"" result)))))
|
||||
|
||||
(deftest test-badge-primary
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
(deftest test-btn-macro
|
||||
(testing "Testing btn macro"
|
||||
(let ((result (spinneret:with-html-string (btn (:type "primary") "foo"))))
|
||||
(let ((result (spinneret:with-html-string (btn (:color "primary") "foo"))))
|
||||
(ok (search "class=\"btn btn-primary\"" result)))))
|
||||
|
||||
(deftest test-btn-primary
|
||||
|
|
Loading…
Add table
Reference in a new issue