From ef85637b59e84c2783623697f70d04c67c001e8c Mon Sep 17 00:00:00 2001 From: trivernis Date: Fri, 4 Sep 2020 18:11:28 +0200 Subject: [PATCH] Add formatting implementation for in_book Signed-off-by: trivernis --- src/references/bibliography.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/references/bibliography.rs b/src/references/bibliography.rs index cce6449..ba11904 100644 --- a/src/references/bibliography.rs +++ b/src/references/bibliography.rs @@ -3,6 +3,7 @@ use crate::elements::{BoldText, ItalicText, Line, List, ListItem, PlainText, Tex use bibliographix::bibliography::bib_types::article::Article; use bibliographix::bibliography::bib_types::book::Book; use bibliographix::bibliography::bib_types::booklet::Booklet; +use bibliographix::bibliography::bib_types::in_book::InBook; use bibliographix::bibliography::bib_types::BibliographyType; use bibliographix::bibliography::bibliography_entry::{ BibliographyEntry, BibliographyEntryReference, @@ -48,6 +49,7 @@ fn get_item_for_entry(entry: BibliographyEntryReference) -> ListItem { BibliographyType::Article(a) => get_item_for_article(&*entry, a), BibliographyType::Book(b) => get_item_for_book(&*entry, b), BibliographyType::Booklet(b) => get_item_for_booklet(&*entry, b), + BibliographyType::InBook(ib) => get_item_for_in_book(&*entry, ib), _ => unimplemented!(), } } @@ -138,3 +140,34 @@ fn get_item_for_booklet(entry: &BibliographyEntry, b: &Booklet) -> ListItem { ListItem::new(Line::Text(text), 0, true) } + +/// Returns the list item for an in book bib entry +fn get_item_for_in_book(entry: &BibliographyEntry, ib: &InBook) -> ListItem { + let mut text = TextLine::new(); + text.subtext + .push(bold_text!(format!("{}: ", entry.key().clone()))); + text.subtext + .push(plain_text!(format!("{}.", ib.author.clone()))); + text.subtext + .push(plain_text!(format!("\"{}\"", ib.title.clone()))); + + text.subtext + .push(plain_text!(format!("({})", ib.position.clone()))); + + if let Some(volume) = ib.volume.clone() { + text.subtext.push(plain_text!(format!(", {}", volume))) + } + if let Some(edition) = ib.edition.clone() { + text.subtext.push(plain_text!(format!(", {}", edition))) + } + if let Some(series) = ib.series.clone() { + text.subtext.push(plain_text!("In: ".to_string())); + text.subtext.push(italic_text!(series)) + } + text.subtext.push(plain_text!(format!( + ", Published By: {}", + ib.publisher.clone() + ))); + + ListItem::new(Line::Text(text), 0, true) +}