Skip to content

Commit 50f6f33

Browse files
fixes
1 parent cd128c3 commit 50f6f33

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ mod tests {
193193
fn test_builtin_django_tags() -> Result<(), anyhow::Error> {
194194
let specs = TagSpecs::load_builtin_specs()?;
195195

196-
// Just verify that common Django tags exist
197196
let expected_tags = ["if", "for", "block"];
198197
let missing_tags = [
199198
"extends",
@@ -211,19 +210,21 @@ mod tests {
211210
}
212211

213212
for tag in missing_tags {
214-
assert!(specs.get(tag).is_none(), "{} tag should not be present yet", tag);
213+
assert!(
214+
specs.get(tag).is_none(),
215+
"{} tag should not be present yet",
216+
tag
217+
);
215218
}
216219

217220
Ok(())
218221
}
219222

220223
#[test]
221224
fn test_user_defined_tags() -> Result<(), anyhow::Error> {
222-
// Create a temporary directory for our test project
223225
let dir = tempfile::tempdir()?;
224226
let root = dir.path();
225227

226-
// Create a pyproject.toml with custom tags
227228
let pyproject_content = r#"
228229
[tool.djls.template.tags.mytag]
229230
type = "block"
@@ -233,14 +234,11 @@ args = [{ name = "myarg", required = true }]
233234
"#;
234235
fs::write(root.join("pyproject.toml"), pyproject_content)?;
235236

236-
// Load both builtin and user specs
237237
let specs = TagSpecs::load_all(root)?;
238238

239-
// Check that builtin tags are still there
240239
let if_tag = specs.get("if").expect("if tag should be present");
241240
assert_eq!(if_tag.tag_type, TagType::Block);
242241

243-
// Check our custom tag
244242
let my_tag = specs.get("mytag").expect("mytag should be present");
245243
assert_eq!(my_tag.tag_type, TagType::Block);
246244
assert_eq!(my_tag.closing, Some("endmytag".to_string()));
@@ -256,18 +254,15 @@ args = [{ name = "myarg", required = true }]
256254
assert_eq!(arg.name, "myarg");
257255
assert!(arg.required);
258256

259-
// Clean up temp dir
260257
dir.close()?;
261258
Ok(())
262259
}
263260

264261
#[test]
265262
fn test_config_file_priority() -> Result<(), anyhow::Error> {
266-
// Create a temporary directory for our test project
267263
let dir = tempfile::tempdir()?;
268264
let root = dir.path();
269265

270-
// Create all config files with different tags
271266
let djls_content = r#"
272267
[mytag1]
273268
type = "block"
@@ -282,21 +277,17 @@ mytag2.closing = "endmytag2"
282277
"#;
283278
fs::write(root.join("pyproject.toml"), pyproject_content)?;
284279

285-
// Load user specs
286280
let specs = TagSpecs::load_user_specs(root)?;
287281

288-
// Should only have mytag1 since djls.toml has highest priority
289282
assert!(specs.get("mytag1").is_some(), "mytag1 should be present");
290283
assert!(
291284
specs.get("mytag2").is_none(),
292285
"mytag2 should not be present"
293286
);
294287

295-
// Remove djls.toml and try again
296288
fs::remove_file(root.join("djls.toml"))?;
297289
let specs = TagSpecs::load_user_specs(root)?;
298290

299-
// Should now have mytag2 since pyproject.toml has second priority
300291
assert!(
301292
specs.get("mytag1").is_none(),
302293
"mytag1 should not be present"
Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
# Django built-in template tags
2-
[django.template.defaulttags.if]
3-
branches = ["elif", "else"]
4-
closing = "endif"
1+
[django.template.defaulttags.block]
2+
closing = "endblock"
53
type = "block"
64

7-
[[django.template.defaulttags.if.args]]
8-
name = "condition"
9-
required = true
10-
115
[django.template.defaulttags.for]
126
branches = ["empty"]
137
closing = "endfor"
148
type = "block"
9+
args = [
10+
{ name = "{item}", required = true },
11+
{ name = "in", required = true },
12+
{ name = "{iterable}", required = true },
13+
]
1514

16-
[[django.template.defaulttags.for.args]]
17-
name = "{item}"
18-
required = true
19-
20-
[[django.template.defaulttags.for.args]]
21-
name = "in"
22-
required = true
23-
24-
[[django.template.defaulttags.for.args]]
25-
name = "{iterable}"
26-
required = true
27-
28-
[django.template.defaulttags.block]
29-
closing = "endblock"
15+
[django.template.defaulttags.if]
16+
branches = ["elif", "else"]
17+
closing = "endif"
3018
type = "block"
19+
args = [{ name = "condition", required = true }]

0 commit comments

Comments
 (0)