work in progress: web/dom: render HTML
This commit is contained in:
parent
036d367439
commit
00366e8b13
3 changed files with 38 additions and 3 deletions
|
@ -10,7 +10,8 @@
|
|||
:lack :lack-component :lack-app-file :quri
|
||||
:scopes-core)
|
||||
:components ((:file "web/client")
|
||||
(:file "web/response")
|
||||
(:file "web/dom")
|
||||
(:file "web/response" :depends-on ("web/dom"))
|
||||
(:file "web/server" :depends-on ("web/response")))
|
||||
:long-description "scopes/web: Web server and web/API/REST client."
|
||||
:in-order-to ((test-op (test-op "scopes-web/test"))))
|
||||
|
|
32
web/dom.lisp
Normal file
32
web/dom.lisp
Normal file
|
@ -0,0 +1,32 @@
|
|||
;;;; cl-scopes/web/dom - "Data Output Model" = simple and dedicated HTML generator
|
||||
|
||||
(defpackage :scopes/web/dom
|
||||
(:use :common-lisp)
|
||||
(:local-nicknames (:alx :alexandria))
|
||||
(:export #:render #:dl))
|
||||
|
||||
(in-package :scopes/web/dom)
|
||||
|
||||
(defvar *output* nil)
|
||||
|
||||
(defmacro render (&body body)
|
||||
`(let ((*output* (make-string-output-stream)))
|
||||
,@body
|
||||
(get-output-stream-string *output*)))
|
||||
|
||||
(defun dl (plist)
|
||||
(write-string "<dl>" *output*)
|
||||
(loop for r on plist by #'cddr do
|
||||
(write-string "<dt>" *output*)
|
||||
(write-string (string-downcase (car r)) *output*)
|
||||
(write-string "</dt>" *output*)
|
||||
(dd (cadr r)))
|
||||
(write-line "</dl>" *output*))
|
||||
|
||||
(defun dd (v)
|
||||
(if (atom v)
|
||||
(setf v (list v)))
|
||||
(dolist (el v)
|
||||
(write-string "<dd>" *output*)
|
||||
(write-string (string el) *output*)
|
||||
(write-string "</dd>" *output*)))
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
(defpackage :scopes/web/response
|
||||
(:use :common-lisp)
|
||||
(:local-nicknames (:message :scopes/core/message))
|
||||
(:local-nicknames (:dom :scopes/web/dom)
|
||||
(:message :scopes/core/message))
|
||||
(:export #:setup
|
||||
#:render #:render-not-found))
|
||||
|
||||
|
@ -27,7 +28,8 @@
|
|||
((ctype :initform "text/html")))
|
||||
|
||||
(defmethod render-content ((resp html-response) msg)
|
||||
(getf (message:data msg) :info))
|
||||
(dom:render (dom:dl (message:data msg))))
|
||||
;(getf (message:data msg) :info))
|
||||
|
||||
;;;; common definitions
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue