-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Tag to interface, removed parent tag, .end()
- Loading branch information
1 parent
5f156fe
commit 7f4d6eb
Showing
13 changed files
with
276 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/java/dev/latvian/apps/webutils/html/LazyRawTag.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/latvian/apps/webutils/html/LazyTagConvertible.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.latvian.apps.webutils.html; | ||
|
||
import dev.latvian.apps.webutils.data.Lazy; | ||
|
||
public record LazyTagConvertible(Lazy<? extends TagConvertible> lazy) implements TagConvertible { | ||
@Override | ||
public void appendHTMLTag(Tag parent) { | ||
var t = lazy.get(); | ||
|
||
if (t != null) { | ||
t.appendHTMLTag(parent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/dev/latvian/apps/webutils/html/ResponseTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.latvian.apps.webutils.html; | ||
|
||
import dev.latvian.apps.webutils.net.FileResponse; | ||
import dev.latvian.apps.webutils.net.Response; | ||
import io.javalin.http.HttpStatus; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public interface ResponseTag { | ||
String getMimeType(); | ||
|
||
default Response asResponse() { | ||
return asResponse(HttpStatus.OK, true); | ||
} | ||
|
||
default Response asResponse(HttpStatus status, boolean header) { | ||
return FileResponse.of(status, getMimeType(), ((Tag) this).toTagString(header).getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 7 additions & 16 deletions
23
src/main/java/dev/latvian/apps/webutils/html/StringTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,33 @@ | ||
package dev.latvian.apps.webutils.html; | ||
|
||
import dev.latvian.apps.webutils.ansi.AnsiComponent; | ||
|
||
import java.io.Writer; | ||
|
||
public class StringTag extends Tag { | ||
public class StringTag implements Tag { | ||
public final String string; | ||
|
||
public StringTag(String string) { | ||
this.string = string; | ||
} | ||
|
||
@Override | ||
public String getRawContent() { | ||
return TagUtils.encode(string); | ||
public String toString() { | ||
return string; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return string.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean isEmptyRecursively() { | ||
return string.isEmpty(); | ||
} | ||
|
||
public StringTag child(String string) { | ||
return new StringTag(string); | ||
} | ||
|
||
@Override | ||
public void write(Writer writer) throws Throwable { | ||
writer.write(getRawContent()); | ||
public void append(StringBuilder builder, boolean header) { | ||
TagUtils.encode(builder, string); | ||
} | ||
|
||
@Override | ||
public void ansi(AnsiComponent component, int depth, int indent) { | ||
component.append(getRawContent()); | ||
public void appendRaw(StringBuilder builder) { | ||
TagUtils.encode(builder, string); | ||
} | ||
} |
Oops, something went wrong.