#[derive(Debug, Clone)]
pub struct RenderOptions {
pub gaiji_dir: String,
pub css_files: Vec<String>,
pub use_jisx0213: bool,
pub use_unicode: bool,
pub title: Option<String>,
}
impl Default for RenderOptions {
fn default() -> Self {
Self {
gaiji_dir: "../../../gaiji/".to_string(),
css_files: vec!["../../aozora.css".to_string()],
use_jisx0213: false,
use_unicode: false,
title: None,
}
}
}
impl RenderOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_gaiji_dir(mut self, dir: impl Into<String>) -> Self {
self.gaiji_dir = dir.into();
self
}
pub fn with_css_files(mut self, files: Vec<String>) -> Self {
self.css_files = files;
self
}
pub fn with_jisx0213(mut self, use_it: bool) -> Self {
self.use_jisx0213 = use_it;
self
}
pub fn with_unicode(mut self, use_it: bool) -> Self {
self.use_unicode = use_it;
self
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_options() {
let opts = RenderOptions::default();
assert_eq!(opts.gaiji_dir, "../../../gaiji/");
assert!(!opts.use_jisx0213);
assert!(!opts.use_unicode);
}
#[test]
fn test_builder_pattern() {
let opts = RenderOptions::new()
.with_gaiji_dir("/path/to/gaiji/")
.with_jisx0213(true)
.with_title("テスト");
assert_eq!(opts.gaiji_dir, "/path/to/gaiji/");
assert!(opts.use_jisx0213);
assert_eq!(opts.title, Some("テスト".to_string()));
}
}