web: use /hx as standard API path for htmx-type response; dom: use pre-defined elements

This commit is contained in:
Helmut Merz 2024-07-22 13:46:40 +02:00
parent f9011dd9c6
commit 5835c54b36
6 changed files with 16 additions and 9 deletions

View file

@ -12,7 +12,7 @@
:port "8800"
:address "0.0.0.0"
:routes
`((("api") server:message-handler :html-responder cs-hx:response)
`((("hx") server:message-handler :html-responder cs-hx:response)
(() server:fileserver :doc-root
,(config:path "/var/www/html/" :env-key :docroot))))
(config:add-action '(:test :data) #'core:echo)

View file

@ -14,7 +14,7 @@
:class 'server:config
:port "8899"
:routes
`((("api") server:message-handler :html-responder cs-hx:response)
`((("hx") server:message-handler :html-responder cs-hx:response)
(() server:fileserver
:doc-root ,(t:test-path "" "docs"))))
(config:add-action '(:test :data) #'core:echo)
@ -22,4 +22,4 @@
(config:add :client
:class 'client:config
:base-url "http://localhost:8899"
:doc-path "/" :api-path "/api/")
:doc-path "/" :api-path "/hx/")

View file

@ -38,9 +38,9 @@
(deftest test-dom ()
(== (dom:render
(dom:element :a '(:href "https://example.com"
:title "Demo" :class (:demo-link :plain))
"Link to example.com"))
(dom:a '(:href "https://example.com"
:title "Demo" :class (:demo-link :plain))
"Link to example.com"))
"<a href=\"https://example.com\" title=\"Demo\" class=\"demo-link plain\">Link to example.com</a>"))
(deftest test-server-config (server)

View file

@ -56,6 +56,9 @@
;;;; utilities
(defmacro normalize (&rest xs)
)
(defun test-path (name &rest dirs)
(apply #'scopes/util:system-path *current-system* name "test" dirs))

View file

@ -11,8 +11,10 @@
;;;; strings, symbols, keywords, ...
(defun flatten-str (s &key (with " "))
(str:join with (str:lines s)))
(defun flatten-str (s &key (sep " "))
(str:join sep
(mapcar (lambda (x) (str:trim x))
(str:lines s))))
(defun to-string (k &key (sep " ") lower-case)
(let ((pattern (if lower-case "~(~a~)" "~a")))

View file

@ -39,7 +39,7 @@
(put c))
(end tag))))
;;;; element = HTML element - no self-closing (<... />) of empty elements
;;;; element = HTML element - no self-closing of empty elements
(defclass element (xml-element) ())
@ -58,6 +58,8 @@
;;;; void element (e.g. <input ...>): no body, no explicit closing of tag
(defclass void-element (xml-element) ())
(defun void-element (tag attrs)
(make-instance 'void-element :tag tag :attrs attrs))