summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-09-28 10:25:20 +0300
committerLars Wirzenius <liw@liw.fi>2022-09-28 10:25:20 +0300
commitf974c9919502764a0319b224eb604d094499ae37 (patch)
tree270b505f63b57df15c65e259dd896689ce6bec15
parentf204a2e599f74485b80c4168e03358c6f3c985bf (diff)
downloadsubplot-f974c9919502764a0319b224eb604d094499ae37.tar.gz
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
-rw-r--r--src/doc.rs21
-rw-r--r--subplot.md18
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<PathBuf>,
ast: Pandoc,
meta: Metadata,
@@ -92,6 +93,7 @@ pub struct Document {
impl Document {
fn new(
+ subplot: PathBuf,
markdowns: Vec<PathBuf>,
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<P>(
basedir: P,
+ subplot: PathBuf,
markdowns: Vec<PathBuf>,
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<PathBuf> {
- 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"
],