From a3d366c7fb716606529320da1b756488ff27a366 Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Wed, 19 Jun 2024 18:17:02 +0200 Subject: [PATCH] Use with-form instead of with-page --- src/views/main.lisp | 53 ++++++++++++++++++++++++++++++++++++++++++ src/views/package.lisp | 7 ++---- src/views/sus.lisp | 23 +++++++++--------- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/views/main.lisp b/src/views/main.lisp index de42d4a..c960997 100644 --- a/src/views/main.lisp +++ b/src/views/main.lisp @@ -1,3 +1,56 @@ (in-package :ml-survey/views) (defparameter *use-cdn* nil) + +(defmacro with-form ((&key + meta + (title "Web page") + add-css-urls + add-js-urls) + &body body) + "This macro simplifies the process of creating an HTML web page. + +META: The meta-information for the web page. + +TITLE: Specifies the title of the web page. Defaults to 'Web page'. + +MAIN-CON: If t add css class `container` to
. + +ADD-CSS-URLS: An optional parameter for additional CSS file URLs. + +ADD-JS-URLS: An optional parameter for additional JavaScript file URLs. + +BODY: Denotes the markup for the body of the web page. + +Example usage: + (with-form (:meta (:author \"John Doe\") :title \"My Page\") \"foo\")" + `(spinneret:with-html-string + (:doctype) + (:html :data-bs-theme ,dev.metalisp.sbt:*color-theme* + (:head (:meta :charset "utf-8") + (:meta :name "viewport" + :content "width=device-width, initial-scale=1") + ,@(loop for (key value) on meta by #'cddr + collect `(:meta :name + ,(string-downcase (symbol-name key)) + :content ,(getf meta key))) + + (:title ,title) + + (:link :type "text/css" :rel "stylesheet" :href ,(dev.metalisp.sbt:bs-url-css)) + ,@(loop for url in add-css-urls + collect `(:link :type "text/css" + :rel "stylesheet" :href ,url))) + + (:body + + (:div :class "container text-center py-3" + (:a :href "#main-content" + :class "skip-link" + (find-l10n "skip-link" spinneret:*html-lang* *l10n*))) + + ,@body + + (:script :src ,(dev.metalisp.sbt:bs-url-js)) + ,@(loop for url in add-js-urls + collect `(:script :src ,url)))))) diff --git a/src/views/package.lisp b/src/views/package.lisp index 8b4e6d7..6e42933 100644 --- a/src/views/package.lisp +++ b/src/views/package.lisp @@ -1,8 +1,7 @@ (defpackage ml-survey/views (:use #:cl) (:import-from #:spinneret - #:*html* - #:*html-lang*) + #:*html*) (:import-from #:dev.metalisp.sbt #:find-l10n) (:import-from #:dev.metalisp.sbt @@ -17,9 +16,7 @@ (:import-from #:dev.metalisp.sbt/utility #:spacing) (:import-from #:dev.metalisp.sbt - #:*use-cdn* - #:bs-url-css - #:bs-url-js) + #:*use-cdn*) (:export #:index #:imprint #:new-survey diff --git a/src/views/sus.lisp b/src/views/sus.lisp index acd918a..5ac1b32 100644 --- a/src/views/sus.lisp +++ b/src/views/sus.lisp @@ -13,14 +13,15 @@ nil) (defun sus-form () - (with-page (:title "SUS Form") - (:section :class "container my-5" - (:h2 "Usability Feedback Form") - (:p "Please fill out the following forms and press the submit button.") - (:form :action (hunchentoot:request-uri*) - :method "post" - :class (spacing :property "m" :side "y" :size 5) - ;; load the multi-form from disk - (load-form *html-lang* "sus.lisp") - (btn-primary (:type "submit") - (find-l10n "submit" *html-lang* *l10n*)))))) + (with-form (:title "SUS Form") + (:main :id "main-content" + :class "container my-5" + (:h1 "Usability Feedback Form") + (:p "Please fill out the following forms and press the submit button.") + (:form :action (hunchentoot:request-uri*) + :method "post" + :class (spacing :property "m" :side "y" :size 5) + ;; load the multi-form from disk + (load-form spinneret:*html-lang* "sus.lisp") + (btn-primary (:type "submit") + (find-l10n "submit" spinneret:*html-lang* *l10n*))))))