Struct crowbook::Book
[−]
[src]
pub struct Book { pub chapters: Vec<(Number, Vec<Token>)>, pub filenames: Vec<String>, pub options: BookOptions, pub root: PathBuf, pub logger: Logger, // some fields omitted }
A Book.
Probably the central structure for of Crowbook, as it is the one that calls the other ones.
It has the tasks of loading a configuration file, loading chapters
and using Parser
to parse them, and then calling various renderers
(HtmlRendrer
, LatexRenderer
, EpubRenderer
and/or OdtRenderer
)
to convert the AST into documents.
Examples
use crowbook::{Book, Number}; // Create a book with some options let mut book = Book::new(&[("author", "Joan Doe"), ("title", "An untitled book"), ("lang", "en")]); // Add content to the book book.add_chapter_as_str(Number::Default, "# The beginning#\nBla, bla, bla").unwrap(); // Render the book as html to stdout book.render_html(&mut std::io::stdout()).unwrap();
Fields
chapters: Vec<(Number, Vec<Token>)>
Internal structure. You should not accesss this directly except if you are writing a new renderer.
filenames: Vec<String>
A list of the filenames of the chapters
options: BookOptions
Options of the book
root: PathBuf
Root path of the book
logger: Logger
Logger
Methods
impl Book
[src]
fn new<'a, I>(options: I) -> Book where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a new Book
with given options
Arguments
*options
a list (or other iterator) of (key, value) tuples. Can be &[].
fn new_from_file<'a, I>(filename: &str, verbosity: InfoLevel, options: I) -> Result<Book> where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a new book from a file, with options
Arguments
filename
: the path of file to load. The directory of this file is used as a "root" directory for all paths referenced in books, whether chapter files, templates, cover images, and so on.- `verbosity: sets the book verbosity
options
: a list of (key, value) options to pass to the book
fn new_from_markdown_file<'a, I>(filename: &str, verbosity: InfoLevel, options: I) -> Result<Book> where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a book from a single markdown file
fn set_from_config(&mut self, s: &str) -> Result<()>
Sets options and load chapters according to configuration file
A line with "option: value" sets the option to value
chapter_name.md adds the (default numbered) chapter
chapter_name.md adds the (unnumbered) chapter
- chapter_name.md adds the (custom numbered) chapter
fn render_all(&self)
Generates output files acccording to book options
fn render_pdf(&self) -> Result<()>
Render book to pdf according to book options
fn render_epub(&self) -> Result<()>
Render book to epub according to book options
fn render_html_dir(&self) -> Result<()>
Render book to HTML directory according to book options
fn render_odt(&self) -> Result<()>
Render book to odt according to book options
fn render_html<T: Write>(&self, f: &mut T) -> Result<()>
Render book to html according to book options
fn render_tex<T: Write>(&self, f: &mut T) -> Result<()>
Render book to pdf according to book options
fn add_chapter(&mut self, number: Number, file: &str) -> Result<()>
Adds a chapter, as a file name, to the book
Book
will then parse the file and store the AST (i.e., a vector
of Token
s).
Arguments
number
: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. SeeNumber
.file
: path of the file for this chapter
Returns an error if file
does not exist, could not be read, of if there was
some error parsing it.
fn add_chapter_as_str(&mut self, number: Number, content: &str) -> Result<()>
Adds a chapter, as a string, to the book
Book
will then parse the string and store the AST (i.e., a vector
of Token
s).
Arguments
number
: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. SeeNumber
.content
: the content of the chapter.
Returns an error if there was some errror parsing content
.
fn clean(&self, text: String, tex: bool) -> String
Either clean a string or does nothing,
according to book lang
and autoclean
options
fn get_template(&self, template: &str) -> Result<Cow<'static, str>>
Returns the template (default or modified version)
fn get_header(&self, n: i32, title: &str) -> Result<String>
Returns the string corresponding to a number, title, and the numbering template
fn get_mapbuilder(&self, format: &str) -> MapBuilder
Returns a MapBuilder
(used by Mustache
for templating), to be used (and completed)
by renderers. It fills it with the followings strings, corresponding to the matching
Book
options:
- "author"
- "title"
- "lang"
It also uses the lang/xx.yaml file corresponding to the language and fills
loc_xxx
fiels with it that corresponds to translated versions