From ab169ace904bd070efe2b67f5591c1201f47181e Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Tue, 4 Feb 2025 16:48:30 +0100 Subject: [PATCH] Finalize make-grid-class function --- src/utility.lisp | 50 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/utility.lisp b/src/utility.lisp index 0ecef51..d84ef5d 100644 --- a/src/utility.lisp +++ b/src/utility.lisp @@ -53,7 +53,8 @@ :text :valign :make-col-class - :combine-classes) + :combine-classes + :make-grid-class) (:documentation "A module for generating Bootstrap utility classes.")) (in-package :ml-sbt/utility) @@ -566,9 +567,17 @@ Example 3: (defun validate-col-value-p (value) "Validate column-related numeric values." - (when (and (integerp value) - (<= 0 value 12)) - t)) + (and (integerp value) + (<= 0 value 12))) + +(defun validate-gutter-value-p (value) + "Validate gutter value is between 0-5." + (and (integerp value) + (<= 0 value 5))) + +(defun validate-alignment-p (value) + "Validate alignment value against allowed values." + (member value '("start" "center" "end" "around" "between" "evenly") :test #'string=)) (defun make-grid-class (&key row @@ -616,7 +625,7 @@ Example: (make-grid-class :col \"auto\") -> \"col col-auto\" (make-grid-class :sm 2) -> \"col-sm-2\" (make-grid-class :row t :col t) -> error - (make-grid-class :g 0) -> \"row g-0\"" + (make-grid-class :row t :g 0) -> \"row g-0\"" (cond ((and row col) (error "Cannot specify both :row and :col")) @@ -628,6 +637,8 @@ Example: (error "Cannot specify both :col and :justify-content")) ((and col align-items) (error "Cannot specify both :col and :align-items")) + ((and row order) + (error "Cannot specify both :row and :order")) ((not (or row col)) (error "Specify at least :row or :col"))) @@ -635,18 +646,41 @@ Example: (breakpoints (loop :for (key value) :on `(:xs ,xs :sm ,sm :md ,md :lg ,lg :xl ,xl :xxl ,xxl) :by #'cddr - :when value :nconc (list key value)))) + :when (or (stringp value) (validate-col-value-p value)) :nconc (list key value)))) (when row (push "row" class-strings) - (push (format nil "~{row-cols-~(~A~)-~A~^ ~}" breakpoints) class-strings) + (when breakpoints + (push (format nil "~{row-cols-~(~A~)-~A~^ ~}" breakpoints) class-strings)) (when (or (stringp row) (validate-col-value-p row)) (push (format nil "row-cols-~A" row) class-strings))) (when col (push "col" class-strings) - (push (format nil "~{col-~(~A~)-~A~^ ~}" breakpoints) class-strings) + (when breakpoints + (push (format nil "~{col-~(~A~)-~A~^ ~}" breakpoints) class-strings)) (when (or (stringp col) (validate-col-value-p col)) (push (format nil "col-~A" col) class-strings))) + (when (validate-gutter-value-p g) + (push (format nil "g-~A" g) class-strings)) + + (when (validate-gutter-value-p gx) + (push (format nil "gx-~A" gx) class-strings)) + + (when (validate-gutter-value-p gy) + (push (format nil "gy-~A" gy) class-strings)) + + (when (validate-alignment-p align-items) + (push (format nil "align-items-~A" align-items) class-strings)) + + (when (validate-alignment-p align-self) + (push (format nil "align-self-~A" align-self) class-strings)) + + (when (validate-alignment-p justify-content) + (push (format nil "justify-content-~A" justify-content) class-strings)) + + (when (validate-gutter-value-p order) + (push (format nil "order-~A" order) class-strings)) + (format nil "~{~A~^ ~}" class-strings)))