summaryrefslogtreecommitdiff
path: root/src/library/insert.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-09 19:46:57 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-09 19:46:57 +0100
commit06ca740d01b428f12f6bd327257cd05dce737b03 (patch)
tree995bf8ff3a606aedecf296c9e805e11e9cd0ae8e /src/library/insert.rs
parente35bbfffcb1f84b2fb0679759152ca0a5eabfad4 (diff)
Split evaluation and execution 🔪
Diffstat (limited to 'src/library/insert.rs')
-rw-r--r--src/library/insert.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/library/insert.rs b/src/library/insert.rs
index 58e8a11c..eff54e91 100644
--- a/src/library/insert.rs
+++ b/src/library/insert.rs
@@ -15,23 +15,23 @@ pub fn image(ctx: &mut EvalContext, args: &mut Args) -> Value {
let width = args.get(ctx, "width");
let height = args.get(ctx, "height");
- if let Some(path) = path {
- let loaded = ctx.env.resources.load(path.v, ImageResource::parse);
- if let Some((res, img)) = loaded {
- let dimensions = img.buf.dimensions();
- ctx.push(NodeImage {
- res,
- dimensions,
- width,
- height,
- align: ctx.state.align,
- });
- } else {
- ctx.diag(error!(path.span, "failed to load image"));
+ Value::template(move |ctx| {
+ if let Some(path) = &path {
+ let loaded = ctx.env.resources.load(&path.v, ImageResource::parse);
+ if let Some((res, img)) = loaded {
+ let dimensions = img.buf.dimensions();
+ ctx.push(NodeImage {
+ res,
+ dimensions,
+ width,
+ height,
+ align: ctx.state.align,
+ });
+ } else {
+ ctx.diag(error!(path.span, "failed to load image"));
+ }
}
- }
-
- Value::None
+ })
}
/// An image node.