diff --git a/frontend/cs-hx.lisp b/frontend/cs-hx.lisp index a9833d5..22e3643 100644 --- a/frontend/cs-hx.lisp +++ b/frontend/cs-hx.lisp @@ -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)))) + diff --git a/test/etc/config-web.lisp b/test/etc/config-web.lisp index 761c957..29ddce1 100644 --- a/test/etc/config-web.lisp +++ b/test/etc/config-web.lisp @@ -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/") diff --git a/test/test-core.lisp b/test/test-core.lisp index d202d55..a380196 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -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*)) diff --git a/test/test-web.lisp b/test/test-web.lisp index 2614747..7c8ea1b 100644 --- a/test/test-web.lisp +++ b/test/test-web.lisp @@ -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) diff --git a/util.lisp b/util.lisp index 84604de..4964792 100644 --- a/util.lisp +++ b/util.lisp @@ -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) diff --git a/web/dom.lisp b/web/dom.lisp index f1cada7..a4e2532 100644 --- a/web/dom.lisp +++ b/web/dom.lisp @@ -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))