API

REBLOCKS/ACTIONS

Generics

Evaluates the action that came with the request.

First it resolves action by trying to find ACTION-NAME inside session or current app's actions. If actions wasn't found, then eval-action calls on-missing-action generic-function. Otherwise it applies arguments to the action callback.

Must be overridden by application to prevent default behaviour - redirect to a root of the application. The new method should determine the behavior in this situation (e.g. redirect, signal an error, etc.).

Functions

Accepts a function or an existing action. If the value is a function, adds it to the session actions and returns its unique code as a string. Otherwise, checks if the action already exists. If it does, returns the argument as is. If it does not, signals an error.

function
function-or-action-code &key (keep-query-params t)

Accepts action code and returns a URL that can be used as href attribute of HTML link.

For example:

(reblocks/app:defapp test-app :autostart nil)

(let* ((reblocks/request::*request*
         (lack.request:make-request
          (list :path-info "/blah/minor"
                :headers (make-hash-table))))
       (app (make-instance 'test-app)))
  (reblocks/app:with-app (app)
    (reblocks/app-actions:define-action test-action test-app ())
    (reblocks/actions:make-action-url "test-action")))
=> "/blah/minor?action=test-action"

If KEEP-QUERY-PARAMS is true (default), then all query arguments are preserved and will be passed as arguments to the action.

Returns JS code which can be inserted into onclick attribute and will execute given Lisp function on click.

It accepts any function as input and produces a string with JavaScript code.

Returns JS code which can be inserted into onsubmit form's attribute.

It accepts any function as input and produces a string with JavaScript code.

On form submit given action will be executed and all input values will be passed as arguments.

REBLOCKS/APP

Classes

APP-ROUTES

Readers

App instance will be set during server initialization.

Accessors

App instance will be set during server initialization.

APP

A class that encapsulates a unique web application and all relevant rnesources. A webapp is a unique set of dependencies and information that can be enabled or disabled independently of others. Multiple webapps can be active concurrently and incoming connections are dispatched to the root of the webapp according to a prefix parameter that defines the URLs parsed by that webapp. The webapp does not see the prefix parameter in URLs that are provided to it. You can, for instance, have different sites (e.g. mobile vs. desktop) with vastly different layout and dependencies running on the same server.

Readers

The subtree of the URI space at this site that belongs to the webapp.

reader
(:page-constructor = #'identity)

Generics

A protocol for performing any special initialization on the creation of a webapp object.

Functions

Macros

macro
name &rest initargs &key prefix routes page-constructor subclasses slots description documentation (autostart t) &allow-other-keys

This macro defines the key parameters for a stand alone web application.
It defines both a class with name 'name' and registers an instance of that class. It also instantiates a defvar with an instance of this class. This is intended to be the primary way a web application is defined.

PREFIX - an URI from where this app should be available on the server. Read more about this in the Routing section.

ROUTES - an object of 40ants-routes/routes:routes class holding routes relative to the given prefix.

page-constructor - a callable of one argument which accepts a widget bound to a route and returns a root widget for the page.

SUBCLASSES - if you want to inherit subclass behavior from other webapps, you can. It's not likely to be needed much

SLOTS - webapps are class so slots are a list of definitions just as in defclass, but as slots are likely to be rare on webapps, we make this a keyword argument.

All of the following, when present, are passed through as additional initargs:

NAME - instantiates a username (and the default title for) a webapp. use this name to get and delete this webapp. Multiple instances of a webapp class can co-exist, so long as they have different prefixes

DESCRIPTION - A description of the application for the title page

DOCUMENTATION - Content of this argument will be added as (:documentation ...) form to the class definition.

AUTOSTART - Whether this webapp is started automatically when start-reblocks is called (primarily for backward compatibility

Bind variable *current-app* to the given APP argument.

REBLOCKS/APP-ACTIONS

Functions

function
app-class action-name function-or-name

Remove an action from a webapp. action-name should be a string, or it will be converted to one (to work with the macro). function-or-name is a symbol or a function object (valid object for funcall)

Returns the action function associated with this symbol in the current app

Removes a permanent action from a webapp

Macros

macro
name app-class action-params &body body

Adds a permanent action to the class's set of permanent actions

REBLOCKS/APP-MOP

Functions

REBLOCKS/CACHED-DEPENDENCIES-MIXIN

Classes

CACHED-DEPENDENCIES-MIXIN

If your widget might return a slightly different code from it's get-dependencies generic-function method, these dependencies will be consided different and every-time loaded into the page.

Sometimes this happens with JS, generated by Parenscript, because it uses GENSYM in the LET form. But actually code is the same and there is no need to load it again when the widget is updated.

Readers

Boolean flag. When T then result of get-dependencies generic-function will be cached. By default is True, but you might turn it off while debugging the application.

Accessors

Boolean flag. When T then result of get-dependencies generic-function will be cached. By default is True, but you might turn it off while debugging the application.

REBLOCKS/COMMANDS

Functions

Pushes a new command into the stack.

After action processing these commands will be sent for execution on the client.

Pushes all commands from the list into the stack.

After action processing these commands will be sent for execution on the client.

Returns all commands created during AJAX request processing in order as they where added.

Macros

Collects commands added using a call to add-commands during the body execution.

Commands list can be aquired using get-collected-commands function.

REBLOCKS/DEBUG

Functions

Returns a value from the latest session.

function
&key (track-latest-session t) (debug-actions t) (track-latest-request t) (invoke-debugger-on-error t)

Resets the latest session when debug mode is on.

Variables

Stores last request if debug mode was enabled.

Stores last session, to be able to clear it during development.

To clear, use function (reset-last-session).

REBLOCKS/DEPENDENCIES

Classes

DEPENDENCY

This class represents a web-dependency. It could be CSS, JS or an image.

All dependencies are divided into remote-dependency or local-dependency.

Readers

reader
(:TYPE = (ERROR ":type argument is required."))

LOCAL-DEPENDENCY

Local dependencies are served by the same webserver which renders reblocks widgets.

Each local dependency should provide a route, which will be added to the server routing table. Also, it might define a path to the file on the local file-system.

Readers

When true, then on creation dependency will read file's data into the memory. This is useful for applications, deployed as a single executable file. Create such dependencies in compile time and store in a global variable.

REMOTE-DEPENDENCY

Remote dependencies refer some URLs. Usually these dependencies are served from a CDN.

Readers

A hash, used by modern browsers for subresource integrity checking.

See more information at: https://www.w3.org/TR/SRI/

Generics

Should return T if two dependencies are considered equal. By default compares their URLs.

Returns a list of object's dependencies.

Object could be an application or a widget. Reblocks will call this method for application and every widget on a page to gather necessary dependencies and to inject them into resulting HTML.

Returns URL of the dependency.

If dependency should be served by the server, second value is :local. Otherwise it is :external. Also, in first case dependency's URL should have only path part, like /local/css/bootstrap.css.

Returns a keyword meaning content type of the dependency by infering it from URL or a path

Returns a JS code to dynamically include a CSS or JS dependency into a webpage on AJAX response.

This makes possible to load new styles and code for widgets which can appear on a page as a response to some action.

Returns two values - content and content-type.

Example output::

(values "body {background: light-green;}" "text/css")

Functions

Returns a MIME content type for given dependency.

It is used when dependency is served locally.

function
path-or-url &key system type integrity crossorigin cache-in-memory defer

Creates a JavaScript dependency, served from the disk.

If the system's name is given, then the path is calculated relatively to this system's source root.

Variables

If this variable is set to a pathname, then remote dependencies will be cached and served as local dependencies.

This pathname should point to a directory where cached dependencies will be stored.

REBLOCKS/DOC/EXAMPLE

Classes

REBLOCKS-EXAMPLE

Readers

The code before any transformations. Used when some example inherits another example.

This slot will contain a package, created for especially this example's body.

Macros

macro
NAME (&KEY (WIDTH "100%") (HEIGHT "10em") (INHERITS NIL) (SHOW-CODE-TAB T)) &BODY BODY

Defines Reblocks app example.

Body should contain a code snippet which includes

TODO: write a doc

When creating a server part, the BODY form will be evaluated as part of the new anonymous package.

Variables

This variable can be used to point to a production server for showing documentation examples.

REBLOCKS/ERROR-HANDLER

Generics

This method is called when some unhandled error was raised by application. It should call reblocks/response:immediate-response like this:

(reblocks/response:immediate-response
    "Unhandled condition"
    :code 500)

REBLOCKS/HOOKS

Functions

This function should be called inside a body, surrounded by ON-APPLICATION-HOOK-…, ON-SESSION-HOOK-… or a ON-REQUEST-HOOK-… type of macro.

Macros

macro
app action-name action-arguments

Called when action is processed.

Returns a result of reblocks/actions:eval-action generic-function application to the arguments.

Called around code reponsible for an HTTP request processing, before any application was choosen.

Accepts Lack's HTTP request environment.

Should return a list of three items:

  • HTTP status code;

  • a plist of HTTP headers;

  • a list of strings corresponding to the page's content.

Called when an reblocks documentation example is being defined.

Called when around whole page or ajax request processing. Should return HTML string.

Called when session is resetted for some reason.

Called around code which starts all applications and a webserver.

Returns a reblocks server object.

Called around code which stops all applications and a webserver.

Returns a reblocks server object.

macro
name (&rest args) &optional docstring

Registers a hook

macro
callback-name (app action-name action-arguments) &body body

Called when action is processed.

Returns a result of reblocks/actions:eval-action generic-function application to the arguments.

Called around code reponsible for an HTTP request processing, before any application was choosen.

Accepts Lack's HTTP request environment.

Should return a list of three items:

  • HTTP status code;

  • a plist of HTTP headers;

  • a list of strings corresponding to the page's content.

Called when an reblocks documentation example is being defined.

Called when around whole page or ajax request processing. Should return HTML string.

Called when session is resetted for some reason.

Called around code which starts all applications and a webserver.

Returns a reblocks server object.

Called around code which stops all applications and a webserver.

Returns a reblocks server object.

macro
callback-name (app action-name action-arguments) &body body

Called when action is processed.

Returns a result of reblocks/actions:eval-action generic-function application to the arguments.

Called around code reponsible for an HTTP request processing, before any application was choosen.

Accepts Lack's HTTP request environment.

Should return a list of three items:

  • HTTP status code;

  • a plist of HTTP headers;

  • a list of strings corresponding to the page's content.

Called when an reblocks documentation example is being defined.

macro
callback-name (app) &body body

Called when around whole page or ajax request processing. Should return HTML string.

macro
callback-name (session) &body body

Called when session is resetted for some reason.

Called around code which starts all applications and a webserver.

Returns a reblocks server object.

Called around code which stops all applications and a webserver.

Returns a reblocks server object.

macro
callback-name (app action-name action-arguments) &body body

Called when action is processed.

Returns a result of reblocks/actions:eval-action generic-function application to the arguments.

Called around code reponsible for an HTTP request processing, before any application was choosen.

Accepts Lack's HTTP request environment.

Should return a list of three items:

  • HTTP status code;

  • a plist of HTTP headers;

  • a list of strings corresponding to the page's content.

Called when an reblocks documentation example is being defined.

macro
callback-name (app) &body body

Called when around whole page or ajax request processing. Should return HTML string.

macro
callback-name (session) &body body

Called when session is resetted for some reason.

Called around code which starts all applications and a webserver.

Returns a reblocks server object.

Called around code which stops all applications and a webserver.

Returns a reblocks server object.

macro
(app action-name action-arguments) &body body

Called when action is processed.

Returns a result of reblocks/actions:eval-action generic-function application to the arguments.

Called around code reponsible for an HTTP request processing, before any application was choosen.

Accepts Lack's HTTP request environment.

Should return a list of three items:

  • HTTP status code;

  • a plist of HTTP headers;

  • a list of strings corresponding to the page's content.

Called when an reblocks documentation example is being defined.

Called when around whole page or ajax request processing. Should return HTML string.

Called when session is resetted for some reason.

Called around code which starts all applications and a webserver.

Returns a reblocks server object.

Called around code which stops all applications and a webserver.

Returns a reblocks server object.

REBLOCKS/HTML

Macros

macro
(&key (pretty nil) (lang nil)) &body body

Renders body using Spinneret HTML generator.

macro
(&key (pretty nil) (lang nil)) &body body

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

Variables

Language to add into the root html element.

We want an HTML nice to read by default.

variable
#<synonym-stream :symbol *standard-output* {1208bf8953}>

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.

REBLOCKS/JS

Classes

JS-BACKEND

Generics

Creates a js backend instance of a given name.

Name should be a keyword like a :jquery or a :prototype.

Macros

Places 'source' between script and CDATA elements. Used to avoid having to worry about special characters in JavaScript code.

Places 'source' between script and CDATA elements. Used to avoid having to worry about special characters in JavaScript code.

REBLOCKS/JS/BASE

Classes

JS-BACKEND

Generics

Creates a js backend instance of a given name.

Name should be a keyword like a :jquery or a :prototype.

Macros

Places 'source' between script and CDATA elements. Used to avoid having to worry about special characters in JavaScript code.

Places 'source' between script and CDATA elements. Used to avoid having to worry about special characters in JavaScript code.

REBLOCKS/PAGE

Classes

PAGE

Readers

reader
(= (make-hash-table :test 'equal))
reader
(:app = \*current-app\*)
reader
(= (make-v4-uuid))

Accessors

accessor
(:app = \*current-app\*)

Generics

Should return a string of CSS classes for the body HTML element or NIL.

Returns NIL or a number of seconds after which page should be removed from the memory.

Default method returns current value of *extend-page-expiration-by* variable or *pages-expire-in* variable.

A method for this generic function should be defined to initialize a new page object.

It should return a widget which become a root widget of the page or it might return the page with initialized root widget in case if you want to use your own subclass of the page class.

Returns NIL or a maximum number of pages to keep in the session. Older pages will be expired and free memory.

Default method returns current value of *max-pages-per-session* variable.

This generic function gets called when user loads a page in the browser. It is called for all non Ajax requests.

When user reloads page multiple times, the page object can be reused. Thus this function may be used to reset some page attributes.

Default method resets a list of loaded dependencies to ensure that all of them will be sent to the browser again.

This generic function gets called when user get's a redirect to another page.

Default method does nothing.

This generic function gets called when user refreshes page in the browser.

Default method does nothing.

Returns NIL or a number of seconds after which page should be removed from the memory.

Default method returns current value of *pages-expire-in* variable.

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.

By default, adds entries with Content-Type, description and keywords to the app's page.

Functions

Returns current page object. Can be useful to pass to call page-metadata.

Extends expiration time of the current page.

Returns a page from a current session by it's id.

Returns T when current-page function will be able to return page instead of throwing an error.

Returns a metadata with NAME, bound to the current page

Macros

macro
page name &optional default

Like page-metadata, but if metadata piece with NAME is not found saves the DEFAULT before returning it. Secondary return value is true if NAME was already in the metadata.

REBLOCKS/PAGE-DEPENDENCIES

Functions

Returns T, if dependency is already loaded into the page.

Returns as list of dependencies loaded into the page. Most recently loaded go first.

Same as `push-dependency' but for the list.

Pushes dependency into the currently collected list of dependencies.

Makes deduplication by comparing dependencies' urls.

Macros

Use this macro to wrap code which may push new dependencies for the page or an action.

REBLOCKS/PREVIEW

Classes

PREVIEW

Functions

REBLOCKS/REQUEST

Functions

function
&key (request \*request\*)

Detects if the current request was initiated via AJAX by looking for X-Requested-With http header. This function expects to be called in a dynamic hunchentoot environment.

function
name &key (request \*request\*)

Returns value of the cookie or nil. Name is case insensitive string.

function
name &key (request \*request\*)

Returns value of the HTTP header or nil. Name is case insensitive.

function
&key (request \*request\*)
function
&key (request \*request\*)

Returns association list with GET or POST parameters for current request.

function
name &key (request \*request\*)

Returns GET or POST parameter by name.

function
&key (request \*request\*)

Returns association list with GET or POST parameters for current request.

function
&key (request \*request\*) with-params

For URL http://example.com/foo/bar?blah=minor returns /foo/bar path of the request's URL.

function
&key (request \*request\*)

Returns a webserver's port.

It may be not a port a lisp server listens on but a port a reverse proxy listens on.

function
&key (request \*request\*)

Returns a possible user's IP.

Note, it may not be reliable, because user might try to set these headers manually.

function
&key (request \*request\*)
function
&key (request \*request\*)

For URL http://example.com/foo/bar?blah=minor returns it as is.

Detects if the current request is declared as 'pure', i.e. affects no widgets or internal application state, but merely is a request for information.

Such requests simply return the result of the function that represents the action and are used by some AJAX operations to retreive information (suggest block, etc).

When such requests are satisfied, the actions have access to the session, the widgets, and all other parameters. However, none of the callbacks are executed, no widgets are sent to the client, etc.

Determines if a request is a result of the user invoking a browser refresh function. Note that a request will not be considered a refresh if there is an action involved (even if the user hits refresh).

function
name &key (request \*request\*)

Removes a HTTP header by name, returns new instance of request without given header.

Macros

This macro binds current request and stores request path in the session if requiest is not AJAX.

Later, this value is used to determine if user refreshed the page.

REBLOCKS/REQUEST-HANDLER

Generics

This generic function is called when Reblocks processes an action called from Javascript.

REBLOCKS/RESPONSE

Classes

IMMEDIATE-RESPONSE

Readers

NOT-FOUND-ERROR

Readers

REDIRECT

Functions

Use this function to add a HTTP header:

(add-header :x-request-id "100500")
function
uri &key (retpath (get-uri))

Adds a "retpath" GET parameter to the giving URL.

Keeps all other parameters and overwrites "retpath" parameter if it is already exists in the URL.

By default, retpath is the current page, rendered by the reblocks. This is very useful to redirect user to login page and return him to the same page where he has been before.

function
&optional (response \*response\*)

Returns a list with a map cookie-name -> cookie:cookie object. Odd items in this list are cookie names and even are lists with cookie parameters.

function
&optional (response \*response\*)

Function get-code is deprecated. Use status-code instead.

function
&optional (response \*response\*)
function
&optional (response \*response\*)
function
&optional (response \*response\*)

Function get-custom-headers is deprecated. Use get-headers instead.

function
&optional (response \*response\*)
function
content &key (condition-class 'immediate-response) (code 200) content-type headers cookies-to-set

Aborts request processing by signaling an immediate-response and returns a given value as response.

HTTP code and headers are taken from CODE and CONTENT-TYPE.

By default, headers and cookies are taken from the current request, but additional headers and cookies may be provides in appropriate arguments.

function
content &key (code 200) (content-type (get-default-content-type-for-response)) (headers (get-headers))

Makes a new URL, based on the current request's URL.

Argument NEW-PATH can be absolute, like /logout or relative, like ./stories.

Also, it can contain a query params like /login?code=100500

By default, function takes a base-uri from the current request, bun in case if you want to call the function in a context where request is not available, you can pass BASE-URI argument explicitly.

Signals an error about not found page or object.

As the first argument you should pass a widget which will be shown as the error page's content. Also you migth pass a string, in this case content widget will be created automatically.

Redirects the client to a new URI.

function
script &optional (place :after-load)

Send JavaScript to the browser. The way of sending depends on whether the current request is via AJAX or not.

Script may be either a string or a list; if it is a list it will be compiled through Parenscript first.

function
cookie &key (response \*response\*)

Use this function to add Set-Cookie header:

(set-cookie (list :name "user_id" :value "bob" :samesite :lax))

Cookie might include these properties:

  • domain

  • path

  • expires

  • secure

  • httponly

  • samesite

function
&optional (response \*response\*)

Returns a status code to be returned in response to the current request.

You can use SETF to change the status code:

(setf (reblocks/response:status-code)
      404)

REBLOCKS/ROUTES

Classes

PAGE-ROUTE

SERVER-ROUTES

STATIC-FILE-ROUTE

The class of route for serving static file from the local disk.

Readers

STATIC-ROUTE

The class of route for serving static file. Content of this file could be on a local disk or can be fetched from some other place.

Generics

Returns a routes object bound to a server or application.

Methods should return a list like that:

(list 200                                ;; status-code
      (list :content-type content-type)  ;; headers
      content)                           ;; content

Functions

function
route-class &key (routes-path 40ants-routes/vars::\*routes-path\*)
function
PATH PATHNAME &KEY (CONTENT-TYPE "text/plain") NAME TITLE

Creates a route item for serving a static file from the local disk.

Macros

macro
(path &key name title) &body handler-body

REBLOCKS/SERVER

Classes

SERVER

Base class for all Reblocks servers. Redefine it if you want to add additional HTTP midlewares, etc.

Readers

reader
(= (reblocks/server::make-initial-server-routes))
reader
(:request-timeout = \*default-request-timeout\*)

Seconds until we abort a request because it took too long. This prevents threads from hogging the CPU indefinitely.

You can set this to NIL to disable timeouts (not recommended).

Generics

Handles HTTP request, passed by Clack

Returns an alist where keys are keywords and values are Lack middlewares or apps.

Default primary method returns alist with two keys :SESSION and :APP, where :SESSION is a middleware and :APP is the main application.

To modify middlewares list, define method for a server subclass and use insert-middleware function on the results of CALL-NEXT-METHOD.

SAMESITE-POLICY argument if given, should be a keyword. It's semantic is described at Mozilla docs. It's default value is taken from *default-samesite-policy* variable.

Here is an example, how this generic-function can be used to run a HTTP API on URLs with path starting from /api/:

(defmethod reblocks/server:make-middlewares ((server ultralisp-server) &rest rest)
  (declare (ignore rest))

  (flet ((test-app (env)
           (declare (ignore env))
           '(200
             (:content-type "text/plain")
             ("Hello, World"))))
    (reblocks/server:insert-middleware
     (call-next-method)
     (cons
      :some-api
      (lambda (app)
        (funcall (lack.util:find-middleware :mount)
                 app
                 "/api/"
                 #'test-app)))
     :before :app)))

Functions

function
layers new-layer &key before after

Returns a new stack of layers inserting NEW-LAYER before or after a layer with given name.

You should not give both BEFORE and AFTER arguments. If layer with given name was not found, the function will signal error.

Original alist LAYERS is not modified.

Returns T if server is running and NIL otherwise.

function
&optional interface port

Returns a list of Reblocks servers.

function
&KEY (DEBUG T) (PORT 8080) (INTERFACE "localhost") (SERVER-TYPE :HUNCHENTOOT) (SAMESITE-POLICY :LAX) APPS (SERVER-CLASS 'SERVER) (REQUEST-TIMEOUT \*DEFAULT-REQUEST-TIMEOUT\*) (DISABLE-WELCOME-APP NIL)

Starts reblocks framework hooked into Clack server.

Set DEBUG to true in order for error messages and stack traces to be shown to the client (note: stack traces are temporarily not available due to changes in Hunchentoot 1.0.0).

Server will start all apps declared having autostart t in their definition unless APPS argument is provided.

Sometimes you might want your app respond on /some-uri and / return 404. In this case it is useful to set DISABLE-WELCOME-APP argument to T.

function
&optional interface port

Stops Reblocks servers matching given INTERFACE and PORT.

This function deactivates all applications bound to the server and stopps a Clack server.

Returns stopped server objects.

Variables

Default value for SameSite header.

You will find more at Mozilla docs.

REBLOCKS/SESSION

Generics

A method for this generic function should be defined to initialize application for a new user session.

It should return a widget which become a root widget.

A method for this generic function should be defined to initialize application for a new user session.

On the moment it get called session has-map already exists and you can use get-value function to set some values.

Functions

Clear the session value for the currently running app.

KEY is compared using EQUAL.

Deletes current session id for the browser.

On the next HTTP request a new session will be created.

function
&OPTIONAL (PREFIX "dom")

Generates an ID unique accross the session. The generated ID can be used to create IDs for html elements, widgets, etc.

Returns a number of sessions where :user key is NIL.

function
key &optional (default nil default-given-p)

Get a session value from the currently running webapp. KEY is compared using EQUAL.

Checks if session is active and data can be safely retrived or stored.

function
&key (samesite-policy :lax) (public-session-keys (list (cons "reblocks/page" "session-pages")))

Reset current session.

Macros

Sets dynamic binding for session and env

REBLOCKS/UTILS/CLOS

Generics

Returns an object's class name (i.e. "Employee"). This method is be used to present the name of an entity to the user. Override this method to change the name for particular objects.

Functions

Returns a direct-slot-definition object of a slot with 'slot-name' in 'class'.

Returns an effective-slot-definition object of a slot with 'slot-name' in 'class'.

function
o1 o2 &key exclude (test #'equal)

Whether O1 and O2 have identical slot contents, excluding slot names in EXCLUDE.

Two slots are considered equal if they are either both unbound or if they are both bound and pass TEST.

Signals an error when the slot names of O1 and O2 don't match.

Retrieves a value of a slot from a hierarchy of objects. A nil on the path is ignored.

ex:

(slot-value-by-path employee '(address street)) => "17 Sunvalley St."

(slot-value-by-path employee '(address)) => #<ADDRESS {XXX}>

(slot-value-by-path employee 'address) => #<ADDRESS {XXX}>

(slot-value-by-path address '(street)) => "17 Sunvalley St."

(slot-value-by-path address '(nil street)) => "17 Sunvalley St."

obj - a CLOS object path - a list of slot names

REBLOCKS/UTILS/I18N

Functions

Translates given string by calling translation-function with string and 'scope'. 'scope' is a set of function key arguments which can be :accusative-form-p :genitive-form-p :items-count :preceding-count

Variables

A function of two arguments: string and scope.

REBLOCKS/UTILS/LIST

Functions

Converts an alist to plist.

Returns a copy of the list without the last element.

function
sequence predicate &key (key #'identity)

Returns a sequence of all elements found in 'sequence' that match 'predicate'. If 'key' is provides, each it is used to retreive each item before passing it to 'predicate'.

Destructively inserts 'newelt' into 'list' after 'index'.

Destructively inserts 'newelt' into 'list' before 'index'.

function
list delimeter &key (last delimeter)

Intersperses a list with a delimeter.

If 'last' is specified, it will be used for the last delimeter, instead of 'delimeter'.

(intersperse '(1 2 3 4 5) 0) => (1 0 2 0 3 0 4 0 5)

Nondestructively convert a list of elements to an association list If an element of a list is a cons cell, it is left as is. Otherwise, it is replaced with a cons cell whose 'car' is the element and whose 'cdr' is a result of 'map' applied to the element. The 'map' is an identity by default.

Ex: (list->assoc '(name age (city . location))) => ((name . name) (age . age) (city . location)) (list->assoc '(1 (2 . 2) 3) :map #'1+) => ((1 . 2) (2 . 2) (3 . 4))

Determines if a list starts with the given elements.

Removes a keyword parameter from a parameter-list. (remove-keyword-parameter '(1 2 3 :a 1 :b 2 :c 3) :b) => (1 2 3 :a 1 :c 3)

Like GETF but copes with odd argument lists. Extracts the first value whose predecessor matches NAME. Returns NIL as second value if the key wasn't found at all.

function
sequence start &optional end

A safe alternative to subseq that automatically adjust indices.

function
list-1 list-2 &key (test #'eql) (key #'identity)

Returns a list of element of 'list-1' that do not appear in 'list-2'.

REBLOCKS/UTILS/MISC

Functions

Appends 'custom-fields' to the end of custom fields that are already defined in 'args'.

function
name &optional (package nil packagep)

Like `find-symbol', but reject symbols not really in PACKAGE.

Returns true if the object is a function designator.

function
input output &key (if-exists :supersede) (if-does-not-exist :create) (minimum-length 300)

Redefined salsa2:gzip-file with more keywords.

Returns all keys in the hashtable.

Infer FILENAME's relative path and extension from TYPE.

Example:

(public-file-relative-path :stylesheet "navigation") => "stylesheets/navigation.css"

A helper function that returns a list of paths for files provided in 'args'. Each argument must be a cons cell where car is either :stylesheet or :script and cdr is a name of the file.

Useful when generating a list of dependencies for widgets and/or the application (see the 'dependencies' generic function and application-dependencies.)

Ex: (get-public-files-paths '(:stylesheet . "navigation") '(:script . "effects")) => (#P"stylesheets/navigation.css" #P"scripts/effects.js")

Apply 'fn' if it isn't nil. Otherwise return nil.

Funcall 'fn' if it isn't nil. Otherwise return nil.

function
filepath &key (element-type 'base-char)

Returns a status of 'symbol' in its package (internal, external, etc.)

Macros

macro
(stream-name path &key (element-type ''base-char)) &body body

Ensures that directories exists, then opens a file for write and executes a body.

REBLOCKS/UTILS/STRING

Generics

Convert objects to a format suitable for serialization (in particular for markup languages like HTML).

Ex: (attributize-name 'hello-world) => "hello-world"

Convert objects to a human-readable string suitable for presentation. Default implementations beautify strings and symbols.

Ex:

(humanize-name 'hello-world) => "Hello World"

(humanize-name "HELLO-WORLD") => "Hello World"

Functions

Condense multiple consecutively occuring slashes in STR into a single slash.

ex:

(remove-spurious-slashes "/ab/////c///")
=> "/ab/c/"

If string 'str' starts with 'prefix', remove 'prefix' from the start of 'str'.

If string 'str' ends with 'suffix', remove 'suffix' from the end of 'str'.

Returns true if every character in a string is a whitespace character, nil otherwise.

REBLOCKS/UTILS/TIMING

Macros

Variables

When this var is T then some parts of request will log timings.

variable
#<FUNCTION (LAMBDA (NAME REAL CPU) :IN "/home/runner/work/reblocks/reblocks/src/utils/timing.lisp") {B80162439B}>

A function of (name real and cpu) to log timing results. By defaults, logs with debug level using log4cl.

REBLOCKS/UTILS/URI

Functions

Removes the given parameter from a URI.

REBLOCKS/VARIABLES

Variables

A string used to pass actions from a client to the server. See 'reblocks/request:get-request-action'.

When this variable is T then a backtrace will be logged if there is an error in session initialization.

A currently active web application.

Content type of the pages.

A number of seconds before request processing will be interrupted.

A number of seconds between expired pages cleanup.

A number of seconds to be added to current page expiration time when a new action is processed.

After an action processing page expiration time either will remain the same or become equal to (+ (now) extend-page-expiration-by).

By default, the variable is unbound and the value of *pages-expire-in* is used.

If this variable is T (default), then Reblocks will just refresh the page when an action is called but the page was already expired.

If this variable is t, then Weblocks will start lisp's debugger on unhandled conditions.

A number of pages per session. When it is reached, oldest pages and their actions will be expired. If NIL, then actions will live in memory forever.

A number of seconds before page and it's actions expiration. If NIL, then actions will live in memory forever.

REBLOCKS/WIDGET

Classes

WIDGET

Base class for all widget objects.

Generics

Methods of this generic should return an instance of subclass of reblocks/widget:widget The most obvious cases are transformation of strings and functions into the widget, but these methods are already supplied by Reblocks.

If reblocks/page:init-page returns an object, then create-widget-from will be called on it to create the root widget.

Returns a list of classes for the widget. Classes may be a strings or a keywords. By default, :widget and keyworded class name are returned. Use (list* :new-class (call-next-method)) to add new classes.

This method determines the enclosing tag of the widget.

The return value should either be a keyword like :div, which will be the enclosing tag, or a list of the form (:tag . attributes), where :tag is the enclosing tag (like :div) and attributes is a property list.

The attributes property list has keywords for keys, corresponding to the attribute name and the values are the values of the attribute.

For example:

  • :div - generates <div ...> widget content </div>;

  • (:div :display "flex") - generates (<div ... :display "flex">widget content</div>.

Note on attributes: in the attribute list the following attributes can not be specified, they will be ignored:

  • :class - Use the get-css-classes generic-function to specify these;

  • :id - This is the value of the dom-id slot of the widget, normally automatically managed by reblocks.

The default implementation returns - :td - inside a table row; - :tr - inside a table; - :div - by default.

Define this method to render widget's content.

Use reblocks/html:with-html macro to render HTML. You can use any other templating engine, just ensure it writes output to reblocks/html:*stream*

Outer DIV wrapper will be added automaticall, see get-html-tag generic-function. It will have CSS tags returned by get-css-classes generic-function.

generic-function
w &key inserted-after inserted-before removed

This method should be called to update widget on a client.

Usually this required as a result of an action execution.

In the original Weblocks there was a mark-dirty method. This one replaces it. To make everything easier, the new protocol excludes "propagation". If you need to update other widgets, please define an "update" method for your widget. You can use :before or :after modifiers, to keep the current behavior and to add propagation code.

There are a few optional arguments to control the way how does widget should be updated. They can be useful to not update the whole parent widget.

  • If one of INSERTED-AFTER or INSERTED-BEFORE is given, it should be a widget object to be used as an anchor. This can be useful to not rerender all children of some "list" widget when you adding a new element.

  • When REMOVED argument is T the widget will be removed from the DOM tree.

Macros

macro
name direct-superclasses &body body

A macro used to define new widget classes. Behaves exactly as defclass, except adds reblocks/widgets/mop:widget-class metaclass specification and inherits from reblocks/widget:widget if no DIRECT-SUPERCLASSES are provided.

REBLOCKS/WIDGETS/DOM

Classes

DOM-OBJECT-MIXIN

Represents attributes and functionality common to all DOM-renderable objects.

Generics

Provides a consistent interface to identifying widgets by their DOM id. Returns a string or nil if the object is to have no id.

REBLOCKS/WIDGETS/FUNCALL-WIDGET

Classes

FUNCALL-WIDGET

Functions

Create a widget from a symbol denoting a function.

REBLOCKS/WIDGETS/MOP

Classes

WIDGET-CLASS

A metaclass used for all widget classes. A custom metaclass is necessary to specialize 'slot-value-using-class'.

REBLOCKS/WIDGETS/STRING-WIDGET

Classes

STRING-WIDGET

Readers

Whether to escape the output for HTML.

Accessors

Whether to escape the output for HTML.

Functions

Create a widget from a string.