1#![deny(missing_docs)]
10
11extern crate clap;
12extern crate toml;
13extern crate serde;
14extern crate mdbook;
15extern crate walkdir;
16extern crate failure;
17extern crate tinytemplate;
18
19#[macro_use]
20extern crate shells;
21
22use mdbook::book::Book;
23use mdbook::errors::Error;
24use mdbook::preprocess::{Preprocessor, PreprocessorContext};
25
26pub mod error;
27pub mod models;
28pub mod render;
29pub mod cat_context;
30
31use cat_context::CatContext;
32
33pub struct Cat;
39
40impl Cat {
41 pub fn new() -> Cat {
46 Cat
47 }
48}
49
50impl Preprocessor for Cat {
51 fn name(&self) -> &str {
54 "cat-preprocessor"
55 }
56
57 fn run(&self, _: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
66 let context = match CatContext::with_book(&mut book) {
67 Ok(c) => c,
68 Err(e) => {
69 eprintln!("[cat prep] failed to create cat context: {}", e);
70 return Err(Error::msg(e.to_string()));
71 }
72 };
73
74 let renders = match render::create_renders(&context, &mut book) {
75 Ok(rs) => rs,
76 Err(e) => {
77 eprintln!("[cat prep] failed to prepare renders of cat content: {}", e);
78 return Err(Error::msg(e.to_string()));
79 }
80 };
81
82 if let Err(e) = render::execute_renders(renders, &mut book) {
83 eprintln!("[cat prep] failed to prepare renders of cat content: {}", e);
84 return Err(Error::msg(e.to_string()));
85 }
86
87 dbg!("{:#?}", context);
88
89 Ok(book)
90 }
91
92 fn supports_renderer(&self, renderer: &str) -> bool {
99 renderer != "not-supported"
100 }
101}