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

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

Full ePub book, bundled together.

Fields

E-book's title

E-book's author

E-book's authoring/publishing date

Language used in e-book

Image to use as e-book cover, if any

Methods

impl EPubBook
[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()))));

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()))));

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();

Trait Implementations

impl Clone for EPubBook
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for EPubBook
[src]

Formats the value using the given formatter.

impl Hash for EPubBook
[src]

Feeds this value into the given [Hasher]. Read more

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

impl PartialEq for EPubBook
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for EPubBook
[src]

impl PartialOrd for EPubBook
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for EPubBook
[src]

This method returns an Ordering between self and other. Read more

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

Compares and returns the maximum of two values. Read more

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

Compares and returns the minimum of two values. Read more