gen_epub_book/
lib.rs

1//! Generate an ePub book from a simple plaintext descriptor
2//!
3//! # Library doc
4//!
5//! This library is used by `gen-epub-book` itself for all its function and is therefore contains all necessary functions.
6//!
7//! ## Data flow
8//!
9//! ```text
10//! Options
11//! |> parse_descriptor()
12//! |> EPubBook::from_elements()
13//! |> EPubBook::normalise_paths()
14//! |> EPubBook::write_zip()
15//! ```
16//!
17//! # Executable manpage
18//!
19//! Exit values and possible errors:
20//!
21//! ```text
22//! 1 - I/O error
23//! 2 - parsing error
24//! 3 - file not found
25//! 4 - file in wrong state
26//! 5 - incorrect amount of elements
27//! 6 - required element missing
28//! ```
29//!
30//! ## SYNOPSIS
31//!
32//! [`gen-epub-book`](https://github.com/nabijaczleweli/gen-epub-book.rs) [OPTIONS] IN_FILE OUT_FILE
33//!
34//! ## DESCRIPTION
35//!
36//! Generate an ePub book from a simple plaintext descriptor.
37//!
38//! ## OPTIONS
39//!
40//! -v --verbose
41//!
42//! ```text
43//! Print out more data.
44//!
45//! Default: false.
46//! ```
47//!
48//! IN_FILE
49//!
50//! ```text
51//! File to parse, must exist, must comply with the DESCRIPTOR FORMAT.
52//!
53//! Special case: '-' to read from stdin.
54//! ```
55//!
56//! OUT_FILE
57//!
58//! ```text
59//! File to write the book to, parent directory needn't exist.
60//!
61//! Special case: '-' to write to stdout.
62//! ```
63//!
64//! -S --separator <SEPARATOR>
65//!
66//! ```text
67//! Enable custom separator feature and set the separator.
68//!
69//! Default: ":".
70//! ```
71//!
72//! -I --include [NAME=]PATH
73//!
74//! ```text
75//! Add an additional directory in which to search for files. Order-dependent.
76//!
77//! `NAME` is an optional name under which the files will be segregated.
78//! `PATH` is an existing directory.
79//! ```
80//!
81//! ## DESCRIPTOR FORMAT
82//!
83//! The descriptor consists of multiple lines in the format *"Key: Value"*, unknown
84//! keys are ignored, lines that don't match the format are ignored.
85//!
86//! Name
87//!
88//! ```text
89//! Required: yes
90//! Type: plaintext
91//! Value: e-book's title
92//! Amount: 1
93//! ```
94//!
95//! Content
96//!
97//! ```text
98//! Required: no
99//! Type: file path
100//! Value: relative path to (X)HTML chunk
101//! Amount: any
102//! Remarks: see ADDITIONAL CONTENT PROCESSING
103//! ```
104//!
105//! String-Content
106//!
107//! ```text
108//! Required: no
109//! Type: (X)HTML
110//! Value: (X)HTML string
111//! Amount: any
112//! ```
113//!
114//! Image-Content
115//!
116//! ```text
117//! Required: no
118//! Type: file path
119//! Value: relative path to image to include in e-book
120//! Amount: any
121//! ```
122//!
123//! Network-Image-Content
124//!
125//! ```text
126//! Required: no
127//! Type: file URL
128//! Value: URL of image to include in e-book
129//! Amount: any
130//! ```
131//!
132//! Cover
133//!
134//! ```text
135//! Required: no
136//! Type: file path
137//! Value: relative path to image to use as e-book cover
138//! Amount: 0-1
139//! Remarks: exclusive with Network-Cover
140//! ```
141//!
142//! Network-Cover
143//!
144//! ```text
145//! Required: no
146//! Type: file URL
147//! Value: URL to image to use as e-book cover
148//! Amount: 0-1
149//! Remarks: exclusive with Cover
150//! ```
151//!
152//! Author
153//!
154//! ```text
155//! Required: yes
156//! Type: plaintext string
157//! Value: e-book's author
158//! Amount: 1
159//! ```
160//!
161//! Date
162//!
163//! ```text
164//! Required: yes
165//! Type: RFC3339-compliant date
166//! Value: e-book's authoring/publishing date
167//! Amount: 1
168//! Remarks: see FREE DATE FORMAT FEATURE
169//! ```
170//!
171//! Language
172//!
173//! ```text
174//! Required: yes
175//! Type: BCP47-compliant language code
176//! Value: language used in e-book
177//! Amount: 1
178//! ```
179//!
180//! ## ADDITIONAL CONTENT PROCESSING
181//!
182//! When adding content using the `Content` entry, the file will additinally be
183//! searched for a comment specifying the its name in the TOC in this format:
184//!
185//! ```text
186//! <!-- ePub title: "TOC_NAME" -->
187//! ```
188//!
189//! Where `TOC_NAME` is a string not containing the *"* character.
190//!
191//! This will, on e-book readers, allow users to jump directly to the content
192//! represented by the document containing this entry.
193//!
194//! Optional.
195//!
196//! ## FREE DATE FORMAT FEATURE
197//!
198//! With the -D/--free-date flag, you can enable the
199//! [free date format feature](https://nabijaczleweli.xyz/content/gen-epub-book/programmer.html#features-free-date-format).
200//!
201//! The supported formats therewith are therefore:
202//!
203//!   * RFC3339 (e.g. "2017-02-08T15:30:18+01:00"),
204//!   * RFC2822 (e.g. "Wed, 08 Feb 2017 15:30:18 +0100"),
205//!   * Unix timestamp w/timezone (e.g. "1486564218+01:00").
206
207
208#[macro_use]
209extern crate lazy_static;
210extern crate mime_guess;
211extern crate reqwest;
212extern crate chrono;
213extern crate regex;
214#[macro_use]
215extern crate clap;
216extern crate uuid;
217extern crate url;
218extern crate zip;
219
220mod error;
221mod options;
222
223pub mod ops;
224pub mod util;
225
226pub use error::Error;
227pub use options::Options;