clog/tutorial/30-tutorial.lisp
2022-04-13 12:02:59 -04:00

71 lines
2.2 KiB
Common Lisp

;; Demonstrates clog-web-site from clog-web instant websites
(defpackage #:clog-tut-30
(:use #:cl #:clog #:clog-web)
(:export start-tutorial))
(in-package :clog-tut-30)
;; Site setup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;l;;
(defun init-site (body)
(clog-web-initialize body)
(create-web-site body
:settings '(:menu-class "w3-black")
:title "CLOG - The Common Lisp Omnificent GUI"
:footer "(c) 2022 David Botton"
:logo "/img/clog-liz.png"))
;; This is the menu structure
(defparameter *menu* `(("Content" (("Home" "/")
("Content from Lambda" "/lambda")
("Content from File" "/readme")))
("Help" (("About" "/about")))))
;; Page handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; / - a simple content string
(defun on-main (body)
;; We call init-site on every page to load our theme and settings
(init-site body)
(create-web-page body :main `(:menu ,*menu*
:content "<b>Welcome to tutorial 30</b><p>Any HTML works!")))
;; /readme - get content from a text file
(defun on-readme (body)
(init-site body)
(let ((readme (alexandria:read-file-into-string
(format nil "~A~A" (asdf:system-source-directory :clog) "README.md"))))
(create-web-page body :main `(:menu ,*menu*
:content ,(format nil "<pre>~A</pre>" readme)))))
;; /lambda - use a function to output to the page content
(defun on-lambda (body)
(init-site body)
(create-web-page body :main `(:menu ,*menu*
:content ,(lambda (obj)
(create-div obj :content "I am in the content area")))))
;; /about
(defun on-about (body)
(init-site body)
(create-web-page body :main `(:menu ,*menu*
:content "About Me")))
;; Start the webserver
(defun start-tutorial ()
;; Initialize CLOG and the / url path
(initialize 'on-main
;; Use long polling technique so pages are crawled by google
:long-poll-first t
;; Supply so meta info
:boot-function (clog-web-meta
"clogpower.com - CLOG - the common lisp omnificent gui"))
;; Setup additional paths
(set-on-new-window 'on-about :path "/about")
(set-on-new-window 'on-lambda :path "/lambda")
(set-on-new-window 'on-readme :path "/readme")
(open-browser))