Skip to content

Commit 313be71

Browse files
authored
Merge pull request #2813 from ehuss/rename-book-sections
Rename Book.sections to Book.items
2 parents 45e700d + 800fb54 commit 313be71

File tree

11 files changed

+22
-22
lines changed

11 files changed

+22
-22
lines changed

crates/mdbook-core/src/book.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ mod tests;
1111

1212
/// A tree structure representing a book.
1313
///
14-
/// For the moment a book is just a collection of [`BookItems`] which are
15-
/// accessible by either iterating (immutably) over the book with [`iter()`], or
16-
/// recursively applying a closure to each section to mutate the chapters, using
14+
/// A book is just a collection of [`BookItems`] which are accessible by
15+
/// either iterating (immutably) over the book with [`iter()`], or recursively
16+
/// applying a closure to each item to mutate the chapters, using
1717
/// [`for_each_mut()`].
1818
///
1919
/// [`iter()`]: #method.iter
2020
/// [`for_each_mut()`]: #method.for_each_mut
2121
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2222
#[non_exhaustive]
2323
pub struct Book {
24-
/// The sections in this book.
25-
pub sections: Vec<BookItem>,
24+
/// The items in this book.
25+
pub items: Vec<BookItem>,
2626
}
2727

2828
impl Book {
@@ -33,13 +33,13 @@ impl Book {
3333

3434
/// Creates a new book with the given items.
3535
pub fn new_with_items(items: Vec<BookItem>) -> Book {
36-
Book { sections: items }
36+
Book { items }
3737
}
3838

3939
/// Get a depth-first iterator over the items in the book.
4040
pub fn iter(&self) -> BookItems<'_> {
4141
BookItems {
42-
items: self.sections.iter().collect(),
42+
items: self.items.iter().collect(),
4343
}
4444
}
4545

@@ -55,12 +55,12 @@ impl Book {
5555
where
5656
F: FnMut(&mut BookItem),
5757
{
58-
for_each_mut(&mut func, &mut self.sections);
58+
for_each_mut(&mut func, &mut self.items);
5959
}
6060

6161
/// Append a `BookItem` to the `Book`.
6262
pub fn push_item<I: Into<BookItem>>(&mut self, item: I) -> &mut Self {
63-
self.sections.push(item.into());
63+
self.items.push(item.into());
6464
self
6565
}
6666
}

crates/mdbook-core/src/book/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn book_iter_iterates_over_sequential_items() {
2626
];
2727
let book = Book::new_with_items(items);
2828

29-
let should_be: Vec<_> = book.sections.iter().collect();
29+
let should_be: Vec<_> = book.items.iter().collect();
3030

3131
let got: Vec<_> = book.iter().collect();
3232

crates/mdbook-driver/src/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ And here is some \
284284
PathBuf::from("chapter_1.md"),
285285
vec![],
286286
);
287-
let sections = vec![BookItem::Chapter(chapter)];
288-
let should_be = Book::new_with_items(sections);
287+
let items = vec![BookItem::Chapter(chapter)];
288+
let should_be = Book::new_with_items(items);
289289

290290
let got = load_book_from_disk(&summary, temp.path()).unwrap();
291291

crates/mdbook-html/src/html_handlebars/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) fn create_files(
3838
.add_field_with_tokenizer("breadcrumbs", Box::new(&tokenize))
3939
.build();
4040

41-
let mut doc_urls = Vec::with_capacity(book.sections.len());
41+
let mut doc_urls = Vec::with_capacity(book.items.len());
4242

4343
let chapter_configs = sort_search_config(&search_config.chapter);
4444
validate_chapter_config(&chapter_configs, book)?;

crates/mdbook-summary/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,9 @@ impl<'a> SummaryParser<'a> {
601601
}
602602
}
603603

604-
fn update_section_numbers(sections: &mut [SummaryItem], level: usize, by: u32) {
605-
for section in sections {
606-
if let SummaryItem::Link(ref mut link) = *section {
604+
fn update_section_numbers(items: &mut [SummaryItem], level: usize, by: u32) {
605+
for item in items {
606+
if let SummaryItem::Link(ref mut link) = *item {
607607
if let Some(ref mut number) = link.number {
608608
number[level] += by;
609609
}

examples/nop-preprocessor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod nop_lib {
134134
"mdbook_version": "0.4.21"
135135
},
136136
{
137-
"sections": [
137+
"items": [
138138
{
139139
"Chapter": {
140140
"name": "Chapter 1",

guide/src/for_developers/preprocessors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if __name__ == '__main__':
9191
# load both the context and the book representations from stdin
9292
context, book = json.load(sys.stdin)
9393
# and now, we can just modify the content of the first chapter
94-
book['sections'][0]['Chapter']['content'] = '# Hello'
94+
book['items'][0]['Chapter']['content'] = '# Hello'
9595
# we are done with the book's modification, we can just print it to stdout,
9696
print(json.dumps(book))
9797
```

tests/testsuite/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn preprocessor_cfg_from_env() {
5454
let mut s = String::new();
5555
std::io::stdin().read_to_string(&mut s).unwrap();
5656
std::fs::write("out.txt", s).unwrap();
57-
println!("{{\"sections\": []}}");
57+
println!("{{\"items\": []}}");
5858
}
5959
"#,
6060
)

tests/testsuite/preprocessor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn relative_command_path() {
115115
let mut s = String::new();
116116
std::io::stdin().read_to_string(&mut s).unwrap();
117117
std::fs::write("preprocessor-ran", "test").unwrap();
118-
println!("{{\"sections\": []}}");
118+
println!("{{\"items\": []}}");
119119
}
120120
"#,
121121
)

tests/testsuite/renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn backends_receive_render_context_via_stdin() {
167167
str![[r##"
168168
{
169169
"book": {
170-
"sections": [
170+
"items": [
171171
{
172172
"Chapter": {
173173
"content": "# Chapter 1\n",

0 commit comments

Comments
 (0)