diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-09 11:06:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-09 11:26:41 +0200 |
| commit | 3932bb2cb93be95d67fc56998423eb9ce047fdfa (patch) | |
| tree | c36bd4df1d2c74f8ae100d2f3bd3a0b232b797f5 /src/library/elements.rs | |
| parent | 3c92bad9a7cd6b880de197806443ffcce2cac9d8 (diff) | |
New source loading architecture
Diffstat (limited to 'src/library/elements.rs')
| -rw-r--r-- | src/library/elements.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/library/elements.rs b/src/library/elements.rs index 3d318d36..e021c0c6 100644 --- a/src/library/elements.rs +++ b/src/library/elements.rs @@ -1,8 +1,10 @@ use std::f64::consts::SQRT_2; +use std::io; use decorum::N64; use super::*; +use crate::diag::Error; use crate::layout::{ BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode, Paint, }; @@ -13,13 +15,17 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { let width = args.named("width")?; let height = args.named("height")?; - let file = ctx.resolve(&path.v, path.span)?; - let node = match ctx.images.load(file) { - Some(id) => ImageNode { id, width, height }, - None => bail!(args.file, path.span, "failed to load image"), - }; - - Ok(Value::template(move |ctx| ctx.push_into_par(node))) + let full = ctx.relpath(path.v.as_str()); + let id = ctx.images.load(&full).map_err(|err| { + Error::boxed(args.source, path.span, match err.kind() { + io::ErrorKind::NotFound => "file not found".into(), + _ => format!("failed to load image ({})", err), + }) + })?; + + Ok(Value::template(move |ctx| { + ctx.push_into_par(ImageNode { id, width, height }) + })) } /// `rect`: A rectangle with optional content. |
