Content Rendering

Page Rendering

generic-function
app inner-html &key dependencies

Renders HTML page for the current application.

By default, it renders:

By default, it just renders BODY-HTML-STRING as is, without escaping.

BODY-HTML-STRING argument contains a rendered widget tree, generated by reblocks/widget:render generic-function call on the root widget.

Renders links to CSS and JS dependencies.

DEPENDENCIES argument contains a list of objects inherited from reblocks/dependencies:dependency class.

These functions can be used during rendering to retrieve an information about the page.

Render protocol first renders the widget tree and only after that renders page HTML headers. Thus you might use setf on these functions during widget rendering to change the title, description or keywords.

If you want to change these variables globally for the whole application, then define a before method like this:

(defmethod reblocks/page:render :before ((app disk-analyzer) inner-html &rest rest)
  (declare (ignore rest))

  (setf (reblocks/page:get-title)
        "Cloud Analyzer - Saves space and money!")
  (setf (reblocks/page:get-description)
        "Helps to save money when storing data in the Cloud.")
  (setf (reblocks/page:get-keywords)
        (list "cloud"
              "storage"
              "analyzer")))

HTML Rendering

Out of the box, Reblocks provides a few facilities for HTML generation. They are based on Spinneret templating engine. Old version of Weblocks used CL-WHO instead. But Spinneret is more flexible and what is more important, it escapes content by default, preventing HTML injection vulnerability.

Most of the time, you only will need a reblocks/html:with-html macro, which is similary to Spinneret's one, but binds a few special variables to a stream to write output to and how to write it:

(reblocks/html:with-html
   (:ul
    (:li "One")
    (:li "Two")
    (:li "Three")))
;.. <ul>
;..  <li>One
;..  <li>Two
;..  <li>Three
;.. </ul>
;=> NIL

Sometimes you might want to get a HTML string instead. In this case you might use reblocks/html:with-html-string:

(reblocks/html:with-html-string
   (:ul
    (:li "One")
    (:li "Two")
    (:li "Three")))
;..
;=> "<ul>
;->  <li>One
;->  <li>Two
;->  <li>Three
;-> </ul>"

You can use any other templating engine, just ensure it writes output to the reblocks/html:*stream* variable.

For more advanced UI, look at the REBLOCKS-UI documentation.

API

Renders body using Spinneret HTML generator.

Like with-html, but capture the output as a string.

variable
#<synonym-stream :symbol *standard-output* {1007f6a233}>

Reblocks will write all output into this stream.

This stream is created for each request and available to code executed within a request as a special variable. All html should be rendered to this stream, but don't worry, if you are using with-html or with-html-string macroses, they handle this for you.

Language to add into the root html element.

We want an HTML nice to read by default.