[−][src]Struct gen_epub_book::ops::EPubBook
Full ePub book, bundled together.
Fields
name: String
E-book's title
E-book's author
date: DateTime<FixedOffset>
E-book's authoring/publishing date
language: String
Language used in e-book
cover: Option<EPubData>
Image to use as e-book cover, if any
description: Option<EPubContentType>
Description of the book, if any.
Methods
impl EPubBook
[src]
pub fn from_elements<E: IntoIterator<Item = BookElement>>(
elems: E
) -> Result<EPubBook, Error>
[src]
elems: E
) -> Result<EPubBook, Error>
Construct a book from loose elements
Returns an error upon violating any of the requirements laid forth in the variants of BookElement
.
Examples
let book = EPubBook::from_elements(vec![ BookElement::Name("Simple ePub demonstration".to_string()), BookElement::Cover(PathBuf::from("examples/cover.png")), BookElement::ImageContent(PathBuf::from("examples/simple/chapter_image.png")), BookElement::Content(PathBuf::from("examples/simple/ctnt.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); assert_eq!(book.name, "Simple ePub demonstration".to_string()); assert_eq!(book.author, "nabijaczleweli".to_string()); assert_eq!(book.date, DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()); assert_eq!(book.language, "en-GB".to_string()); assert_eq!(book.cover, Some(("cover-content-1".to_string(), PathBuf::from("cover-data-1.html"), EPubContentType::Raw("<center>\ <img src=\"examples-cover.png\" \ alt=\"examples-cover.png\"></img>\ </center>".to_string()))));
pub fn normalise_paths<W: Write>(
&mut self,
relroot: &[IncludeDirectory],
verbose: bool,
verb_out: &mut W
) -> Result<(), Error>
[src]
&mut self,
relroot: &[IncludeDirectory],
verbose: bool,
verb_out: &mut W
) -> Result<(), Error>
Normalise the paths in the book based on the specified relative path root, optionally printing verbose output to the specified stream.
Will return an error if the file the path points to doesn't exist or isn't a file.
Examples
let mut book = EPubBook::from_elements(vec![ BookElement::Name("Path normalisation demonstration".to_string()), BookElement::Cover(PathBuf::from("cover.png")), BookElement::Content(PathBuf::from("content/ch01.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); book.normalise_paths(&["./".parse().unwrap()], false, &mut stdout()).unwrap(); assert_eq!(book.cover, Some(("cover".to_string(), PathBuf::from("cover.png"), EPubContentType::File( PathBuf::from("cover.png").canonicalize().unwrap()))));
pub fn write_zip<W: Write + Seek, V: Write>(
&self,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
[src]
&self,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
Write the book as ePub into the specified stream, optionally logging verbose output.
Examples
let mut book = EPubBook::from_elements(vec![ BookElement::Name("Path normalisation demonstration".to_string()), BookElement::Cover(PathBuf::from("cover.png")), BookElement::Content(PathBuf::from("content/ch01.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); book.normalise_paths(&["./".parse().unwrap()], false, &mut stdout()).unwrap(); book.write_zip(&mut File::create("write_zip.epub").unwrap(), false, &mut stdout()).unwrap();
pub fn write_zip_ext<W: Write + Seek, V: Write>(
&self,
string_toc: bool,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
[src]
&self,
string_toc: bool,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
Write the book as ePub into the specified stream with additional configuration, optionally logging verbose output.
This function is equivalent to write_zip()
with all config arguments defaulted.
Config arguments:
string_toc
– whether to processRaw
elements for TOC specifiers – default:false
Note: functionality governed by this additional config is accessible only via the API.
Examples
In the following example the resulting ePub will have the following TOC:
- Introduxion
- The Parodies
Wherease without string_toc
, the TOC would be empty.
let mut book = EPubBook::from_elements(vec![ BookElement::Name("String TOC demonstration".to_string()), BookElement::StringContent(r#" <!-- ePub title: "Introduxion" --> It is a measure of Sherlock Holmes' immense popularity, that he's literature's most imitated character. "#.to_string()), BookElement::StringContent(r#" <!-- ePub title: "The Parodies" --> Sherlock Holmes appeared for the first time in A Study in Scarlet and The Sign of The Four, two novels published in 1887 and 1890. "#.to_string()), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2018-06-27T12:30:38+02:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); book.write_zip_ext( true, &mut File::create("write_zip_ext.epub").unwrap(), false, &mut stdout()).unwrap();
Trait Implementations
impl PartialEq<EPubBook> for EPubBook
[src]
impl Ord for EPubBook
[src]
fn cmp(&self, other: &EPubBook) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl Clone for EPubBook
[src]
fn clone(&self) -> EPubBook
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for EPubBook
[src]
impl PartialOrd<EPubBook> for EPubBook
[src]
fn partial_cmp(&self, other: &EPubBook) -> Option<Ordering>
[src]
fn lt(&self, other: &EPubBook) -> bool
[src]
fn le(&self, other: &EPubBook) -> bool
[src]
fn gt(&self, other: &EPubBook) -> bool
[src]
fn ge(&self, other: &EPubBook) -> bool
[src]
impl Debug for EPubBook
[src]
impl Hash for EPubBook
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
impl<Q, K> Equivalent for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,