Skip to content

Commit ad293c6

Browse files
rename block type to container
1 parent 00f3fb3 commit ad293c6

14 files changed

+71
-71
lines changed

crates/djls-template-ast/SPEC.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ Represents Django template tags that may have nested content, assignments, and c
110110

111111
```rust
112112
pub enum Block {
113-
Block {
114-
tag: Tag,
115-
nodes: Vec<Node>,
116-
closing: Option<Box<Block>>,
117-
},
118113
Branch {
119114
tag: Tag,
120115
nodes: Vec<Node>,
121116
},
122117
Closing {
123118
tag: Tag,
124119
},
120+
Container {
121+
tag: Tag,
122+
nodes: Vec<Node>,
123+
closing: Option<Box<Block>>,
124+
},
125125
Inclusion {
126126
tag: Tag,
127127
template_name: String,
@@ -159,24 +159,6 @@ pub struct Assignment {
159159

160160
#### Variants
161161

162-
##### `Block::Block`
163-
164-
Represents standard block tags that may contain child nodes and require a closing tag.
165-
166-
```rust
167-
Block::Block {
168-
tag: Tag, // The opening Tag of the block
169-
nodes: Vec<Node>, // Nodes contained within the block
170-
closing: Option<Box<Block>>, // Contains Block::Closing if present
171-
}
172-
```
173-
174-
Examples:
175-
176-
- `{% if %}...{% endif %}`
177-
- `{% for %}...{% endfor %}`
178-
- `{% with %}...{% endwith %}`
179-
180162
##### `Block::Branch`
181163

182164
Represents branch tags that are part of control flow structures and contain child nodes.
@@ -210,6 +192,24 @@ Examples:
210192
- `{% endfor %}`
211193
- `{% endwith %}`
212194

195+
##### `Block::Container`
196+
197+
Represents standard block tags that may contain child nodes and require a closing tag.
198+
199+
```rust
200+
Block::Block {
201+
tag: Tag, // The opening Tag of the block
202+
nodes: Vec<Node>, // Nodes contained within the block
203+
closing: Option<Box<Block>>, // Contains Block::Closing if present
204+
}
205+
```
206+
207+
Examples:
208+
209+
- `{% if %}...{% endif %}`
210+
- `{% for %}...{% endfor %}`
211+
- `{% with %}...{% endwith %}`
212+
213213
##### `Block::Inclusion`
214214

215215
Represents tags that include or extend templates.
@@ -250,7 +250,7 @@ Tag Specifications (TagSpecs) define how tags are parsed and understood. They al
250250

251251
```toml
252252
[package.module.path.tag_name] # Path where tag is registered, e.g., django.template.defaulttags
253-
type = "block" | "inclusion" | "single"
253+
type = "container" | "inclusion" | "single"
254254
closing = "closing_tag_name" # For block tags that require a closing tag
255255
branches = ["branch_tag_name", ...] # For block tags that support branches
256256

@@ -267,7 +267,7 @@ The `name` field in args should match the internal name used in Django's node im
267267

268268
### Tag Types
269269

270-
- `block`: Tags that wrap content and require a closing tag
270+
- `container`: Tags that wrap content and require a closing tag
271271

272272
```django
273273
{% if condition %}content{% endif %}
@@ -298,7 +298,7 @@ The `name` field in args should match the internal name used in Django's node im
298298

299299
```toml
300300
[django.template.defaulttags.if]
301-
type = "block"
301+
type = "container"
302302
closing = "endif"
303303
branches = ["elif", "else"]
304304
args = [{ name = "condition", required = true }]
@@ -316,7 +316,7 @@ args = [{ name = "template_name", required = true }]
316316

317317
```toml
318318
[django.template.defaulttags.autoescape]
319-
type = "block"
319+
type = "container"
320320
closing = "endautoescape"
321321
args = [{ name = "setting", required = true, allowed_values = ["on", "off"] }]
322322
```

crates/djls-template-ast/src/ast.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ impl Node {
145145

146146
#[derive(Debug, Clone, Serialize)]
147147
pub enum Block {
148-
Block {
149-
tag: Tag,
150-
nodes: Vec<Node>,
151-
closing: Option<Box<Block>>,
152-
},
153148
Branch {
154149
tag: Tag,
155150
nodes: Vec<Node>,
156151
},
157152
Closing {
158153
tag: Tag,
159154
},
155+
Container {
156+
tag: Tag,
157+
nodes: Vec<Node>,
158+
closing: Option<Box<Block>>,
159+
},
160160
Inclusion {
161161
tag: Tag,
162162
template_name: String,
@@ -169,7 +169,7 @@ pub enum Block {
169169
impl Block {
170170
pub fn tag(&self) -> &Tag {
171171
match self {
172-
Self::Block { tag, .. }
172+
Self::Container { tag, .. }
173173
| Self::Branch { tag, .. }
174174
| Self::Single { tag }
175175
| Self::Inclusion { tag, .. }
@@ -179,15 +179,15 @@ impl Block {
179179

180180
pub fn nodes(&self) -> Option<&Vec<Node>> {
181181
match self {
182-
Block::Block { nodes, .. } => Some(nodes),
182+
Block::Container { nodes, .. } => Some(nodes),
183183
Block::Branch { nodes, .. } => Some(nodes),
184184
_ => None,
185185
}
186186
}
187187

188188
pub fn closing(&self) -> Option<&Block> {
189189
match self {
190-
Block::Block { closing, .. } => closing.as_deref(),
190+
Block::Container { closing, .. } => closing.as_deref(),
191191
_ => None,
192192
}
193193
}
@@ -306,7 +306,7 @@ mod tests {
306306

307307
#[test]
308308
fn test_block_spans() {
309-
let nodes = vec![Node::Block(Block::Block {
309+
let nodes = vec![Node::Block(Block::Container {
310310
tag: Tag {
311311
name: "if".to_string(),
312312
bits: vec!["user.is_authenticated".to_string()],
@@ -341,7 +341,7 @@ mod tests {
341341
assert!(errors.is_empty());
342342

343343
let nodes = ast.nodes();
344-
if let Node::Block(Block::Block {
344+
if let Node::Block(Block::Container {
345345
tag,
346346
nodes,
347347
closing,

crates/djls-template-ast/src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Parser {
120120

121121
match spec {
122122
Some(spec) => match spec.tag_type {
123-
TagType::Block => self.parse_block_tag(tag, spec),
123+
TagType::Container => self.parse_block_tag(tag, spec),
124124
TagType::Single => Ok(Node::Block(Block::Single { tag })),
125125
TagType::Inclusion => {
126126
let template_name = tag.bits.get(1).cloned().unwrap_or_default();
@@ -161,7 +161,7 @@ impl Parser {
161161
.push(ParserError::Ast(AstError::UnclosedTag(tag.name.clone())));
162162
}
163163

164-
Ok(Node::Block(Block::Block {
164+
Ok(Node::Block(Block::Container {
165165
tag,
166166
nodes,
167167
closing,

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: ast
44
---
55
nodes:
66
- Block:
7-
Block:
7+
Container:
88
tag:
99
name: if
1010
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: ast
44
---
55
nodes:
66
- Block:
7-
Block:
7+
Container:
88
tag:
99
name: for
1010
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: ast
44
---
55
nodes:
66
- Block:
7-
Block:
7+
Container:
88
tag:
99
name: if
1010
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_mixed_content.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ nodes:
99
start: 0
1010
length: 8
1111
- Block:
12-
Block:
12+
Container:
1313
tag:
1414
name: if
1515
bits:
@@ -43,7 +43,7 @@ nodes:
4343
start: 47
4444
length: 31
4545
- Block:
46-
Block:
46+
Container:
4747
tag:
4848
name: for
4949
bits:
@@ -60,7 +60,7 @@ nodes:
6060
assignment: ~
6161
nodes:
6262
- Block:
63-
Block:
63+
Container:
6464
tag:
6565
name: if
6666
bits:
@@ -101,7 +101,7 @@ nodes:
101101
start: 171
102102
length: 10
103103
- Block:
104-
Block:
104+
Container:
105105
tag:
106106
name: if
107107
bits:
@@ -135,7 +135,7 @@ nodes:
135135
length: 5
136136
assignment: ~
137137
- Block:
138-
Block:
138+
Container:
139139
tag:
140140
name: if
141141
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_nested_for_if.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: ast
44
---
55
nodes:
66
- Block:
7-
Block:
7+
Container:
88
tag:
99
name: for
1010
bits:
@@ -21,7 +21,7 @@ nodes:
2121
assignment: ~
2222
nodes:
2323
- Block:
24-
Block:
24+
Container:
2525
tag:
2626
name: if
2727
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_error_recovery.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ nodes:
1414
start: 28
1515
length: 15
1616
- Block:
17-
Block:
17+
Container:
1818
tag:
1919
name: if
2020
bits:
@@ -62,7 +62,7 @@ nodes:
6262
start: 198
6363
length: 41
6464
- Block:
65-
Block:
65+
Container:
6666
tag:
6767
name: for
6868
bits:

crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_for.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ expression: ast
44
---
55
nodes:
66
- Block:
7-
Block:
7+
Container:
88
tag:
99
name: for
1010
bits:

0 commit comments

Comments
 (0)