From 70251c7ec00fdf5bce1c1b0386fdfcce50669916 Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Sat, 27 Jan 2024 14:41:21 +0100 Subject: [PATCH] Modify with-page and questionnaire docs --- docs/pattern/questionnaire-page.html | 250 ++++++++++++++------------- docs/pattern/questionnaire.org | 44 ++--- src/main.lisp | 6 +- 3 files changed, 148 insertions(+), 152 deletions(-) diff --git a/docs/pattern/questionnaire-page.html b/docs/pattern/questionnaire-page.html index 3256140..1258c2e 100644 --- a/docs/pattern/questionnaire-page.html +++ b/docs/pattern/questionnaire-page.html @@ -1,145 +1,149 @@ - + + - - Questionnaire Examples + + + Questionnaire Example + href=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css> -

Questionnaire Examples

-
-
- How old are you? -
    -
  1. - +

    Questionnaire Example

    +
    + +
    + How old are you? +
      +
    1. +
      - -
      -
    2. - + + +
    3. +
      - -
      -
    4. - + + +
    5. +
      - -
      -
    6. - + + +
    7. +
      - -
      -
    8. - + + +
    9. +
      - -
      -
    -
    -
    -
    - Gender -
      -
    1. - + + +
    +
    +
    +
    + Gender +
      +
    1. +
      - -
      -
    2. - + + +
    3. +
      - -
      -
    4. - + + +
    5. +
      - -
      -
    6. - + + +
    7. +
      - -
      -
    8. - + + +
    9. +
      - -
      -
    10. - + + +
    11. +
      - - -
      -
    -
    -
    -
    - How many hours per day, on average, do you spend browsing the internet? -
      -
    1. - + + + +
    +
    +
    +
    + How many hours per day, on average, do you spend browsing the internet? +
      +
    1. +
      - -
      -
    2. - + + +
    3. +
      - -
      -
    4. - + + +
    5. +
      - -
      -
    6. - + + +
    7. +
      - -
      -
    -
    -
    - - + + +
+
+
+ + + + src=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js> \ No newline at end of file diff --git a/docs/pattern/questionnaire.org b/docs/pattern/questionnaire.org index 9923ea1..55c48fb 100644 --- a/docs/pattern/questionnaire.org +++ b/docs/pattern/questionnaire.org @@ -1,7 +1,7 @@ #+title: Creating a Questionnaire using cl-sbt/questionnaire Macros in a Web Application #+author: Marcus Kammer #+email: marcus.kammer@mailbox.org -#+date: 2023-11-09T18:27+01:00 +#+date: 2024-01-27T14:40+01:00 * Introduction Questionnaires are powerful tools for gathering information and insights from @@ -31,35 +31,27 @@ required for different types of questions in a questionnaire. #+name: questionnaire-page #+begin_src lisp :results output file :file-ext html (defpackage my-web-app - (:use :cl :cl-sbt/questionnaire) - (:export :generate-button-page)) + (:use :cl) + (:import-from :dev.metalisp.sbt :with-page) + (:import-from :dev.metalisp.sbt/pattern/questionnaire :questionnaire) + (:export :generate-button-page)) (in-package :my-web-app) (defun generate-questionnaire-page () - "Generates an HTML page with questionnaires using cl-sbt/questionnaire macros." - (spinneret:with-html-string - (:html - (:head - (:title "Questionnaire Examples") - (:link :type "text/css" - :rel "stylesheet" - :href "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css")) - (:body - (:h1 "Questionnaire Examples") - ;; --- - (questionnaire "/submit" - (:ask "How old are you?" - :group "age" - :choices (:radio "18-24" "25-34" "35-44" "45-54" "55+")) - (:ask "Gender" - :group "gender" - :choices (:radio "Male" "Female" "Non-binary" "Prefer not to say" "Other" :text "Other")) - (:ask "How many hours per day, on average, do you spend browsing the internet?" - :group "webbrowsing" - :choices (:radio "Less than 1 hour" "1-3 hours" "3-5 hours" "5+ hours"))) - ;; --- - (:script :src "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"))))) + "Generates an HTML page with questionnaires using cl-sbt/questionnaire macros." + (with-output-to-string (spinneret:*html*) + (with-page (:title "Questionnaire Example" :main-con t) + (questionnaire "/submit" + (:ask "How old are you?" + :group "age" + :choices (:radio "18-24" "25-34" "35-44" "45-54" "55+")) + (:ask "Gender" + :group "gender" + :choices (:radio "Male" "Female" "Non-binary" "Prefer not to say" "Other" :text "Other")) + (:ask "How many hours per day, on average, do you spend browsing the internet?" + :group "webbrowsing" + :choices (:radio "Less than 1 hour" "1-3 hours" "3-5 hours" "5+ hours")))))) (format t (generate-questionnaire-page)) #+end_src diff --git a/src/main.lisp b/src/main.lisp index fed6152..4bad9f5 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -69,9 +69,9 @@ (with-open-file (stream filename :direction :output :if-exists :supersede) (write-string string stream)))) -(defmacro with-page ((&key meta title add-css-urls add-js-urls) &body body) +(defmacro with-page ((&key meta title main-con add-css-urls add-js-urls) &body body) (unless title - (error "Please add a title")) + (error "A page needs a title. Please add a title.")) `(spinneret:with-html (:doctype) (:html :data-bs-theme ,*color-theme* @@ -89,7 +89,7 @@ collect `(:link :type "text/css" :rel "stylesheet" :href ,url))) (:body (:h1 :class "visually-hidden" ,title) - (:main ,@body) + (:main ,@(when main-con (list :class "container")) ,@body) (:script :src ,(js-url)) ,@(loop for url in add-js-urls