diff --git a/crates/djls-template-ast/src/ast.rs b/crates/djls-template-ast/src/ast.rs index 672b075..2072520 100644 --- a/crates/djls-template-ast/src/ast.rs +++ b/crates/djls-template-ast/src/ast.rs @@ -50,18 +50,21 @@ pub enum TagNode { bits: Vec, children: Vec, }, - Branching { + Branch { name: String, bits: Vec, children: Vec, - branches: Vec, + }, + Closing { + name: String, + bits: Vec, }, } #[derive(Clone, Debug, Serialize)] pub struct DjangoFilter { - name: String, - arguments: Vec, + pub name: String, + pub arguments: Vec, } impl DjangoFilter { diff --git a/crates/djls-template-ast/src/tagspecs.rs b/crates/djls-template-ast/src/tagspecs.rs index e7c744f..4f6201d 100644 --- a/crates/djls-template-ast/src/tagspecs.rs +++ b/crates/djls-template-ast/src/tagspecs.rs @@ -5,15 +5,21 @@ use std::fs; use std::path::Path; use toml::Value; -#[derive(Clone, Debug, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct TagSpec { #[serde(rename = "type")] pub tag_type: TagType, pub closing: Option, - pub intermediates: Option>, + pub intermediates: Option>, pub args: Option>, } +#[derive(Debug, Clone, Deserialize)] +pub struct IntermediateSpec { + pub name: String, + pub args: bool, +} + impl TagSpec { pub fn load_builtin_specs() -> Result> { let specs_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tagspecs"); diff --git a/crates/djls-template-ast/tagspecs/django.toml b/crates/djls-template-ast/tagspecs/django.toml index 7eb1b35..b934466 100644 --- a/crates/djls-template-ast/tagspecs/django.toml +++ b/crates/djls-template-ast/tagspecs/django.toml @@ -1,7 +1,14 @@ [django.template.defaulttags.if] type = "block" closing = "endif" -intermediates = ["else", "elif"] + +[[django.template.defaulttags.if.intermediates]] +name = "elif" +args = true + +[[django.template.defaulttags.if.intermediates]] +name = "else" +args = false [[django.template.defaulttags.if.args]] name = "condition" @@ -10,7 +17,10 @@ required = true [django.template.defaulttags.for] type = "block" closing = "endfor" -intermediates = ["empty"] + +[[django.template.defaulttags.for.intermediates]] +name = "empty" +args = false [[django.template.defaulttags.for.args]] name = "{item}"