work in progress: sc-hx:render-content; provide macro for looping over property list

This commit is contained in:
Helmut Merz 2024-07-19 12:13:12 +02:00
parent 5ee58b2437
commit a404e8ee88
6 changed files with 32 additions and 16 deletions

View file

@ -5,9 +5,14 @@
(defpackage :scopes/frontend/cs-hx
(:use :common-lisp)
(:local-nicknames (:dom :scopes/web/dom)
(:message :scopes/core/message)
(:response :scopes/web/response))
(:export #:render-content #:response))
(in-package :scopes/frontend/cs-hx)
(defclass response (response:html-response) ())
(defmethod render-content ((resp response) msg)
(dom:render (dom:dlist nil (message:data msg))))

View file

@ -4,19 +4,22 @@
(config:root :env-keys '(:address :port))
(config:add :logger :class 'logging:config
:loglevel :debug
:logfile (t:test-path "scopes-test.log" "log")
:console nil)
(config:add :logger
:class 'logging:config
:loglevel :debug
:logfile (t:test-path "scopes-test.log" "log")
:console nil)
(config:add :server :class 'server:config
:port "8899"
:routes
`((("api") server:message-handler)
(() server:fileserver
:doc-root ,(t:test-path "" "docs"))))
(config:add :server
:class 'server:config
:port "8899"
:routes
`((("api") server:message-handler :html-responder cs-hx:response)
(() server:fileserver
:doc-root ,(t:test-path "" "docs"))))
(config:add-action '(:test :data) #'core:echo)
(config:add :client :class 'client:config
:base-url "http://localhost:8899"
:doc-path "/" :api-path "/api/")
(config:add :client
:class 'client:config
:base-url "http://localhost:8899"
:doc-path "/" :api-path "/api/")

View file

@ -61,7 +61,8 @@
(t:show-result))))
(deftest test-util ()
(== (util:to-keyword "hello-kitty") :hello-kitty))
(== (util:to-keyword "hello-kitty") :hello-kitty)
(== (util:loop-plist '(:a "a" :b "b") k v collect (string-upcase k)) '("A" "B")))
(deftest test-send ()
(let ((rcvr (receiver t:*test-suite*))

View file

@ -5,6 +5,7 @@
(:local-nicknames (:config :scopes/config)
(:core :scopes/core)
(:client :scopes/web/client)
(:cs-hx :scopes/frontend/cs-hx)
(:dom :scopes/web/dom)
(:logging :scopes/logging)
(:message :scopes/core/message)

View file

@ -3,6 +3,7 @@
(defpackage :scopes/util
(:use :common-lisp)
(:export #:flatten-str #:to-keyword #:to-string
#:loop-plist
#:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string
#:relative-path #:runtime-path #:system-path))
@ -22,6 +23,9 @@
(defun to-keyword (s)
(intern (string-upcase s) :keyword))
(defmacro loop-plist (plist kvar vvar &body body)
`(loop for (,kvar ,vvar . _) on ,plist by #'cddr ,@body))
;;;; directory and pathname utilities
(defun split-filename (name)

View file

@ -50,7 +50,8 @@
(defun dlist (attrs plist)
(elem :dl attrs
(loop for (key val . r) on plist by #'cddr append
;(loop for (key val . r) on plist by #'cddr append
(util:loop-plist plist key val append
(cons (element :dt nil (string-downcase key)) (dds nil val)))))
(defun dds (attrs cont)
@ -88,7 +89,8 @@
(write-char c *output*))
(defun put-attrs (plist)
(loop for (key val . r) on plist by #'cddr do
;(loop for (key val . r) on plist by #'cddr do
(util:loop-plist plist key val do
(put-char #\Space)
(when val
(put-string (string-downcase key))