diff --git a/src/main/java/dev/latvian/apps/webutils/html/LazyTagConvertible.java b/src/main/java/dev/latvian/apps/webutils/html/LazyTagConvertible.java deleted file mode 100644 index bc3a2a5..0000000 --- a/src/main/java/dev/latvian/apps/webutils/html/LazyTagConvertible.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.latvian.apps.webutils.html; - -import dev.latvian.apps.webutils.data.Lazy; - -public record LazyTagConvertible(Lazy lazy) implements TagConvertible { - @Override - public void appendHTMLTag(Tag parent) { - var t = lazy.get(); - - if (t != null) { - t.appendHTMLTag(parent); - } - } -} diff --git a/src/main/java/dev/latvian/apps/webutils/html/Tag.java b/src/main/java/dev/latvian/apps/webutils/html/Tag.java index 9d4dfb4..45f3ba1 100644 --- a/src/main/java/dev/latvian/apps/webutils/html/Tag.java +++ b/src/main/java/dev/latvian/apps/webutils/html/Tag.java @@ -2,7 +2,6 @@ import dev.latvian.apps.webutils.ansi.Ansi; import dev.latvian.apps.webutils.ansi.AnsiComponent; -import dev.latvian.apps.webutils.data.Lazy; import org.jetbrains.annotations.Nullable; import java.time.Instant; @@ -20,6 +19,10 @@ default Tag copy() { return this; } + default Tag end() { + throw new IllegalStateException("This tag type does not support end()"); + } + void append(StringBuilder builder, boolean header); void appendRaw(StringBuilder builder); @@ -145,18 +148,16 @@ default Tag raw(Object string) { return str.isEmpty() ? this : add(new RawTag(str)); } - default Tag lazy(Lazy lazy) { - return add(new LazyTagConvertible(lazy)); - } - default UnpairedTag unpaired(String name) { var tag = new UnpairedTag(name); + tag.parent = this; add(tag); return tag; } default PairedTag paired(String name) { var tag = new PairedTag(name); + tag.parent = this; add(tag); return tag; } @@ -500,6 +501,22 @@ default Tag u() { return paired("u"); } + default Tag svg(PairedTag xml) { + var svg = paired("svg"); + svg.attr("xmlns", "http://www.w3.org/2000/svg"); + svg.attr("fill", "currentcolor"); + + if (xml.attributes != null) { + svg.attributes.putAll(xml.attributes); + } + + for (var tag : xml.content) { + svg.add(tag); + } + + return svg; + } + // Form default String getPrefix() { diff --git a/src/main/java/dev/latvian/apps/webutils/html/UnpairedTag.java b/src/main/java/dev/latvian/apps/webutils/html/UnpairedTag.java index d2a6786..00e8db1 100644 --- a/src/main/java/dev/latvian/apps/webutils/html/UnpairedTag.java +++ b/src/main/java/dev/latvian/apps/webutils/html/UnpairedTag.java @@ -10,12 +10,22 @@ public class UnpairedTag implements Tag { public final String name; protected Map attributes; + public Tag parent; public UnpairedTag(String name) { this.name = name; this.attributes = null; } + @Override + public Tag end() { + if (parent == null) { + throw new IllegalStateException("This tag does not have a parent tag"); + } + + return parent; + } + @Override public Tag attr(String key, Object value) { if (key.isEmpty()) {