#![warn(missing_docs)]
use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub enum TemplateEngine {
Custom,
#[cfg(feature = "handlebars")]
Handlebars,
#[cfg(feature = "dejavu")]
DejaVu,
#[cfg(feature = "jinja")]
Jinja2,
#[cfg(feature = "liquid")]
Liquid,
}
impl TemplateEngine {
pub fn all() -> &'static [Self] {
#[cfg(all(not(feature = "handlebars"), not(feature = "dejavu"), not(feature = "jinja"), not(feature = "liquid")))]
{
&[Self::Custom]
}
#[cfg(any(feature = "handlebars", feature = "dejavu", feature = "jinja", feature = "liquid"))]
{
&[
Self::Custom,
#[cfg(feature = "handlebars")] Self::Handlebars,
#[cfg(feature = "dejavu")] Self::DejaVu,
#[cfg(feature = "jinja")] Self::Jinja2,
#[cfg(feature = "liquid")] Self::Liquid,
]
}
}
pub fn display_name(&self) -> &'static str {
match self {
Self::Custom => "自定义",
#[cfg(feature = "handlebars")]
Self::Handlebars => "Handlebars",
#[cfg(feature = "dejavu")]
Self::DejaVu => "DejaVu",
#[cfg(feature = "jinja")]
Self::Jinja2 => "Jinja2",
#[cfg(feature = "liquid")]
Self::Liquid => "Liquid",
}
}
pub fn description(&self) -> &'static str {
match self {
Self::Custom => "自定义模板引擎",
#[cfg(feature = "handlebars")]
Self::Handlebars => "Handlebars 模板引擎,流行的 JavaScript 模板语言",
#[cfg(feature = "dejavu")]
Self::DejaVu => "DejaVu 模板引擎,编译期零成本抽象",
#[cfg(feature = "jinja")]
Self::Jinja2 => "Jinja2 模板引擎,Python 生态系统中流行的模板语言",
#[cfg(feature = "liquid")]
Self::Liquid => "Liquid 模板引擎,Shopify 开发的模板语言",
}
}
pub fn default_extension(&self) -> &'static str {
match self {
Self::Custom => "tpl",
#[cfg(feature = "handlebars")]
Self::Handlebars => "hbs",
#[cfg(feature = "dejavu")]
Self::DejaVu => "dejavu",
#[cfg(feature = "jinja")]
Self::Jinja2 => "jinja2",
#[cfg(feature = "liquid")]
Self::Liquid => "liquid",
}
}
}