Skip to content

Commit 8df956f

Browse files
add args
1 parent 261ed6b commit 8df956f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

crates/djls-templates/src/templatetags/builtins.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
4343
intermediate_tags: Some(vec![
4444
IntermediateTag {
4545
name: "elif".to_string(),
46+
args: vec![TagArg::expr("condition", true)],
4647
},
4748
IntermediateTag {
4849
name: "else".to_string(),
50+
args: vec![],
4951
},
5052
]),
5153
args: vec![TagArg::expr("condition", true)],
@@ -59,6 +61,7 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
5961
}),
6062
intermediate_tags: Some(vec![IntermediateTag {
6163
name: "empty".to_string(),
64+
args: vec![],
6265
}]),
6366
args: vec![
6467
TagArg::var("item", true),
@@ -76,6 +79,7 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
7679
}),
7780
intermediate_tags: Some(vec![IntermediateTag {
7881
name: "else".to_string(),
82+
args: vec![],
7983
}]),
8084
args: vec![TagArg::varargs("variables", false)],
8185
},
@@ -327,6 +331,7 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
327331
}),
328332
intermediate_tags: Some(vec![IntermediateTag {
329333
name: "plural".to_string(),
334+
args: vec![TagArg::var("count", false)],
330335
}]),
331336
args: vec![
332337
TagArg::string("context", false),

crates/djls-templates/src/templatetags/specs.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ impl From<djls_conf::EndTagDef> for EndTag {
272272
#[derive(Debug, Clone, PartialEq)]
273273
pub struct IntermediateTag {
274274
pub name: String,
275+
pub args: Vec<TagArg>,
275276
}
276277

277278
impl From<djls_conf::IntermediateTagDef> for IntermediateTag {
278279
fn from(value: djls_conf::IntermediateTagDef) -> Self {
279280
IntermediateTag {
280281
name: value.name,
281-
// Note: IntermediateTagDef has args field but IntermediateTag doesn't
282-
// This is intentional - we don't support args on intermediate tags yet
282+
args: value.args.into_iter().map(Into::into).collect(),
283283
}
284284
}
285285
}
@@ -316,9 +316,11 @@ mod tests {
316316
intermediate_tags: Some(vec![
317317
IntermediateTag {
318318
name: "elif".to_string(),
319+
args: vec![TagArg::expr("condition", true)],
319320
},
320321
IntermediateTag {
321322
name: "else".to_string(),
323+
args: vec![],
322324
},
323325
]),
324326
args: vec![],
@@ -338,9 +340,11 @@ mod tests {
338340
intermediate_tags: Some(vec![
339341
IntermediateTag {
340342
name: "empty".to_string(),
343+
args: vec![],
341344
},
342345
IntermediateTag {
343346
name: "else".to_string(),
347+
args: vec![],
344348
}, // Note: else is shared
345349
]),
346350
args: vec![],
@@ -662,10 +666,16 @@ mod tests {
662666
// Test IntermediateTagDef -> IntermediateTag conversion
663667
let intermediate_def = djls_conf::IntermediateTagDef {
664668
name: "elif".to_string(),
665-
args: vec![], // These are ignored in conversion
669+
args: vec![djls_conf::TagArgDef {
670+
name: "condition".to_string(),
671+
required: true,
672+
arg_type: djls_conf::ArgTypeDef::Simple(djls_conf::SimpleArgTypeDef::Expression),
673+
}],
666674
};
667675
let intermediate = IntermediateTag::from(intermediate_def);
668676
assert_eq!(intermediate.name, "elif");
677+
assert_eq!(intermediate.args.len(), 1);
678+
assert_eq!(intermediate.args[0].name, "condition");
669679

670680
// Test full TagSpecDef -> TagSpec conversion
671681
let tagspec_def = djls_conf::TagSpecDef {
@@ -692,6 +702,10 @@ mod tests {
692702
tagspec.intermediate_tags.as_ref().unwrap()[0].name,
693703
"branch"
694704
);
705+
assert_eq!(
706+
tagspec.intermediate_tags.as_ref().unwrap()[0].args.len(),
707+
0
708+
);
695709
}
696710

697711
#[test]

0 commit comments

Comments
 (0)