Skip to content

Add data property to chapter struct #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/nop-preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ mod nop_lib {
"sub_items": [],
"path": "chapter_1.md",
"source_path": "chapter_1.md",
"parent_names": []
"parent_names": [],
"data": {}
}
}
],
Expand Down
7 changes: 7 additions & 0 deletions src/book/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
Expand All @@ -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();
Expand Down Expand Up @@ -533,6 +538,7 @@ And here is some \
Vec::new(),
)),
],
data: serde_json::Map::new(),
}),
BookItem::Separator,
],
Expand Down Expand Up @@ -586,6 +592,7 @@ And here is some \
Vec::new(),
)),
],
data: serde_json::Map::new(),
}),
BookItem::Separator,
],
Expand Down
1 change: 1 addition & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down