From 00f3fb3c478d1490bd9a0a62a1687dce4a3c202f Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 6 Jan 2025 23:06:08 -0600 Subject: [PATCH] rename tag enum member to single --- crates/djls-template-ast/SPEC.md | 38 +++++++++---------- crates/djls-template-ast/src/ast.rs | 6 +-- crates/djls-template-ast/src/parser.rs | 12 +++--- ...__django__parse_django_tag_assignment.snap | 2 +- crates/djls-template-ast/src/tagspecs.rs | 2 +- crates/djls-template-ast/tagspecs/django.toml | 14 +++---- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/crates/djls-template-ast/SPEC.md b/crates/djls-template-ast/SPEC.md index 870a7af..061ee4e 100644 --- a/crates/djls-template-ast/SPEC.md +++ b/crates/djls-template-ast/SPEC.md @@ -119,14 +119,14 @@ pub enum Block { tag: Tag, nodes: Vec, }, - Tag { + Closing { tag: Tag, }, Inclusion { tag: Tag, template_name: String, }, - Closing { + Single { tag: Tag, }, } @@ -194,21 +194,21 @@ Examples: - `{% else %}` - `{% empty %}` -##### `Block::Tag` +##### `Block::Closing` -Represents standalone tags that do not contain child nodes or require a closing tag. +Represents closing tags corresponding to opening block tags. ```rust -Block::Tag { - tag: Tag, // The Tag of the standalone tag +Block::Closing { + tag: Tag, // The Tag of the closing tag } ``` Examples: -- `{% csrf_token %}` -- `{% load %}` -- `{% now "Y-m-d" %}` +- `{% endif %}` +- `{% endfor %}` +- `{% endwith %}` ##### `Block::Inclusion` @@ -226,21 +226,21 @@ Examples: - `{% include "template.html" %}` - `{% extends "base.html" %}` -##### `Block::Closing` +##### `Block::Single` -Represents closing tags corresponding to opening block tags. +Represents standalone tags that do not contain child nodes or require a closing tag. ```rust -Block::Closing { - tag: Tag, // The Tag of the closing tag +Block::Single { + tag: Tag, // The Tag of the standalone tag } ``` Examples: -- `{% endif %}` -- `{% endfor %}` -- `{% endwith %}` +- `{% csrf_token %}` +- `{% load %}` +- `{% now "Y-m-d" %}` ## TagSpecs @@ -250,7 +250,7 @@ Tag Specifications (TagSpecs) define how tags are parsed and understood. They al ```toml [package.module.path.tag_name] # Path where tag is registered, e.g., django.template.defaulttags -type = "block" | "inclusion" | "tag" +type = "block" | "inclusion" | "single" closing = "closing_tag_name" # For block tags that require a closing tag branches = ["branch_tag_name", ...] # For block tags that support branches @@ -281,7 +281,7 @@ The `name` field in args should match the internal name used in Django's node im {% include "partial.html" %} ``` -- `tag`: Single tags that don't wrap content +- `single`: Single tags that don't wrap content ```django {% csrf_token %} @@ -325,7 +325,7 @@ args = [{ name = "setting", required = true, allowed_values = ["on", "off"] }] ```toml [my_module.templatetags.my_tags.my_custom_tag] -type = "tag" +type = "single" args = [ { name = "arg1", required = true }, { name = "kwarg1", required = false, is_kwarg = true } diff --git a/crates/djls-template-ast/src/ast.rs b/crates/djls-template-ast/src/ast.rs index 5e8bed4..2feda7f 100644 --- a/crates/djls-template-ast/src/ast.rs +++ b/crates/djls-template-ast/src/ast.rs @@ -154,14 +154,14 @@ pub enum Block { tag: Tag, nodes: Vec, }, - Tag { + Closing { tag: Tag, }, Inclusion { tag: Tag, template_name: String, }, - Closing { + Single { tag: Tag, }, } @@ -171,7 +171,7 @@ impl Block { match self { Self::Block { tag, .. } | Self::Branch { tag, .. } - | Self::Tag { tag } + | Self::Single { tag } | Self::Inclusion { tag, .. } | Self::Closing { tag } => tag, } diff --git a/crates/djls-template-ast/src/parser.rs b/crates/djls-template-ast/src/parser.rs index c063ad0..2c5c02b 100644 --- a/crates/djls-template-ast/src/parser.rs +++ b/crates/djls-template-ast/src/parser.rs @@ -121,14 +121,14 @@ impl Parser { match spec { Some(spec) => match spec.tag_type { TagType::Block => self.parse_block_tag(tag, spec), - TagType::Tag => Ok(Node::Block(Block::Tag { tag })), + TagType::Single => Ok(Node::Block(Block::Single { tag })), TagType::Inclusion => { let template_name = tag.bits.get(1).cloned().unwrap_or_default(); Ok(Node::Block(Block::Inclusion { tag, template_name })) } }, - None => Ok(Node::Block(Block::Tag { tag })), + None => Ok(Node::Block(Block::Single { tag })), } } @@ -138,14 +138,14 @@ impl Parser { while !self.is_at_end() { match self.next_node() { - Ok(Node::Block(Block::Tag { tag: inner_tag })) => { + Ok(Node::Block(Block::Single { tag: inner_tag })) => { if self.is_closing_tag(&inner_tag, spec) { closing = Some(Box::new(Block::Closing { tag: inner_tag })); break; } else if self.is_branch_tag(&inner_tag, spec) { nodes.push(self.parse_branch_tag(inner_tag, spec)?); } else { - nodes.push(Node::Block(Block::Tag { tag: inner_tag })); + nodes.push(Node::Block(Block::Single { tag: inner_tag })); } } Ok(node) => nodes.push(node), @@ -173,13 +173,13 @@ impl Parser { while !self.is_at_end() { match self.next_node() { - Ok(Node::Block(Block::Tag { tag: inner_tag })) => { + Ok(Node::Block(Block::Single { tag: inner_tag })) => { if self.is_closing_tag(&inner_tag, spec) || self.is_branch_tag(&inner_tag, spec) { self.backtrack(1)?; break; } else { - branch_nodes.push(Node::Block(Block::Tag { tag: inner_tag })); + branch_nodes.push(Node::Block(Block::Single { tag: inner_tag })); } } Ok(node) => branch_nodes.push(node), diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_tag_assignment.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_tag_assignment.snap index c863418..cec9ce5 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_tag_assignment.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_tag_assignment.snap @@ -4,7 +4,7 @@ expression: ast --- nodes: - Block: - Tag: + Single: tag: name: url bits: diff --git a/crates/djls-template-ast/src/tagspecs.rs b/crates/djls-template-ast/src/tagspecs.rs index 7e0c6ed..80b54a9 100644 --- a/crates/djls-template-ast/src/tagspecs.rs +++ b/crates/djls-template-ast/src/tagspecs.rs @@ -138,7 +138,7 @@ impl TagSpec { #[serde(rename_all = "lowercase")] pub enum TagType { Block, - Tag, + Single, Inclusion, } diff --git a/crates/djls-template-ast/tagspecs/django.toml b/crates/djls-template-ast/tagspecs/django.toml index abd8cb6..35282d9 100644 --- a/crates/djls-template-ast/tagspecs/django.toml +++ b/crates/djls-template-ast/tagspecs/django.toml @@ -13,14 +13,14 @@ closing = "endcomment" [django.template.defaulttags.cycle] -type = "tag" +type = "single" args = [ { name = "cyclevars", required = true }, { name = "variable_name", required = false, is_kwarg = true }, ] [django.template.defaulttags.debug] -type = "tag" +type = "single" [django.template.defaulttags.extends] type = "inclusion" @@ -42,7 +42,7 @@ closing = "endfilter" args = [{ name = "filter_expr", required = true }] [django.template.defaulttags.firstof] -type = "tag" +type = "single" args = [{ name = "variables", required = true }] [django.template.defaulttags.if] @@ -60,11 +60,11 @@ args = [ ] [django.template.defaulttags.load] -type = "tag" +type = "single" args = [{ name = "library", required = true }] [django.template.defaulttags.now] -type = "tag" +type = "single" args = [{ name = "format_string", required = true }] [django.template.defaulttags.spaceless] @@ -72,7 +72,7 @@ type = "block" closing = "endspaceless" [django.template.defaulttags.templatetag] -type = "tag" +type = "single" [[django.template.defaulttags.templatetag.args]] name = "tagtype" @@ -89,7 +89,7 @@ allowed_values = [ ] [django.template.defaulttags.url] -type = "tag" +type = "single" args = [ { name = "view_name", required = true }, { name = "asvar", required = false, is_kwarg = true },