1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! # base16_color_scheme
//!
//! A library to build [base16](https://github.com/chriskempson/base16) colorschemes written in Rust.
//!
//! It uses [ramhorns](https://docs.rs/ramhorns/latest/ramhorns/index.html)
//! as template engine and therefore is fairly fast. \
//! (Around 70 ms - 200 ms for a 9 mb template I generated based on <https://github.com/chriskempson/base16-templates-source>.)
//!
//! ## Getting Started
//!
//! To get started use you need to create a [`Template`] and a [`Scheme`].
//!
//! A [`Template`] can be created by just reading the template file and using
//! [`Template::new()`].
//!
//! A [`Scheme`] is often created by deserializing using [`serde`].
//!
//! Neither [`Template`] nor [`Scheme`] get modified by the rendering process,
//! which means both can be reused for efficiency.
//!
//! ```rust,no_run
//! use base16_color_scheme::{Scheme, Template};
//! use std::fs::read_to_string;
//!
//! let template_str = read_to_string("path/to/template.mustache").unwrap();
//! let scheme_str = read_to_string("path/to/scheme.yml").unwrap();
//!
//! let template = Template::new(template_str).unwrap();
//! let scheme: Scheme = serde_yaml::from_str(&scheme_str).unwrap();
//!
//! template
//!     .render_to_file("path/to/rendered/template", &scheme)
//!     .unwrap();
//! ```
//!
//! ## How it works
//!
//! Internally the crate works by implementing [`ramhorns`]'s [`Content`](ramhorns::Content) trait.
//! When the rendering process tries to look up a field, the field name gets
//! parsed into a [`TemplateField`](template::TemplateField). If it is a color, this color is fetched
//! from the [`Scheme`] and formatted as specified by <https://github.com/chriskempson/base16/blob/main/builder.md#template-tags>.

pub use crate::scheme::Scheme;
pub use ramhorns::Template;

pub mod scheme;
pub mod template;