Widgets
Widget objects should be subclasses of the reblocks/widget:widget class.
Also, minimally you have to define a method for the
reblocks/widget:render generic function. This function should
use the reblocks/html:with-html macro to render the widget.
Other parts of the API around widgets are:
reblocks/dependencies:get-dependencies- returns a list ofCSS/JSdependencies.reblocks/widget:update- marks a widget as needing to update on the frontend.reblocks/widget:get-html-tag- returns anHTMLtag instead of the standardDIV.reblocks/widget:get-css-classes- returns a list ofCSSclasses. By default returns:WIDGETand the widget class's name.reblocks/widget:create-widget-from- returns a widget for representing an object. This way widgets can be created out of strings, functions, etc.
Example
To define a widget, use the reblocks/widget:defwidget macro. It creates a class
with a proper meta-class. The old Weblocks version used this metaclass to
discover slot changes, and probably this feature will be returned some day.
CL-USER> (reblocks/widget:defwidget hello ()
((name :initarg :name
:reader get-name)))
#<REBLOCKS/WIDGETS/MOP:WIDGET-CLASS COMMON-LISP-USER::HELLO>
CL-USER> (defmethod reblocks/widget:render ((widget hello))
(reblocks/html:with-html ()
(:span ("Hello ~A" (get-name widget)))))
#<STANDARD-METHOD REBLOCKS/WIDGET:RENDER (HELLO) {1004E27BC3}>Then call this to run a webserver and preview your widget in the browser:
CL-USER> (reblocks/preview:preview
(make-instance 'hello
:name "Bob"))The result will look like this:
String widget
This is a simple type of widget which can be made out of any string.
Create it using the reblocks/widgets/string-widget:make-string-widget function.