Dependencies ΒΆ
When Reblocks renders page, it collects CSS
and JS
dependencies from all widgets
by calling generic-function reblocks/dependencies:get-dependencies
. Also, this function
is called on the current app to get such common dependencies as jQuery and CSS
framework.
If you are defining your own method for reblocks/dependencies:get-dependencies
generic-function,
make sure it returns a list of reblocks/dependencies:dependency
objects.
Typically, you already have JS
or CSS
file somewhere near your ASDF
system. In this case,
you can use reblocks/dependencies:make-dependency
function like this:
(defmethod reblocks/dependencies:get-dependencies ((app my-app))
(list* (reblocks/dependencies:make-dependency "js/my-app.js"
:system :some-asdf-system)
(call-next-method)))
Other way to specify a dependency is to use Parenscript or LASS
to define JS
or CSS
right inside
the method. Here we define CSS
code for the widget:
(defmethod reblocks/dependencies:get-dependencies ((widget my-custom-widget))
(list*
(reblocks-lass:make-dependency
`(.my-custom-widget
:border 2px solid red
:padding 1em))
(call-next-method)))
Pay attention, this code uses REBLOCKS-LASS:MAKE-DEPENDENCY
function which is available from
the separate asdf system REBLOCKS-LASS
.
API
-
[class]
This class represents a web-dependency. It could be
CSS
,JS
or an image.All dependencies are divided into
remote-dependency
orlocal-dependency
.
-
[class]
Remote dependencies refer some
URL
s. Usually these dependencies are served from aCDN
.
-
[class]
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.
-
[variable]
nil
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.
-
[function]
dependency
Returns a
MIME
content type for given dependency.It is used when dependency is served locally.
- [reader] (:CROSSORIGIN = "anonymous")
-
[reader]
(:integrity = nil)
A hash, used by modern browsers for subresource integrity checking.
See more information at: https://www.w3.org/TR/SRI/
-
[generic-function]
dependency
Returns a path on local disk to serve dependency from.
This could be a real source file or a cached version of remote dependency.
-
[generic-function]
dependency
This method should return a routes:route object if dependency should ber served from local server.
- [reader] (:TYPE = (ERROR ":type argument is required."))
-
[generic-function]
dependency
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.
-
[reader]
(:cache-in-memory = nil)
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.
-
[generic-function]
path-or-url
Returns a keyword meaning content type of the dependency by infering it from
URL
or a path
-
[function]
dependency
Pushes dependency into the currently collected list of dependencies.
Makes deduplication by comparing dependencies' urls.
-
[function]
list-of-dependencies
Same as `push-dependency' but for the list.
-
[generic-function]
dependency
Returns a
JS
code to dynamically include aCSS
orJS
dependency into a webpage onAJAX
response.This makes possible to load new styles and code for widgets which can appear on a page as a response to some action.
-
[generic-function]
dependency
Renders a piece of html.
-
[generic-function]
dependency
Returns two values - content and content-type.
Example output::
(values "body {background: light-green;}" "text/css")
-
[macro]
&body body
Use this macro to wrap code which may push new dependencies for the page or an action.
-
[function]
path-or-url &key system type integrity crossorigin
cache-in-memory
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.
-
[generic-function]
object
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
.