This commit is contained in:
Josh Thomas 2025-01-04 15:17:24 -06:00
parent 8bfead37b2
commit 0ea2dea1a9
3 changed files with 27 additions and 8 deletions

View file

@ -50,18 +50,21 @@ pub enum TagNode {
bits: Vec<String>, bits: Vec<String>,
children: Vec<Node>, children: Vec<Node>,
}, },
Branching { Branch {
name: String, name: String,
bits: Vec<String>, bits: Vec<String>,
children: Vec<Node>, children: Vec<Node>,
branches: Vec<TagNode>, },
Closing {
name: String,
bits: Vec<String>,
}, },
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
pub struct DjangoFilter { pub struct DjangoFilter {
name: String, pub name: String,
arguments: Vec<String>, pub arguments: Vec<String>,
} }
impl DjangoFilter { impl DjangoFilter {

View file

@ -5,15 +5,21 @@ use std::fs;
use std::path::Path; use std::path::Path;
use toml::Value; use toml::Value;
#[derive(Clone, Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct TagSpec { pub struct TagSpec {
#[serde(rename = "type")] #[serde(rename = "type")]
pub tag_type: TagType, pub tag_type: TagType,
pub closing: Option<String>, pub closing: Option<String>,
pub intermediates: Option<Vec<String>>, pub intermediates: Option<Vec<IntermediateSpec>>,
pub args: Option<Vec<ArgSpec>>, pub args: Option<Vec<ArgSpec>>,
} }
#[derive(Debug, Clone, Deserialize)]
pub struct IntermediateSpec {
pub name: String,
pub args: bool,
}
impl TagSpec { impl TagSpec {
pub fn load_builtin_specs() -> Result<HashMap<String, TagSpec>> { pub fn load_builtin_specs() -> Result<HashMap<String, TagSpec>> {
let specs_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tagspecs"); let specs_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tagspecs");

View file

@ -1,7 +1,14 @@
[django.template.defaulttags.if] [django.template.defaulttags.if]
type = "block" type = "block"
closing = "endif" 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]] [[django.template.defaulttags.if.args]]
name = "condition" name = "condition"
@ -10,7 +17,10 @@ required = true
[django.template.defaulttags.for] [django.template.defaulttags.for]
type = "block" type = "block"
closing = "endfor" closing = "endfor"
intermediates = ["empty"]
[[django.template.defaulttags.for.intermediates]]
name = "empty"
args = false
[[django.template.defaulttags.for.args]] [[django.template.defaulttags.for.args]]
name = "{item}" name = "{item}"