give access to clog-web-site object

This commit is contained in:
David Botton 2022-04-24 12:35:37 -04:00
parent c2196ca3c6
commit dba768a76d

View file

@ -97,9 +97,8 @@
"CLOG-WEB - Websites" "CLOG-WEB - Websites"
(clog-web-site class) (clog-web-site class)
(clog-web-routes-from-menu function)
(clog-web-meta function)
(create-web-site generic-function) (create-web-site generic-function)
(get-web-site generic-function)
(create-web-page generic-function) (create-web-page generic-function)
"CLOG-WEB-SITE - Accessors" "CLOG-WEB-SITE - Accessors"
@ -112,9 +111,11 @@
(logo generic-function) (logo generic-function)
"CLOG-WEB - Utilities" "CLOG-WEB - Utilities"
(base-url-p function) (clog-web-routes-from-menu function)
(adjust-for-base-url function) (clog-web-meta function)
(base-url-split function)) (base-url-p function)
(adjust-for-base-url function)
(base-url-split function))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-web - CLOG Web page abstraction ;; Implementation - clog-web - CLOG Web page abstraction
@ -917,8 +918,8 @@ the value if set in the theme settings."
(cond (cond
((eq (third l) :select) ((eq (third l) :select)
(format nil (format nil
"<div><label class='~A'>~A</label>~ "<p><label class='~A'>~A</label>~
<select class='w3-select ~A' name='~A-~A'>~A</select></div>" <select class='w3-select ~A' name='~A-~A'>~A</select></p>"
text-class (first l) text-class (first l)
border-class html-id (second l) border-class html-id (second l)
(format nil "~{~A~}" (format nil "~{~A~}"
@ -933,14 +934,14 @@ the value if set in the theme settings."
(fourth l))))) (fourth l)))))
((eq (third l) :radio) ((eq (third l) :radio)
(format nil (format nil
"<div><label class='~A'>~A</label>~A</div>" "<p><label class='~A'>~A</label>~A</p>"
text-class (first l) text-class (first l)
(format nil "~{~A~}" (format nil "~{~A~}"
(mapcar (lambda (s) (mapcar (lambda (s)
(format nil (format nil
"<div><input type=radio class='w3-radio' name='~A-~A'~ "<p><input type=radio class='w3-radio' name='~A-~A'~
id='~A-~A-~A' value='~A' ~A> ~ id='~A-~A-~A' value='~A' ~A> ~
<label for='~A-~A-~A'>~A</label></div>" <label for='~A-~A-~A'>~A</label></p>"
html-id (second l) html-id (second l)
html-id (second l) (second s) html-id (second l) (second s)
(second s) (second s)
@ -952,11 +953,11 @@ the value if set in the theme settings."
(fourth l))))) (fourth l)))))
((eq (third l) :checkbox) ((eq (third l) :checkbox)
(format nil (format nil
"<div><input class='w3-check' type='checkbox' ~ "<p><input class='w3-check' type='checkbox' ~
name='~A-~A' id='~A-~A' ~A> ~ name='~A-~A' id='~A-~A' ~A> ~
<label class='~A' for='~A-~A'>~ <label class='~A' for='~A-~A'>~
~A</label>~ ~A</label>~
</div>" </p>"
html-id (second l) html-id (second l) html-id (second l) html-id (second l)
(if (fourth l) (if (fourth l)
"checked" "checked"
@ -965,9 +966,9 @@ the value if set in the theme settings."
(first l))) (first l)))
((third l) ((third l)
(format nil (format nil
"<div><label class='~A'>~A</label>~ "<p><label class='~A'>~A</label>~
<input class='w3-input ~A' type='~A'~ <input class='w3-input ~A' type='~A'~
name='~A-~A' id='~A-~A' value='~A'></div>" name='~A-~A' id='~A-~A' value='~A'></p>"
text-class (first l) text-class (first l)
border-class (third l) border-class (third l)
html-id (second l) html-id (second l) html-id (second l) html-id (second l)
@ -976,8 +977,8 @@ the value if set in the theme settings."
""))) "")))
(t (t
(format nil (format nil
"<div><label class='~A'>~A</label>~ "<p><label class='~A'>~A</label>~
<input class='w3-input ~A' type='text' name='~A-~A' id='~A-~A'></div>" <input class='w3-input ~A' type='text' name='~A-~A' id='~A-~A'></p>"
text-class (first l) text-class (first l)
border-class html-id (second l) html-id (second l))))) border-class html-id (second l) html-id (second l)))))
fields))) fields)))
@ -1055,32 +1056,6 @@ the value if set in the theme settings."
:reader logo)) :reader logo))
(:documentation "Website information")) (:documentation "Website information"))
;;;;;;;;;;;;;;;;;;;
;; clog-web-meta ;;
;;;;;;;;;;;;;;;;;;;
(defun clog-web-meta (description)
"Returns a boot-function for use with CLOG:INITIALIZE to add meta
and no-script body information for search engines with DESCRIPTION."
(lambda (path content)
(declare (ignore path))
(funcall (cl-template:compile-template content)
(list :meta (format nil "<meta name='description' content='~A'>"
description)
:body description))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; clog-web-routes-from-menu ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun clog-web-routes-from-menu (menu)
"Use a menu to setup a route for each menu item that has a third
element."
(dolist (drop-down menu)
(dolist (item (second drop-down))
(when (third item)
(set-on-new-window (third item) :path (second item))))))
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
;; create-web-site ;; ;; create-web-site ;;
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
@ -1114,6 +1089,15 @@ clog-body."))
(setf (web-site app) website) (setf (web-site app) website)
website)) website))
(defgeneric get-web-site (clog-obj)
(:documentation "Retrieve the clog-web-site object created on CLOG-OBJ's
connection"))
(defmethod get-web-site ((obj clog-obj))
(let* ((app (connection-data-item obj "clog-web"))
(website (web-site app)))
website))
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
;; create-web-page ;; ;; create-web-page ;;
;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;
@ -1123,24 +1107,60 @@ clog-body."))
CLOG-OBJ as parent")) CLOG-OBJ as parent"))
(defmethod create-web-page ((obj clog-obj) page properties) (defmethod create-web-page ((obj clog-obj) page properties)
(let* ((app (connection-data-item obj "clog-web")) (funcall (theme (get-web-site obj))
(website (web-site app))) obj (get-web-site obj) page properties))
(funcall (theme website) obj website page properties)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utilities ;; Utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;
;; clog-web-meta ;;
;;;;;;;;;;;;;;;;;;;
(defun clog-web-meta (description)
"Returns a boot-function for use with CLOG:INITIALIZE to add meta
and no-script body information for search engines with DESCRIPTION."
(lambda (path content)
(declare (ignore path))
(funcall (cl-template:compile-template content)
(list :meta (format nil "<meta name='description' content='~A'>"
description)
:body description))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; clog-web-routes-from-menu ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun clog-web-routes-from-menu (menu)
"Use a menu to setup a route for each menu item that has a third
element."
(dolist (drop-down menu)
(dolist (item (second drop-down))
(when (third item)
(set-on-new-window (third item) :path (second item))))))
;;;;;;;;;;;;;;;;
;; base-url-p ;;
;;;;;;;;;;;;;;;;
(defun base-url-p (base-url url-path) (defun base-url-p (base-url url-path)
"True if url-path is based on base-url" "True if url-path is based on base-url"
(ppcre:scan (format nil "^~A/" base-url) (format nil "~A/" url-path))) (ppcre:scan (format nil "^~A/" base-url) (format nil "~A/" url-path)))
;;;;;;;;;;;;;;;;;;;;;;;;;
;; adjust-for-base-url ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun adjust-for-base-url (base-url url-path) (defun adjust-for-base-url (base-url url-path)
"If url-path is not on base-url return base-url otherwise url-path" "If url-path is not on base-url return base-url otherwise url-path"
(if (base-url-p base-url url-path) (if (base-url-p base-url url-path)
url-path url-path
base-url)) base-url))
;;;;;;;;;;;;;;;;;;;;
;; base-url-split ;;
;;;;;;;;;;;;;;;;;;;;
(defun base-url-split (base-url url-path) (defun base-url-split (base-url url-path)
"Split path by / adjusting for base-url" "Split path by / adjusting for base-url"
(ppcre:split "/" (adjust-for-base-url base-url url-path))) (ppcre:split "/" (adjust-for-base-url base-url url-path)))