use toml_edit::{InlineTable, Item, Value};
use crate::{
composition::{
recipe::{
capture_fixed_panel, read_content, FixedOptions, SupplyContent, CONTENT_FIELDS,
FIXED_FIELDS,
},
DeclaredContent,
},
recipe::{
capture::Capture,
codec::{array_items, choice, field, invalid, table, Codec},
declaration::BindingRequirement,
resolve::Resolver,
CanvasRecipeScope,
},
Result,
};
use crate::recipe::schema::{self as grammar, Schema};
use super::{
placement, Arc, AxisRef, Canvas, CanvasCategoryLabels, CanvasHeader, CanvasLegendPolicy,
LegendComposition, PanelPath, ReservedSlot, TextPanel, Theme,
};
choice!(CanvasCategoryLabels {EveryPlot=>"every_plot",FirstColumnPerRow=>"first_column_per_row"});
choice!(CanvasLegendPolicy {PerPlot=>"per_plot",Shared=>"shared",Hidden=>"hidden"});
const TEXT_PANEL_FIELDS: &[grammar::Field] = &[
grammar::mandatory::<crate::Text>("title"),
grammar::mandatory::<crate::Text>("body"),
];
impl Codec for TextPanel {
fn schema(ctx: &mut Schema) -> serde_json::Value {
grammar::record(ctx, TEXT_PANEL_FIELDS)
}
fn encode(&self) -> Value {
let mut fields = InlineTable::new();
fields.insert("title", self.title.encode());
fields.insert("body", self.body.encode());
fields.into()
}
fn decode(item: &Item, _: Option<Self>) -> Result<Self> {
let fields = grammar::record_fields(item, TEXT_PANEL_FIELDS)?;
Self::new(
field::<crate::Text>(fields, "title", None)?,
field::<crate::Text>(fields, "body", None)?,
)
}
}
const HEADER_FIELDS: &[grammar::Field] = &[
grammar::mandatory::<usize>("start"),
grammar::optional::<usize>("span"),
grammar::mandatory::<crate::Text>("text"),
];
impl Codec for CanvasHeader {
fn schema(ctx: &mut Schema) -> serde_json::Value {
grammar::record(ctx, HEADER_FIELDS)
}
fn encode(&self) -> Value {
let mut fields = InlineTable::new();
fields.insert("start", self.start.encode());
fields.insert("span", self.span.encode());
fields.insert("text", self.text.encode());
fields.into()
}
fn decode(item: &Item, _: Option<Self>) -> Result<Self> {
let fields = grammar::record_fields(item, HEADER_FIELDS)?;
Ok(Self {
start: field(fields, "start", None)?,
span: field(fields, "span", Some(1))?,
text: field(fields, "text", None)?,
})
}
}
struct PanelBuild {
footprint: placement::Footprint,
source: SupplyContent,
fixed: FixedOptions,
path: String,
}
pub(crate) struct Blueprint {
canvas: Canvas,
panels: Vec<PanelBuild>,
floating: Vec<crate::composition::recipe::SupplyPlacement>,
}
fn read_range_groups(item: &Item, canvas: &mut Canvas) -> Result<()> {
for item in array_items(item)? {
let fields = grammar::record_fields(item, RANGE_GROUP_FIELDS)?;
if field::<String>(fields, "axis", Some("x".to_owned()))? != "x"
|| field::<String>(fields, "mode", Some("domain".to_owned()))? != "domain"
{
return Err(invalid(
"Canvas range groups currently require x and domain",
));
}
let paths: Vec<PanelPath> = field(fields, "panels", None)?;
*canvas = canvas.clone().range_group(AxisRef::X, paths)?;
}
Ok(())
}
const FIELDS: &[grammar::Field] = &[
grammar::custom("scope", false, |_| grammar::choices(&["full", "layout"])),
grammar::mandatory::<usize>("rows"),
grammar::mandatory::<usize>("columns"),
grammar::optional::<crate::layout::RootRequest>("size"),
grammar::optional::<Option<Theme>>("theme"),
grammar::optional::<Option<Theme>>("default_theme"),
grammar::optional::<crate::Text>("title"),
grammar::optional::<crate::Text>("subtitle"),
grammar::optional::<crate::Text>("caption"),
grammar::optional::<CanvasLegendPolicy>("legend_policy"),
grammar::optional::<LegendComposition>("legend_composition"),
grammar::custom(
"labels",
false,
crate::builder::recipe::non_grid_labels_schema,
),
grammar::optional::<CanvasCategoryLabels>("category_labels"),
grammar::optional::<Option<crate::text::TextAlignment>>("panel_title_alignment"),
grammar::optional::<Option<crate::text::TextAlignment>>("panel_subtitle_alignment"),
grammar::custom("guide_text_layouts", false, guide_layouts_schema),
grammar::optional::<Vec<CanvasHeader>>("row_headers"),
grammar::optional::<Vec<CanvasHeader>>("column_headers"),
grammar::optional::<Vec<CanvasHeader>>("row_titles"),
grammar::custom("range_groups", false, |ctx| {
grammar::array(grammar::record(ctx, RANGE_GROUP_FIELDS))
}),
grammar::custom("panels", false, |_| grammar::primitive("array")),
];
const RESERVE_FIELDS: &[grammar::Field] = &[
grammar::optional::<f64>("min_width"),
grammar::optional::<f64>("min_height"),
];
const PANEL_FIELDS: &[grammar::Field] = &[
grammar::optional::<Option<String>>("name"),
grammar::mandatory::<usize>("row"),
grammar::mandatory::<usize>("column"),
grammar::optional::<usize>("row_span"),
grammar::optional::<usize>("column_span"),
grammar::custom("reserve", false, |ctx| grammar::record(ctx, RESERVE_FIELDS)),
grammar::optional::<bool>("vacant"),
];
const RANGE_GROUP_FIELDS: &[grammar::Field] = &[
grammar::custom("axis", false, |_| grammar::literal("x")),
grammar::custom("mode", false, |_| grammar::literal("domain")),
grammar::mandatory::<Vec<PanelPath>>("panels"),
];
const GUIDE_LAYOUT_FIELDS: &[grammar::Field] = &[
grammar::optional::<Option<crate::text::TextLayout>>("title"),
grammar::optional::<Option<crate::text::TextLayout>>("entry"),
grammar::optional::<Option<crate::text::TextLayout>>("number"),
];
pub(crate) fn guide_layouts_schema(ctx: &mut Schema) -> serde_json::Value {
ctx.named("GuideTextLayouts", |ctx| {
grammar::record(ctx, GUIDE_LAYOUT_FIELDS)
})
}
const LAYOUT_REMOVED: &[&str] = &[
"title",
"subtitle",
"caption",
"labels",
"row_headers",
"column_headers",
"row_titles",
];
fn panel_schema(ctx: &mut Schema, layout: bool) -> serde_json::Value {
use crate::composition::recipe::{
content_names, content_properties, fixed_properties, placement_schema, FIXED_FIELDS,
};
let geometry = grammar::record(ctx, PANEL_FIELDS);
let reserved =
serde_json::json!({"required":["reserve","vacant"],"properties":{"vacant":{"const":true}}});
if layout {
return grammar::with(geometry, serde_json::json!({"not":reserved}));
}
let mut properties = PANEL_FIELDS
.iter()
.map(|field| (field.name, geometry["properties"][field.name].clone()))
.collect::<Vec<_>>();
properties.extend(content_properties(ctx, false));
properties.extend(fixed_properties(ctx, true));
let names = content_names(false);
let empty = serde_json::json!({"not":{"anyOf":names.iter().chain(FIXED_FIELDS).chain(std::iter::once(&"binding_map")).map(|name|grammar::required(&[name])).collect::<Vec<_>>() }});
let filled = serde_json::json!({"allOf":[
grammar::exclusive(&names),
{"not":{"required":["reserve"]}},
{"properties":{"vacant":{"const":false}}},
{"dependentRequired":{"binding_map":["use"]}},
{"if":{"anyOf":FIXED_FIELDS.iter().map(|name|grammar::required(&[name])).collect::<Vec<_>>()},
"then":{"anyOf":[{"required":["asset"]},{"required":["frozen"]},{"required":["use"]}]}}
]});
let vacant = serde_json::json!({"required":["vacant"],"properties":{"vacant":{"const":true}},"not":{"required":["reserve"]}});
let solid = grammar::with(
grammar::object(properties, &["row", "column"]),
grammar::one_of([
filled,
serde_json::json!({"allOf":[empty.clone(),{"required":["reserve"],"properties":{"vacant":{"const":false}}}]}),
serde_json::json!({"allOf":[empty,vacant]}),
]),
);
let floating = serde_json::json!({"allOf":[placement_schema(ctx),{
"oneOf":[{"required":["slot"]},{"required":["box"],"properties":{"box":crate::layout::recipe::slot_box_schema(ctx)}}],
"not":{"required":["at"]},
"properties":{"boundary":{"const":false}}
}]});
grammar::one_of([solid, floating])
}
pub(crate) fn schema(ctx: &mut Schema) -> serde_json::Value {
ctx.named("Canvas", |ctx| {
grammar::one_of([false, true].into_iter().map(|layout| {
let fields = FIELDS
.iter()
.copied()
.filter(|field| !layout || !LAYOUT_REMOVED.contains(&field.name))
.collect::<Vec<_>>();
let mut shape = grammar::record(ctx, &fields);
grammar::declare_property(
&mut shape,
"scope",
grammar::literal(if layout { "layout" } else { "full" }),
);
grammar::declare_property(
&mut shape,
"panels",
grammar::array(panel_schema(ctx, layout)),
);
if layout {
grammar::with(shape, grammar::required(&["scope"]))
} else {
shape
}
}))
})
}
impl Blueprint {
pub(crate) fn read(
item: &Item,
path: &str,
fallback: Option<&str>,
requirements: &mut Vec<BindingRequirement>,
) -> Result<Self> {
let fields = grammar::record_fields(item, FIELDS)?;
let layout = match field::<String>(fields, "scope", Some("full".to_owned()))?.as_str() {
"full" => false,
"layout" => true,
_ => return Err(invalid("Canvas recipe requires full or layout scope")),
};
let mut canvas = Canvas::grid(
field(fields, "rows", None)?,
field(fields, "columns", None)?,
)?;
canvas.theme = field::<Option<Theme>>(fields, "theme", Some(None))?.map(Arc::new);
canvas.default_theme =
field::<Option<Theme>>(fields, "default_theme", Some(None))?.map(Arc::new);
canvas.root_size = field(fields, "size", Some(crate::layout::RootRequest::Natural))?;
read_configuration(&mut canvas, fields, path, fallback, requirements, layout)?;
let mut panels = Vec::new();
let mut floating = Vec::new();
if let Some(items) = fields.get("panels") {
for (index, item) in array_items(items)?.enumerate() {
crate::operation::check()?;
let panel_path = format!("{path}.panels[{index}]");
if item.get("slot").is_some()
|| item.get("box").is_some()
|| item.get("at").is_some()
{
if layout {
return Err(invalid(format!(
"{panel_path}: layout scope cannot contain floating content"
)));
}
floating.push(crate::composition::recipe::read_placement(
item,
&panel_path,
fallback,
requirements,
)?);
} else if let Some(panel) = read_panel(
item,
&mut canvas,
&panel_path,
fallback,
requirements,
layout,
)? {
panels.push(panel);
}
}
}
if let Some(groups) = fields.get("range_groups") {
read_range_groups(groups, &mut canvas)?;
}
for panel in &panels {
let index = panel.footprint.row * canvas.columns + panel.footprint.column;
let shared = canvas.category_labels == CanvasCategoryLabels::FirstColumnPerRow
|| canvas
.x_range_groups
.iter()
.any(|group| group.contains(&index));
if shared && !panel.source.permits_plot() {
return Err(invalid(format!(
"{}: shared scientific axes require Plot content",
panel.path
)));
}
}
for placement in &floating {
let (row, column) = placement.slot_borrow()?;
if row >= canvas.rows
|| column >= canvas.columns
|| canvas
.placements
.reservation(row * canvas.columns + column)
.is_none()
{
return Err(invalid(format!("{path}: floating placement requires an actual reserved anchor ({row}, {column})")));
}
}
canvas.validate_recipe_topology()?;
Ok(Self {
canvas,
panels,
floating,
})
}
pub(crate) fn build(self, resolver: &mut Resolver<'_>) -> Result<Canvas> {
let mut canvas = self.canvas;
for panel in self.panels {
let source = panel.source.build(resolver)?;
let payload = match source.0 {
DeclaredContent::Plot(plot) => placement::Payload::Plot(*plot),
DeclaredContent::Text(text) => placement::Payload::Text(text),
DeclaredContent::Fixed(source) => {
placement::Payload::Fixed(panel.fixed.admit(source)?)
}
DeclaredContent::Canvas(_) => {
return Err(invalid(format!(
"{}: nested Canvas grid panels are not available",
panel.path
)))
}
};
let placements = Arc::make_mut(&mut canvas.placements);
placements.insert(panel.footprint, payload)?;
placements.set_content_origin(
panel.footprint.row * canvas.columns + panel.footprint.column,
source.1,
);
}
for placement in self.floating {
canvas.place_panel_placement(placement.build(resolver)?)?;
}
canvas.validate_recipe_topology()?;
Ok(canvas)
}
}
fn read_configuration(
canvas: &mut Canvas,
fields: &dyn toml_edit::TableLike,
path: &str,
fallback: Option<&str>,
requirements: &mut Vec<BindingRequirement>,
layout: bool,
) -> Result<()> {
canvas.legend_policy = field(fields, "legend_policy", Some(CanvasLegendPolicy::PerPlot))?;
canvas.legend_composition = field(
fields,
"legend_composition",
Some(LegendComposition::Combined),
)?;
canvas.category_labels = field(
fields,
"category_labels",
Some(CanvasCategoryLabels::EveryPlot),
)?;
if layout && LAYOUT_REMOVED.iter().any(|key| fields.contains_key(key)) {
return Err(invalid(
"layout scope does not retain prose or authored data labels",
));
}
canvas.title = field(fields, "title", Some(crate::Text::UNSET))?;
canvas.subtitle = field(fields, "subtitle", Some(crate::Text::UNSET))?;
canvas.caption = field(fields, "caption", Some(crate::Text::UNSET))?;
canvas.panel_title_alignment = field(fields, "panel_title_alignment", Some(None))?;
canvas.panel_subtitle_alignment = field(fields, "panel_subtitle_alignment", Some(None))?;
if let Some(labels) = fields.get("labels") {
canvas.labels = Some(
crate::builder::recipe::read_labels(labels, path, fallback, false, requirements)?.0,
);
}
if let Some(item) = fields.get("guide_text_layouts") {
let fields = grammar::record_fields(item, GUIDE_LAYOUT_FIELDS)?;
for (slot, role) in canvas
.guide_text_layouts
.iter_mut()
.zip(["title", "entry", "number"])
{
*slot = field(fields, role, Some(None))?;
}
}
for header in field::<Vec<CanvasHeader>>(fields, "column_headers", Some(Vec::new()))? {
*canvas = canvas
.clone()
.column_header(header.start, header.span, header.text)?;
}
for header in field::<Vec<CanvasHeader>>(fields, "row_headers", Some(Vec::new()))? {
*canvas = canvas
.clone()
.row_header(header.start, header.span, header.text)?;
}
for header in field::<Vec<CanvasHeader>>(fields, "row_titles", Some(Vec::new()))? {
if header.span != 1 {
return Err(invalid("row title spans exactly one row"));
}
*canvas = canvas.clone().row_title(header.start, header.text)?;
}
Ok(())
}
fn read_panel(
item: &Item,
canvas: &mut Canvas,
path: &str,
fallback: Option<&str>,
requirements: &mut Vec<BindingRequirement>,
layout: bool,
) -> Result<Option<PanelBuild>> {
let mut allowed = grammar::names(PANEL_FIELDS);
allowed.extend(CONTENT_FIELDS);
allowed.extend(FIXED_FIELDS);
let fields = table(item, &allowed)?;
let footprint = placement::Footprint {
row: field(fields, "row", None)?,
column: field(fields, "column", None)?,
row_span: field(fields, "row_span", Some(1))?,
column_span: field(fields, "column_span", Some(1))?,
};
let name: Option<String> = field(fields, "name", Some(None))?;
let content = CONTENT_FIELDS.iter().any(|key| fields.contains_key(key));
let fixed = FIXED_FIELDS.iter().any(|key| fields.contains_key(key));
let vacant = field(fields, "vacant", Some(false))?;
let reserve = fields.get("reserve");
let location = format!(
"{path} {:?} ({}, {})",
name.as_deref(),
footprint.row,
footprint.column
);
let reservation = if let Some(item) = reserve {
let fields = grammar::record_fields(item, RESERVE_FIELDS)?;
let width = field(fields, "min_width", Some(0.))?;
let height = field(fields, "min_height", Some(0.))?;
ReservedSlot::at_least(width, height)?;
Some((width, height))
} else {
None
};
if (reservation.is_some() || layout || vacant) && (content || fixed)
|| (vacant && reservation.is_some())
{
return Err(invalid(format!(
"{location}: a vacant or reserved slot cannot have content"
)));
}
if fixed && !(fields.contains_key("asset") || fields.contains_key("frozen")) {
return Err(invalid(format!(
"{location}: fixed-frame options require fixed content"
)));
}
if reservation.is_none() && !vacant && !layout && !content {
return Err(invalid(format!(
"{location}: a full panel requires content"
)));
}
let placements = Arc::make_mut(&mut canvas.placements);
placements
.insert(
footprint,
reservation.map_or(placement::Payload::Vacant, placement::Payload::Reserved),
)
.map_err(|error| error.with_prefix(&location))?;
if let Some(name) = name {
placements.name(footprint.row, footprint.column, &name)?;
}
if content {
Ok(Some(PanelBuild {
footprint,
source: read_content(fields, path, fallback, requirements, false)?,
fixed: FixedOptions::read(fields)?,
path: path.to_owned(),
}))
} else {
Ok(None)
}
}
impl Canvas {
fn validate_recipe_topology(&self) -> Result<()> {
self.root_size.validate()?;
if self.placements.slots().next().is_some() {
self.validate_structure()?;
}
Ok(())
}
pub(crate) fn capture_recipe(
&self,
context: &mut Capture,
path: &str,
scope: CanvasRecipeScope,
) -> Result<Value> {
if scope == CanvasRecipeScope::Style {
return self.capture_style(true);
}
let layout = scope == CanvasRecipeScope::Layout;
let mut fields = self.capture_recipe_configuration(context, path, layout)?;
if layout {
fields.insert("scope", "layout".into());
}
let mut panels = toml_edit::Array::new();
for slot in self.placements.slots() {
crate::operation::check()?;
let index = slot.row() * self.columns + slot.column();
let prefix = slot.name().map_or_else(
|| format!("panel_{}_{}", slot.row(), slot.column()),
str::to_owned,
);
let panel_path = format!("{path}.panels[{}]", panels.len());
let mut panel = InlineTable::new();
for (key, value) in [
("row", slot.row()),
("column", slot.column()),
("row_span", slot.row_span()),
("column_span", slot.column_span()),
] {
panel.insert(key, value.encode());
}
if let Some(name) = slot.name() {
panel.insert("name", Value::from(name));
}
if let Some((width, height)) = slot.reservation() {
let mut reserved = InlineTable::new();
reserved.insert("min_width", width.encode());
reserved.insert("min_height", height.encode());
panel.insert("reserve", reserved.into());
} else if !layout {
context.owner(&prefix, |context| {
let origin = self.placements.content_origin(index);
match self.placements.payload(index).expect("actual panel owner") {
placement::Payload::Vacant => {
panel.insert("vacant", true.into());
}
placement::Payload::Plot(_) | placement::Payload::Text(_)
if origin.is_some() =>
{
panel.insert(
"native",
context.content_reference(
origin.expect("actual content binding"),
"native",
&format!("{panel_path}.native"),
)?,
);
}
placement::Payload::Plot(plot) => {
panel.insert(
"plot",
plot.capture_recipe(context, &format!("{panel_path}.plot"))?,
);
}
placement::Payload::Text(text) => {
panel.insert("text", text.encode());
}
placement::Payload::Fixed(fixed) => {
capture_fixed_panel(fixed, &mut panel, context, origin, &panel_path)?;
}
placement::Payload::Reserved(_) => unreachable!("actual reservation"),
}
Ok(())
})?;
}
panels.push(Value::from(panel));
}
if !layout {
for (index, placement) in self.slot_placements.iter().enumerate() {
let panel_path = format!("{path}.panels[{}]", panels.len());
let value = context.owner(&format!("placement_{index}"), |context| {
placement.capture_recipe(context, &panel_path)
})?;
panels.push(value);
}
}
fields.insert("panels", panels.into());
Ok(fields.into())
}
fn capture_recipe_configuration(
&self,
context: &mut Capture,
path: &str,
layout: bool,
) -> Result<InlineTable> {
let mut fields = InlineTable::new();
fields.insert("rows", self.rows.encode());
fields.insert("columns", self.columns.encode());
fields.insert("size", self.root_size.encode());
if let Some(theme) = &self.theme {
fields.insert("theme", theme.encode());
}
if let Some(theme) = &self.default_theme {
fields.insert("default_theme", theme.encode());
}
fields.insert("legend_policy", self.legend_policy.encode());
fields.insert("legend_composition", self.legend_composition.encode());
fields.insert("category_labels", self.category_labels.encode());
if let Some(value) = self.panel_title_alignment {
fields.insert("panel_title_alignment", value.encode());
}
if let Some(value) = self.panel_subtitle_alignment {
fields.insert("panel_subtitle_alignment", value.encode());
}
let mut guides = InlineTable::new();
for (role, layout) in ["title", "entry", "number"]
.into_iter()
.zip(&self.guide_text_layouts)
{
if let Some(layout) = layout {
guides.insert(role, layout.encode());
}
}
if !guides.is_empty() {
fields.insert("guide_text_layouts", guides.into());
}
if !layout {
for (key, value) in [
("title", &self.title),
("subtitle", &self.subtitle),
("caption", &self.caption),
] {
if value != &crate::Text::UNSET {
fields.insert(key, value.encode());
}
}
if let Some(labels) = &self.labels {
fields.insert(
"labels",
crate::builder::recipe::encode_labels(labels, context, path)?,
);
}
for (key, headers) in [
("column_headers", &self.column_headers),
("row_headers", &self.row_headers),
("row_titles", &self.row_titles),
] {
if !headers.is_empty() {
fields.insert(key, headers.encode());
}
}
}
if !self.x_range_groups.is_empty() {
let groups: toml_edit::Array = self
.x_range_groups
.iter()
.map(|group| {
let mut fields = InlineTable::new();
fields.insert("axis", "x".into());
fields.insert("mode", "domain".into());
let paths = group
.iter()
.map(|&index| {
self.placements
.slot(index)
.and_then(|slot| slot.name().map(PanelPath::from))
.unwrap_or_else(|| {
PanelPath::from((index / self.columns, index % self.columns))
})
})
.collect::<Vec<_>>();
fields.insert("panels", paths.encode());
Value::from(fields)
})
.collect();
fields.insert("range_groups", groups.into());
}
Ok(fields)
}
}
impl Canvas {
pub fn get_recipe(&self) -> Result<crate::recipe::Recipe> {
self.get_recipe_with_operation(&crate::operation::OperationOptions::default())
}
pub fn get_recipe_with_operation(
&self,
options: &crate::operation::OperationOptions,
) -> Result<crate::recipe::Recipe> {
self.get_recipe_with_scope_and_operation(CanvasRecipeScope::Full, options)
}
pub fn get_recipe_with_scope(&self, scope: CanvasRecipeScope) -> Result<crate::recipe::Recipe> {
self.get_recipe_with_scope_and_operation(
scope,
&crate::operation::OperationOptions::default(),
)
}
pub fn get_recipe_with_scope_and_operation(
&self,
scope: CanvasRecipeScope,
options: &crate::operation::OperationOptions,
) -> Result<crate::recipe::Recipe> {
crate::operation::run(options, || {
let mut context = Capture::new();
let value = self.capture_recipe(&mut context, "canvas", scope)?;
crate::recipe::Recipe::from_capture("canvas", value, context)
})
}
pub fn recipe(&self, path: impl AsRef<std::path::Path>) -> Result<crate::recipe::Recipe> {
self.recipe_with_operation(path, &crate::operation::OperationOptions::default())
}
pub fn recipe_with_operation(
&self,
path: impl AsRef<std::path::Path>,
options: &crate::operation::OperationOptions,
) -> Result<crate::recipe::Recipe> {
self.recipe_with_scope_and_operation(path, CanvasRecipeScope::Full, options)
}
pub fn recipe_with_scope(
&self,
path: impl AsRef<std::path::Path>,
scope: CanvasRecipeScope,
) -> Result<crate::recipe::Recipe> {
self.recipe_with_scope_and_operation(
path,
scope,
&crate::operation::OperationOptions::default(),
)
}
pub fn recipe_with_scope_and_operation(
&self,
path: impl AsRef<std::path::Path>,
scope: CanvasRecipeScope,
options: &crate::operation::OperationOptions,
) -> Result<crate::recipe::Recipe> {
crate::operation::run(options, || {
let mut context = Capture::new();
let value = self.capture_recipe(&mut context, "canvas", scope)?;
let recipe = crate::recipe::Recipe::from_capture("canvas", value, context)?;
recipe.write_document(path.as_ref())?;
Ok(recipe)
})
}
}