Skip to content

Commit

Permalink
Re-added Tag#end()
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Oct 1, 2023
1 parent 41ea76f commit b279b84
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.

This file was deleted.

27 changes: 22 additions & 5 deletions src/main/java/dev/latvian/apps/webutils/html/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -145,18 +148,16 @@ default Tag raw(Object string) {
return str.isEmpty() ? this : add(new RawTag(str));
}

default Tag lazy(Lazy<? extends TagConvertible> 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;
}
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/latvian/apps/webutils/html/UnpairedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
public class UnpairedTag implements Tag {
public final String name;
protected Map<String, String> 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()) {
Expand Down

0 comments on commit b279b84

Please sign in to comment.