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:

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.