Skip to main content

microsoft_fast_build/
lib.rs

1mod json;
2mod context;
3mod expression;
4mod attribute;
5mod content;
6mod directive;
7mod node;
8mod renderer;
9mod error;
10mod locator;
11
12pub use json::{JsonValue, JsonError};
13pub use error::RenderError;
14pub use locator::Locator;
15
16/// Render a FAST HTML template with a JSON state string.
17pub fn render_template(template: &str, state: &str) -> Result<String, RenderError> {
18    let state_value = json::parse(state).map_err(|e| RenderError::JsonParse { message: e.message })?;
19    renderer::render(template, &state_value)
20}
21
22/// Render a FAST HTML template with a parsed [`JsonValue`].
23pub fn render(template: &str, state: &JsonValue) -> Result<String, RenderError> {
24    renderer::render(template, state)
25}
26
27/// Render a FAST HTML template with a parsed [`JsonValue`] and a [`Locator`] for custom elements.
28pub fn render_with_locator(template: &str, state: &JsonValue, locator: &Locator) -> Result<String, RenderError> {
29    renderer::render_with_locator(template, state, locator)
30}
31
32/// Render a FAST HTML template with a JSON state string and a [`Locator`] for custom elements.
33pub fn render_template_with_locator(template: &str, state: &str, locator: &Locator) -> Result<String, RenderError> {
34    let state_value = json::parse(state).map_err(|e| RenderError::JsonParse { message: e.message })?;
35    renderer::render_with_locator(template, &state_value, locator)
36}