From c010cbc17dcbb2f0d6005d21530143bf57cb5871 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 25 May 2022 13:50:33 +0200 Subject: Move route from context to VM --- src/model/content.rs | 26 +++++++++++++------------- src/model/mod.rs | 2 +- src/model/recipe.rs | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/model') diff --git a/src/model/content.rs b/src/model/content.rs index 64579747..c09979d5 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -19,6 +19,19 @@ use crate::library::text::{ }; use crate::util::EcoString; +/// Layout content into a collection of pages. +pub fn layout(ctx: &mut Context, content: &Content) -> TypResult>> { + let copy = ctx.config.styles.clone(); + let styles = StyleChain::with_root(©); + let scratch = Scratch::default(); + + let mut builder = Builder::new(ctx, &scratch, true); + builder.accept(content, styles)?; + + let (doc, shared) = builder.into_doc(styles)?; + doc.layout(ctx, shared) +} + /// Composable representation of styled content. /// /// This results from: @@ -207,19 +220,6 @@ impl Content { Self::sequence(seq) } - - /// Layout this content into a collection of pages. - pub fn layout(&self, ctx: &mut Context) -> TypResult>> { - let copy = ctx.config.styles.clone(); - let styles = StyleChain::with_root(©); - let scratch = Scratch::default(); - - let mut builder = Builder::new(ctx, &scratch, true); - builder.accept(self, styles)?; - - let (doc, shared) = builder.into_doc(styles)?; - doc.layout(ctx, shared) - } } impl Layout for Content { diff --git a/src/model/mod.rs b/src/model/mod.rs index a9d1344a..5c8b82c0 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,4 +1,4 @@ -//! Structured representation of styled content. +//! Styled and structured representation of layoutable content. #[macro_use] mod styles; diff --git a/src/model/recipe.rs b/src/model/recipe.rs index 3404a384..e4417adf 100644 --- a/src/model/recipe.rs +++ b/src/model/recipe.rs @@ -82,12 +82,12 @@ impl Recipe { F: FnOnce() -> Value, { let args = if self.func.argc() == Some(0) { - Args::new(self.span) + Args::new(self.span, []) } else { - Args::from_values(self.span, [arg()]) + Args::new(self.span, [arg()]) }; - Ok(self.func.call(ctx, args)?.display()) + Ok(self.func.call_detached(ctx, args)?.display()) } /// What kind of structure the property interrupts. -- cgit v1.2.3