Improve view

This commit is contained in:
Akira Tempaku 2024-04-19 13:04:30 +09:00
parent 0952cb2e13
commit cf691411d7
7 changed files with 39 additions and 20 deletions

View file

View file

@ -1,10 +1,8 @@
(defpackage #:hp/view/renderer
(defpackage #:hp/components/document
(:use #:cl)
(:local-nicknames (#:jg #:jingle))
(:local-nicknames (#:pi #:piccolo))
(:export #:render
#:partial-render))
(in-package #:hp/view/renderer)
(:export #:document))
(in-package #:hp/components/document)
(pi:define-element document (title description)
(pi:h
@ -24,15 +22,4 @@
(meta
:name "description"
:content (or description "pakuの個人サイト")))
(body :hx-ext "head-support"
(main pi:children)))))
(defun render (page &key status metadata)
(jg:with-html-response
(and status (jg:set-response-status status))
(pi:elem-str (document metadata page))))
(defun partial-render (component &key status)
(jg:with-html-response
(and status (jg:set-response-status status))
(pi:elem-str component)))
pi:children)))

View file

@ -0,0 +1,13 @@
(defpackage #:hp/components/layout
(:use #:cl)
(:local-nicknames (#:pi #:piccolo))
(:export #:layout))
(in-package #:hp/components/layout)
(pi:define-element layout ()
(pi:h
(body :hx-ext "head-support"
; header
(main pi:children)
; footer
)))

View file

@ -1,7 +1,7 @@
(defpackage #:hp/routes/about
(:use #:cl)
(:local-nicknames (#:pi #:piccolo))
(:local-nicknames (#:view #:hp/view/*))
(:local-nicknames (#:view #:hp/view))
(:export #:handle-get))
(in-package #:hp/routes/about)

View file

@ -1,7 +1,7 @@
(defpackage #:hp/routes/index
(:use #:cl)
(:local-nicknames (#:pi #:piccolo))
(:local-nicknames (#:view #:hp/view/*))
(:local-nicknames (#:view #:hp/view))
(:export #:handle-get))
(in-package #:hp/routes/index)

View file

@ -2,7 +2,7 @@
(:use #:cl)
(:local-nicknames (#:jg #:jingle))
(:local-nicknames (#:pi #:piccolo))
(:local-nicknames (#:view #:hp/view/*))
(:local-nicknames (#:view #:hp/view))
(:export #:handle-not-found))
(in-package #:hp/routes/not-found)

19
src/view.lisp Normal file
View file

@ -0,0 +1,19 @@
(defpackage #:hp/view
(:use #:cl)
(:local-nicknames (#:jg #:jingle))
(:local-nicknames (#:pi #:piccolo))
(:local-nicknames (#:cmp #:hp/components/*))
(:export #:render
#:partial-render))
(in-package #:hp/view)
(defun render (page &key status metadata)
(jg:with-html-response
(and status (jg:set-response-status status))
(pi:elem-str (cmp:document metadata
(cmp:layout page)))))
(defun partial-render (component &key status)
(jg:with-html-response
(and status (jg:set-response-status status))
(pi:elem-str component)))