diff --git a/src/section.lisp b/src/section.lisp index f0dca64..81aeb53 100644 --- a/src/section.lisp +++ b/src/section.lisp @@ -45,34 +45,52 @@ Example: (:h* ,head) ,(when items `(btn-group-outline-primary ,@items))))) - (defmacro section (grid-class row-class &body body) "Creates a Bootstrap-styled section. -GRID-CLASS: Set bootstrap grid classes. +GRID-CLASS: Can be: + - A string of space-separated classes + - A list of grid options for make-grid-class + - A call to make-grid-class + Examples: + (section (:row 1 :xs 2) nil \"foo\") + (section (make-grid-class :row 1 :xs 2) nil \"foo\") -ROW-CLASS: Enable a div as row +ROW-CLASS: Similar to GRID-CLASS. Can be: + - A string of space-separated classes + - A list of grid options for make-grid-class + - A call to make-grid-class + Examples: + (section nil (:row 1 :xs 2) \"foo\") + (section nil (make-grid-class :row 1 :xs 2) \"foo\") -BODY: The content of the section, typically including a call to with-title-bar." +BODY: The content of the section." `(spinneret:with-html (:section :class - ,@(progn `((combine-classes "mb-3" ,grid-class))) + ,(cond ((stringp grid-class) `(combine-classes "mb-3" ,grid-class)) + ((eq 'make-grid-class (first grid-class)) `(combine-classes "mb-3" ,grid-class)) + (t `(combine-classes "mb-3" (apply #'make-grid-class ',grid-class)))) ,@(if row-class - `((:div :class ,row-class ,@body)) + `((:div :class ,(cond ((stringp row-class) row-class) + ((eq 'make-grid-class (first row-class)) row-class) + (t `(apply #'make-grid-class ',row-class))) + ,@body)) body)))) (defmacro define-section-type (name grid-class row-class) "Define section types. +NAME: macro name + GRID-CLASS: Set bootstrap grid classes. ROW-CLASS: Enable a div as row." `(defmacro ,name (&body body) - `(section ,,grid-class ,,row-class ,@body))) + `(section ,',grid-class ,',row-class ,@body))) (define-section-type with-section nil nil) -(define-section-type with-section-row (make-grid-class :row t) nil) -(define-section-type with-section-col (make-grid-class :col t) nil) +(define-section-type with-section-row (:row t) nil) +(define-section-type with-section-col (:col t) nil) ;; In my GUIs I often like to have some kind of `properties` on the left side. -(define-section-type with-section-props (make-grid-class :col t :xs 12 :lg 4 :xl 2) nil) +(define-section-type with-section-props (:col t :xs 12 :lg 4 :xl 2) nil) diff --git a/src/utility.lisp b/src/utility.lisp index d84ef5d..9f42e70 100644 --- a/src/utility.lisp +++ b/src/utility.lisp @@ -579,22 +579,22 @@ Example 3: "Validate alignment value against allowed values." (member value '("start" "center" "end" "around" "between" "evenly") :test #'string=)) -(defun make-grid-class (&key - row - col - xs - sm - md - lg - xl - xxl - g - gx - gy - align-items - align-self - justify-content - order) +(defun make-grid-class (&rest args &key + row + col + xs + sm + md + lg + xl + xxl + g + gx + gy + align-items + align-self + justify-content + order) "Return a css class as string according to Bootstrap Grid System. --- @@ -627,20 +627,22 @@ Example: (make-grid-class :row t :col t) -> error (make-grid-class :row t :g 0) -> \"row g-0\"" - (cond ((and row col) - (error "Cannot specify both :row and :col")) - ((and row align-self) - (error "Cannot specify both :row and :align-self")) - ((and col (or g gx gy)) - (error "Cannot specify both :col and gutters (:g :gx :gy)")) - ((and col justify-content) - (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"))) + (if (null args) + nil + (cond ((and row col) + (error "Cannot specify both :row and :col")) + ((and row align-self) + (error "Cannot specify both :row and :align-self")) + ((and col (or g gx gy)) + (error "Cannot specify both :col and gutters (:g :gx :gy)")) + ((and col justify-content) + (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")))) (let ((class-strings '()) (breakpoints