[][src]Struct gen_epub_book::ops::EPubBook

pub struct EPubBook {
    pub name: String,
    pub author: String,
    pub date: DateTime<FixedOffset>,
    pub language: String,
    pub cover: Option<EPubData>,
    pub description: Option<EPubContentType>,
    // some fields omitted
}

Full ePub book, bundled together.

Fields

name: String

E-book's title

author: String

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]

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]

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]

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]

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 process Raw 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 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_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]

impl Debug for EPubBook[src]

impl Hash for EPubBook[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl Send for EPubBook

impl Sync for EPubBook

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> Erased for T[src]