Add data property to chapter struct
This data property makes it possible to share data between pre-processors, or between pre-processors and the renderer, including the "html" renderer which exposes the chapter data as "data" in the .hbs files.
This commit is contained in:
parent
ab2cb71c00
commit
18cb9091ea
|
@ -138,7 +138,8 @@ mod nop_lib {
|
|||
"sub_items": [],
|
||||
"path": "chapter_1.md",
|
||||
"source_path": "chapter_1.md",
|
||||
"parent_names": []
|
||||
"parent_names": [],
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -165,6 +165,9 @@ pub struct Chapter {
|
|||
pub source_path: Option<PathBuf>,
|
||||
/// An ordered list of the names of each chapter above this one in the hierarchy.
|
||||
pub parent_names: Vec<String>,
|
||||
/// Data that can be shared between preprocessors, accessed in the renderer
|
||||
/// or accessed in the theme's `.hbs` files
|
||||
pub data: serde_json::Map<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Chapter {
|
||||
|
@ -444,6 +447,7 @@ And here is some \
|
|||
source_path: Some(PathBuf::from("second.md")),
|
||||
parent_names: vec![String::from("Chapter 1")],
|
||||
sub_items: Vec::new(),
|
||||
data: serde_json::Map::new(),
|
||||
};
|
||||
let should_be = BookItem::Chapter(Chapter {
|
||||
name: String::from("Chapter 1"),
|
||||
|
@ -457,6 +461,7 @@ And here is some \
|
|||
BookItem::Separator,
|
||||
BookItem::Chapter(nested),
|
||||
],
|
||||
data: serde_json::Map::new(),
|
||||
});
|
||||
|
||||
let got = load_summary_item(&SummaryItem::Link(root), temp.path(), Vec::new()).unwrap();
|
||||
|
@ -533,6 +538,7 @@ And here is some \
|
|||
Vec::new(),
|
||||
)),
|
||||
],
|
||||
data: serde_json::Map::new(),
|
||||
}),
|
||||
BookItem::Separator,
|
||||
],
|
||||
|
@ -586,6 +592,7 @@ And here is some \
|
|||
Vec::new(),
|
||||
)),
|
||||
],
|
||||
data: serde_json::Map::new(),
|
||||
}),
|
||||
BookItem::Separator,
|
||||
],
|
||||
|
|
|
@ -105,6 +105,7 @@ impl HtmlHandlebars {
|
|||
ctx.data
|
||||
.insert("section".to_owned(), json!(section.to_string()));
|
||||
}
|
||||
ctx.data.insert("data".to_owned(), json!(ch.data));
|
||||
|
||||
// Render the handlebars template with the data
|
||||
debug!("Render template");
|
||||
|
|
Loading…
Reference in New Issue