1#![warn(missing_docs)]
2
3use serde::Serialize;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
7pub enum TemplateEngine {
8 Custom,
10
11 #[cfg(feature = "handlebars")]
12 Handlebars,
14
15 #[cfg(feature = "dejavu")]
16 DejaVu,
18
19 #[cfg(feature = "jinja")]
20 Jinja2,
22
23 #[cfg(feature = "liquid")]
24 Liquid,
26}
27
28impl TemplateEngine {
29 pub fn all() -> &'static [Self] {
31 #[cfg(all(not(feature = "handlebars"), not(feature = "dejavu"), not(feature = "jinja"), not(feature = "liquid")))]
32 {
33 &[Self::Custom]
34 }
35
36 #[cfg(any(feature = "handlebars", feature = "dejavu", feature = "jinja", feature = "liquid"))]
37 {
38 &[
39 Self::Custom,
40 #[cfg(feature = "handlebars")] Self::Handlebars,
41 #[cfg(feature = "dejavu")] Self::DejaVu,
42 #[cfg(feature = "jinja")] Self::Jinja2,
43 #[cfg(feature = "liquid")] Self::Liquid,
44 ]
45 }
46 }
47
48 pub fn display_name(&self) -> &'static str {
50 match self {
51 Self::Custom => "自定义",
52 #[cfg(feature = "handlebars")]
53 Self::Handlebars => "Handlebars",
54 #[cfg(feature = "dejavu")]
55 Self::DejaVu => "DejaVu",
56 #[cfg(feature = "jinja")]
57 Self::Jinja2 => "Jinja2",
58 #[cfg(feature = "liquid")]
59 Self::Liquid => "Liquid",
60 }
61 }
62
63 pub fn description(&self) -> &'static str {
65 match self {
66 Self::Custom => "自定义模板引擎",
67 #[cfg(feature = "handlebars")]
68 Self::Handlebars => "Handlebars 模板引擎,流行的 JavaScript 模板语言",
69 #[cfg(feature = "dejavu")]
70 Self::DejaVu => "DejaVu 模板引擎,编译期零成本抽象",
71 #[cfg(feature = "jinja")]
72 Self::Jinja2 => "Jinja2 模板引擎,Python 生态系统中流行的模板语言",
73 #[cfg(feature = "liquid")]
74 Self::Liquid => "Liquid 模板引擎,Shopify 开发的模板语言",
75 }
76 }
77
78 pub fn default_extension(&self) -> &'static str {
80 match self {
81 Self::Custom => "tpl",
82 #[cfg(feature = "handlebars")]
83 Self::Handlebars => "hbs",
84 #[cfg(feature = "dejavu")]
85 Self::DejaVu => "dejavu",
86 #[cfg(feature = "jinja")]
87 Self::Jinja2 => "jinja2",
88 #[cfg(feature = "liquid")]
89 Self::Liquid => "liquid",
90 }
91 }
92}