pub trait JsRuntime: Send {
Show 22 methods
// Required methods
fn set_argument(&mut self, arg: &Value) -> JsResult<()>;
fn load(&mut self, file: &Path, call: bool) -> JsResult<Decoded>;
fn call(
&mut self,
f: FnHandle,
this: This<'_>,
args: &[Value],
settle: Settle,
) -> JsResult<Decoded>;
fn page_open(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
) -> JsResult<PageId>;
fn page_vars(
&mut self,
page: PageId,
f: FnHandle,
keys: &[String],
) -> JsResult<Vec<String>>;
fn page_call(
&mut self,
page: PageId,
f: FnHandle,
set: Option<&str>,
) -> JsResult<Decoded>;
fn page_set(
&mut self,
page: PageId,
key: &str,
value: &Value,
) -> JsResult<()>;
fn page_close(&mut self, page: PageId);
fn reads(&mut self) -> JsResult<Vec<PathBuf>>;
fn loads_changed(&mut self) -> JsResult<Vec<(PathBuf, Decoded)>>;
fn begin_calls(&mut self) -> JsResult<()>;
fn set_filters(&mut self, filters: Filters);
fn template_setup(&mut self, filters: &[String]) -> JsResult<()>;
fn load_template(
&mut self,
file: &Path,
layout: bool,
) -> JsResult<LoadedTemplate>;
fn render(
&mut self,
template: TemplateId,
data: &Value,
first: Option<&Value>,
traps: &[(String, String)],
filters: &mut FilterCall<'_>,
) -> JsResult<Decoded>;
fn verify(&mut self) -> JsResult<()>;
// Provided methods
fn load_config(&mut self, _file: &Path) -> JsResult<Decoded> { ... }
fn begin(&mut self, op: Op<'_>, filters: &mut FilterCall<'_>) -> Begun { ... }
fn finish(&mut self, _waited: Waited) -> Finished { ... }
fn page_once(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
f: FnHandle,
) -> JsResult<Decoded> { ... }
fn page_open_with_vars(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
functions: &[FnHandle],
keys: &[String],
) -> JsResult<(PageId, Vec<Vec<String>>)> { ... }
fn page_run(
&mut self,
page: PageId,
steps: &[PageStep<'_>],
) -> Vec<JsResult<Decoded>> { ... }
}Expand description
A JavaScript runtime that loads data files and calls the functions in them, one request at a time.
Required Methods§
Sourcefn set_argument(&mut self, arg: &Value) -> JsResult<()>
fn set_argument(&mut self, arg: &Value) -> JsResult<()>
The data 11ty hands an exported function (addGlobalData values and
eleventy), sent once before any file loads.
Sourcefn load(&mut self, file: &Path, call: bool) -> JsResult<Decoded>
fn load(&mut self, file: &Path, call: bool) -> JsResult<Decoded>
Import file (absolute) as 11ty does; when call and the export is
a function, call it with the argument and await it.
Sourcefn call(
&mut self,
f: FnHandle,
this: This<'_>,
args: &[Value],
settle: Settle,
) -> JsResult<Decoded>
fn call( &mut self, f: FnHandle, this: This<'_>, args: &[Value], settle: Settle, ) -> JsResult<Decoded>
Call a function value from a template with this and args.
Sourcefn page_open(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
) -> JsResult<PageId>
fn page_open( &mut self, data: &Value, traps: &[(String, String)], defaults: &[String], ) -> JsResult<PageId>
Keep data as a page’s data object. Each of traps (a top-level
key and why) is a key Brrrty can’t supply: reading it refuses the
call. Each of defaults (a dotted computed key) that is undefined
is set to "", as 11ty’s computed data proxy does.
Sourcefn page_vars(
&mut self,
page: PageId,
f: FnHandle,
keys: &[String],
) -> JsResult<Vec<String>>
fn page_vars( &mut self, page: PageId, f: FnHandle, keys: &[String], ) -> JsResult<Vec<String>>
The keys f reads of the page’s data, as 11ty’s
ComputedDataProxy.findVarsUsed finds them (keys are the page’s
computed keys).
Sourcefn page_call(
&mut self,
page: PageId,
f: FnHandle,
set: Option<&str>,
) -> JsResult<Decoded>
fn page_call( &mut self, page: PageId, f: FnHandle, set: Option<&str>, ) -> JsResult<Decoded>
Call f with the page’s data, as 11ty calls a computed function or
a permalink function, awaiting it; with set, store the result at
that dotted key of the page’s data.
Sourcefn page_set(&mut self, page: PageId, key: &str, value: &Value) -> JsResult<()>
fn page_set(&mut self, page: PageId, key: &str, value: &Value) -> JsResult<()>
Set a dotted key of the page’s data, as 11ty’s lodash.set does.
Sourcefn page_close(&mut self, page: PageId)
fn page_close(&mut self, page: PageId)
Forget the page’s data.
Sourcefn reads(&mut self) -> JsResult<Vec<PathBuf>>
fn reads(&mut self) -> JsResult<Vec<PathBuf>>
Every file the site’s code read or loaded so far, absolute.
Sourcefn loads_changed(&mut self) -> JsResult<Vec<(PathBuf, Decoded)>>
fn loads_changed(&mut self) -> JsResult<Vec<(PathBuf, Decoded)>>
The global data files are loaded: each of their values that a later one changed (by its file), as it is now, which is what 11ty’s pages see.
Sourcefn begin_calls(&mut self) -> JsResult<()>
fn begin_calls(&mut self) -> JsResult<()>
The data files are loaded; what follows are the pages’ calls.
Refused when a template or directory data file changed a value
another file gave, or a built-in prototype.
Sourcefn set_filters(&mut self, filters: Filters)
fn set_filters(&mut self, filters: Filters)
Brrrty’s filters, which JavaScript calls on this (a template, a
computed or permalink function): (name, arguments).
Sourcefn template_setup(&mut self, filters: &[String]) -> JsResult<()>
fn template_setup(&mut self, filters: &[String]) -> JsResult<()>
The names 11ty puts on a JavaScript template’s this as functions
(its filters and shortcodes), in its order. Sent before any template
loads.
Sourcefn load_template(
&mut self,
file: &Path,
layout: bool,
) -> JsResult<LoadedTemplate>
fn load_template( &mut self, file: &Path, layout: bool, ) -> JsResult<LoadedTemplate>
Import the JavaScript template or layout file (absolute) as 11ty
does, make its instance, and read its data.
Sourcefn render(
&mut self,
template: TemplateId,
data: &Value,
first: Option<&Value>,
traps: &[(String, String)],
filters: &mut FilterCall<'_>,
) -> JsResult<Decoded>
fn render( &mut self, template: TemplateId, data: &Value, first: Option<&Value>, traps: &[(String, String)], filters: &mut FilterCall<'_>, ) -> JsResult<Decoded>
Render a loaded template with the page’s data (for a layout, with
content), as 11ty’s JavaScript engine does: first is the page
11ty’s first render of it set as this.page. Each of traps (a
top-level key and why) is a key Brrrty can’t supply. A filter the
template calls on this runs as filters(name, arguments); Err
refuses the render with why.
Provided Methods§
Sourcefn load_config(&mut self, _file: &Path) -> JsResult<Decoded>
fn load_config(&mut self, _file: &Path) -> JsResult<Decoded>
Import the site’s 11ty config file (absolute) as 11ty does and call
its export with a recording eleventyConfig. The value is
{ returned, values, functions, unsupported }.
Sourcefn begin(&mut self, op: Op<'_>, filters: &mut FilterCall<'_>) -> Begun
fn begin(&mut self, op: Op<'_>, filters: &mut FilterCall<'_>) -> Begun
Begin an operation. A runtime that can run several at once sends it
and gives back Begun::Sent: the render threads then wait for
their results at the same time, and the runtime never waits on
Brrrty between one request and the next. Any other runs it here.
Sourcefn finish(&mut self, _waited: Waited) -> Finished
fn finish(&mut self, _waited: Waited) -> Finished
What came of an operation JsRuntime::begin sent.
Sourcefn page_once(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
f: FnHandle,
) -> JsResult<Decoded>
fn page_once( &mut self, data: &Value, traps: &[(String, String)], defaults: &[String], f: FnHandle, ) -> JsResult<Decoded>
JsRuntime::page_open, one JsRuntime::page_call of f with
nothing set, and JsRuntime::page_close: a permalink function
called for a page with no computed data open.
Sourcefn page_open_with_vars(
&mut self,
data: &Value,
traps: &[(String, String)],
defaults: &[String],
functions: &[FnHandle],
keys: &[String],
) -> JsResult<(PageId, Vec<Vec<String>>)>
fn page_open_with_vars( &mut self, data: &Value, traps: &[(String, String)], defaults: &[String], functions: &[FnHandle], keys: &[String], ) -> JsResult<(PageId, Vec<Vec<String>>)>
JsRuntime::page_open, then JsRuntime::page_vars of each of
functions in order: the page, and what each reads. When one of
them gives no list, the page is closed and that is the result.
Sourcefn page_run(
&mut self,
page: PageId,
steps: &[PageStep<'_>],
) -> Vec<JsResult<Decoded>>
fn page_run( &mut self, page: PageId, steps: &[PageStep<'_>], ) -> Vec<JsResult<Decoded>>
The steps in order, each as JsRuntime::page_call or
JsRuntime::page_set would run it. The list ends with the first
result that isn’t a value (a runtime may have run the steps after
it all the same: nothing is made of them).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".