From f974c9919502764a0319b224eb604d094499ae37 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 28 Sep 2022 10:25:20 +0300 Subject: fix: include the subplot in the sources of the document This means that if only the subplot is modified, docgen will rebuild the output. Sponsored-by: author --- src/doc.rs | 21 +++++++++++++++++---- subplot.md | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/doc.rs b/src/doc.rs index 2ed3ef5..cc6a616 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -82,6 +82,7 @@ static KNOWN_PANDOC_CLASSES: &[&str] = &["numberLines", "noNumberLines"]; /// ~~~~ #[derive(Debug)] pub struct Document { + subplot: PathBuf, markdowns: Vec, ast: Pandoc, meta: Metadata, @@ -92,6 +93,7 @@ pub struct Document { impl Document { fn new( + subplot: PathBuf, markdowns: Vec, ast: Pandoc, meta: Metadata, @@ -99,6 +101,7 @@ impl Document { style: Style, ) -> Document { Document { + subplot, markdowns, ast, meta, @@ -115,6 +118,7 @@ impl Document { fn from_ast

( basedir: P, + subplot: PathBuf, markdowns: Vec, yamlmeta: &ast::YamlMetadata, mut ast: Pandoc, @@ -133,7 +137,7 @@ impl Document { return Err(linter.issues.remove(0)); } let files = EmbeddedFiles::new(&mut ast); - let doc = Document::new(markdowns, ast, meta, files, style); + let doc = Document::new(subplot, markdowns, ast, meta, files, style); trace!("Loaded from JSON OK"); Ok(doc) } @@ -186,7 +190,15 @@ impl Document { trace!("Parsing document AST as JSON..."); let mut ast: Pandoc = serde_json::from_str(&json).map_err(SubplotError::AstJson)?; ast.meta = meta.to_map(); - let doc = Self::from_ast(basedir, markdowns, &meta, ast, style, template)?; + let doc = Self::from_ast( + basedir, + filename.into(), + markdowns, + &meta, + ast, + style, + template, + )?; trace!("Loaded document OK"); Ok(doc) @@ -214,7 +226,8 @@ impl Document { trace!("Parsed document OK"); Self::from_ast( basedir, - vec![filename.into()], + filename.into(), + vec![mdfile], &meta, ast.to_pandoc(), style, @@ -241,7 +254,7 @@ impl Document { /// The sources are any files that affect the output so that if /// the source file changes, the output needs to be re-generated. pub fn sources(&mut self, template: Option<&str>) -> Vec { - let mut names = vec![]; + let mut names = vec![self.subplot.clone()]; for x in self.meta().bindings_filenames() { names.push(PathBuf::from(x)) diff --git a/subplot.md b/subplot.md index 8ae5014..8daf1dd 100644 --- a/subplot.md +++ b/subplot.md @@ -1931,6 +1931,23 @@ then file simple.pdf has same metadata as before and only files simple.subplot, simple.md, b.yaml, f.py, simple.pdf exist ~~~ +### Do typeset if output is older than subplot + +~~~scenario +given file simple.subplot +given file simple.md +and file b.yaml +and file f.py +and an installed subplot +when I run subplot docgen simple.subplot -o simple.pdf +then file simple.pdf exists +when I remember metadata for file simple.pdf +and I wait until 1 second has passed +and I touch file simple.subplot +and I run subplot docgen simple.subplot -o simple.pdf +then file simple.pdf has changed from before +~~~ + ### Do typeset if output is older than markdown ~~~scenario @@ -2614,6 +2631,7 @@ bibliography: [foo.bib, bar.bib] "foo.bib", "image.gif", "images.md", + "images.subplot", "other.py", "other.yaml" ], -- cgit v1.2.1