From 33a2d3f09291ae4ff0892e3e87c40bc65828f5a1 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 17 Mar 2024 00:30:22 +0000 Subject: [PATCH] Allow `not` to negate, doesn't produce syntax error in HTML fragments in Eclipse --- README.md | 8 ++++++++ src/main/java/com/sshtools/tinytemplate/Templates.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f33c046..5e68096 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,14 @@ And the Java. model.condition("feelingFriendly", false); ``` +Conditions can be negated by prefixing the name with either a `!` or the more XML syntax friendly `not`. + +```html + +

Humbug!

+
+``` + If no such named condition exists, then checks will be made to see if a *Variable* with the same name exists. If it doesn't exist, the condition will evaluate as `false`. If it does exist however, then it's result will depend on the value and it's type. diff --git a/src/main/java/com/sshtools/tinytemplate/Templates.java b/src/main/java/com/sshtools/tinytemplate/Templates.java index 3855edd..a023547 100644 --- a/src/main/java/com/sshtools/tinytemplate/Templates.java +++ b/src/main/java/com/sshtools/tinytemplate/Templates.java @@ -745,7 +745,9 @@ private Condition(boolean negate, String name) { } private static Condition parse(String cond) { - if(cond.startsWith("!")) + if(cond.startsWith("not")) + return new Condition(true, cond.substring(4)); + else if(cond.startsWith("!")) return new Condition(true, cond.substring(1)); else return new Condition(false, cond);