From 50f6f337739c4c71fe2146231bf0a501f1dd3fb5 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 6 Jan 2025 18:47:41 -0600 Subject: [PATCH] fixes --- crates/djls-template-ast/src/tagspecs.rs | 19 +++-------- crates/djls-template-ast/tagspecs/django.toml | 33 +++++++------------ 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/crates/djls-template-ast/src/tagspecs.rs b/crates/djls-template-ast/src/tagspecs.rs index 4bb976c..2e099c9 100644 --- a/crates/djls-template-ast/src/tagspecs.rs +++ b/crates/djls-template-ast/src/tagspecs.rs @@ -193,7 +193,6 @@ mod tests { fn test_builtin_django_tags() -> Result<(), anyhow::Error> { let specs = TagSpecs::load_builtin_specs()?; - // Just verify that common Django tags exist let expected_tags = ["if", "for", "block"]; let missing_tags = [ "extends", @@ -211,7 +210,11 @@ mod tests { } for tag in missing_tags { - assert!(specs.get(tag).is_none(), "{} tag should not be present yet", tag); + assert!( + specs.get(tag).is_none(), + "{} tag should not be present yet", + tag + ); } Ok(()) @@ -219,11 +222,9 @@ mod tests { #[test] fn test_user_defined_tags() -> Result<(), anyhow::Error> { - // Create a temporary directory for our test project let dir = tempfile::tempdir()?; let root = dir.path(); - // Create a pyproject.toml with custom tags let pyproject_content = r#" [tool.djls.template.tags.mytag] type = "block" @@ -233,14 +234,11 @@ args = [{ name = "myarg", required = true }] "#; fs::write(root.join("pyproject.toml"), pyproject_content)?; - // Load both builtin and user specs let specs = TagSpecs::load_all(root)?; - // Check that builtin tags are still there let if_tag = specs.get("if").expect("if tag should be present"); assert_eq!(if_tag.tag_type, TagType::Block); - // Check our custom tag let my_tag = specs.get("mytag").expect("mytag should be present"); assert_eq!(my_tag.tag_type, TagType::Block); assert_eq!(my_tag.closing, Some("endmytag".to_string())); @@ -256,18 +254,15 @@ args = [{ name = "myarg", required = true }] assert_eq!(arg.name, "myarg"); assert!(arg.required); - // Clean up temp dir dir.close()?; Ok(()) } #[test] fn test_config_file_priority() -> Result<(), anyhow::Error> { - // Create a temporary directory for our test project let dir = tempfile::tempdir()?; let root = dir.path(); - // Create all config files with different tags let djls_content = r#" [mytag1] type = "block" @@ -282,21 +277,17 @@ mytag2.closing = "endmytag2" "#; fs::write(root.join("pyproject.toml"), pyproject_content)?; - // Load user specs let specs = TagSpecs::load_user_specs(root)?; - // Should only have mytag1 since djls.toml has highest priority assert!(specs.get("mytag1").is_some(), "mytag1 should be present"); assert!( specs.get("mytag2").is_none(), "mytag2 should not be present" ); - // Remove djls.toml and try again fs::remove_file(root.join("djls.toml"))?; let specs = TagSpecs::load_user_specs(root)?; - // Should now have mytag2 since pyproject.toml has second priority assert!( specs.get("mytag1").is_none(), "mytag1 should not be present" diff --git a/crates/djls-template-ast/tagspecs/django.toml b/crates/djls-template-ast/tagspecs/django.toml index 0f1d68c..48b1e90 100644 --- a/crates/djls-template-ast/tagspecs/django.toml +++ b/crates/djls-template-ast/tagspecs/django.toml @@ -1,30 +1,19 @@ -# Django built-in template tags -[django.template.defaulttags.if] -branches = ["elif", "else"] -closing = "endif" +[django.template.defaulttags.block] +closing = "endblock" type = "block" -[[django.template.defaulttags.if.args]] -name = "condition" -required = true - [django.template.defaulttags.for] branches = ["empty"] closing = "endfor" type = "block" +args = [ + { name = "{item}", required = true }, + { name = "in", required = true }, + { name = "{iterable}", required = true }, +] -[[django.template.defaulttags.for.args]] -name = "{item}" -required = true - -[[django.template.defaulttags.for.args]] -name = "in" -required = true - -[[django.template.defaulttags.for.args]] -name = "{iterable}" -required = true - -[django.template.defaulttags.block] -closing = "endblock" +[django.template.defaulttags.if] +branches = ["elif", "else"] +closing = "endif" type = "block" +args = [{ name = "condition", required = true }]