Skip to content

Commit 324eee3

Browse files
TanX-009ys5g
authored andcommitted
feat: custom expr and block prefix, postfix
fix: revert keywords to custom_keywords
1 parent 80a7816 commit 324eee3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/template.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub struct Template {
3939
pub compare_to: Option<String>,
4040
pub pre_hook: Option<String>,
4141
pub post_hook: Option<String>,
42+
pub expr_prefix: Option<String>,
43+
pub expr_postfix: Option<String>,
44+
pub block_prefix: Option<String>,
45+
pub block_postfix: Option<String>,
4246
}
4347

4448
#[allow(clippy::manual_strip)]
@@ -78,11 +82,6 @@ impl Template {
7882
) -> Result<(), Report> {
7983
info!("Loaded <b><cyan>{}</> templates.", &templates.len());
8084

81-
let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build();
82-
let mut engine = Engine::with_syntax(syntax);
83-
84-
add_engine_filters(&mut engine);
85-
8685
let image = match &source {
8786
Source::Image { path } => Some(path),
8887
#[cfg(feature = "web-image")]
@@ -99,6 +98,19 @@ impl Template {
9998
)?;
10099

101100
for (i, (name, template)) in templates.iter().enumerate() {
101+
let expr_prefix = template.expr_prefix.as_deref().unwrap_or("{{");
102+
let expr_postfix = template.expr_postfix.as_deref().unwrap_or("}}");
103+
let block_prefix = template.block_prefix.as_deref().unwrap_or("<*");
104+
let block_postfix = template.block_postfix.as_deref().unwrap_or("*>");
105+
106+
let syntax = Syntax::builder()
107+
.expr(expr_prefix, expr_postfix)
108+
.block(block_prefix, block_postfix)
109+
.build();
110+
let mut engine = Engine::with_syntax(syntax);
111+
112+
add_engine_filters(&mut engine);
113+
102114
let (input_path_absolute, output_path_absolute) =
103115
get_absolute_paths(&config_path, template)?;
104116

0 commit comments

Comments
 (0)