Widget rendering helper #74
Replies: 7 comments 2 replies
-
Oh, this is an interesting trick. I'll have to experiment with it, because when building a widget from subwidgets it is often needed to make a widget instance and to call render in the same method, like this: https://github.com/40ants/reblocks-file-server/blob/master/src/core.lisp#L324-L325 Especially in the reblocks-ui2, because it provides reusable components to be rendered inside other components. |
Beta Was this translation helpful? Give feedback.
-
@mmontone I've tested this way of rendering, and object rendering does not work in some cases. Here is a little test where these cases are shown: (uiop:define-package #:spinneret-render-test
(:use #:cl))
(in-package #:spinneret-render-test)
(defclass custom ()
((html :initarg :html
:reader custom-html)))
(defun custom (html)
(make-instance 'custom
:html html))
(defmethod spinneret:html ((obj custom))
(write-string (custom-html obj)
spinneret:*html*))
#|
SPINNERET-RENDER-TEST> (test-render-1)
"<p>Before
<p>First
<p>Second
<p>Third
<p>After"
|#
(defun test-render-1 ()
"This example works as expected"
(spinneret:with-html-string
(:p "Before")
(:p (custom "First"))
(:p (custom "Second"))
(:p (custom "Third"))
(:p "After")))
#|
SPINNERET-RENDER-TEST> (test-render-2)
"<p>Before
<p>After"
Expected result:
<p>Before
First Second Third
<p>After
|#
(defun test-render-2 ()
(spinneret:with-html-string
(:p "Before")
(custom "First")
(custom "Second")
(custom "Third")
(:p "After")))
#|
SPINNERET-RENDER-TEST> (test-render-3)
""
Expected result:
"First Second Third"
|#
(defun test-render-3 ()
(spinneret:with-html-string
(custom "First")
(custom "Second")
(custom "Third")))
#|
SPINNERET-RENDER-TEST> (test-render-4)
"<p>Before
<p>First Second Third
<p>After"
|#
(defun test-render-4 ()
"This example works as expected"
(spinneret:with-html-string
(:p "Before")
(:p (custom "First")
(custom "Second")
(custom "Third"))
(:p "After")))
#|
SPINNERET-RENDER-TEST> (test-render-5)
"<p>Before
<p>After"
Expected result:
"<p>Before
First Second Third
<p>After"
|#
(defun test-render-5 ()
(spinneret:with-html-string
(:p "Before")
(spinneret:with-html
(custom "First")
(custom "Second")
(custom "Third"))
(:p "After"))) Is it possible to make spinneret call |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tests. I'll have a look. |
Beta Was this translation helpful? Give feedback.
-
I don't think it is possible to make spinneret capture the output of top-level "unwrapped" elements. |
Beta Was this translation helpful? Give feedback.
-
Well, I think this feature is useful anyway. It is just needed to be documented propertly. I'll add a method for spinneret:html today. |
Beta Was this translation helpful? Give feedback.
-
Here is PR: #76 Now Reblocks documentation mentions how to use alternative HTML template engines! |
Beta Was this translation helpful? Give feedback.
-
That's great! Btw, I think docs regarding widget rendering could be expanded a bit here: https://40ants.com/reblocks/rendering/#x-28REBLOCKS-2FDOC-2FRENDERING-3A-3A-40WIDGETS-2040ANTS-DOC-2FLOCATIVES-3ASECTION-29 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using this helper for rendering widgets without explicitly having to invoke
render
:Just a detail, but allows rendering widgets like:
no explicit call to
render
in spinneretwith-html
templates.Beta Was this translation helpful? Give feedback.
All reactions