import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Consumer;
-import kotlin.Unit;
-import kotlin.jvm.functions.Function1;
-import kotlinx.html.Tag;
import net.pterodactylus.rhynodge.Reaction;
import net.pterodactylus.rhynodge.State;
import net.pterodactylus.rhynodge.filters.EpisodeFilter;
import static kotlinx.html.Gen_tags_tKt.thead;
import static kotlinx.html.Gen_tags_tKt.tr;
import static kotlinx.html.stream.StreamKt.createHTML;
+import static net.pterodactylus.util.dom.KotlinXHtml.wrapper;
/**
* {@link State} implementation that stores episodes of TV shows, parsed via
return String.format("%s[episodes=%s]", getClass().getSimpleName(), episodes);
}
- private static <T extends Tag> Function1<T, Unit> wrapper(Consumer<T> tagConsumer) {
- return t -> {
- tagConsumer.accept(t);
- return null;
- };
- }
-
/**
* Stores attributes for an episode.
*
--- /dev/null
+package net.pterodactylus.util.dom;
+
+import java.util.function.Consumer;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function1;
+import kotlinx.html.Tag;
+
+/**
+ * Helper class that collects methods for use of {@link kotlinx.html} from
+ * Java.
+ */
+public class KotlinXHtml {
+
+ /**
+ * Can be used to wrap the block body during HTML construction. It
+ * removes the need to construct lambdas that require a
+ * {@code return null;} at the end to satisfy {@link Function1}’s
+ * second type parameter, {@link Unit}.
+ *
+ * <h2>Usage</h2>
+ * <pre>
+ * html(output, null, wrapper(html -> {
+ * body(html, null, wrapper(body -> {
+ * // add more HTML
+ * }));
+ * }));
+ * </pre>
+ *
+ * @param tagConsumer The body to wrap
+ * @param <T> The type of tag
+ * @return A Kotlin {@link Function1} wrapper around the given
+ * {@code tagConsumer}
+ */
+ public static <T extends Tag> Function1<T, Unit> wrapper(Consumer<T> tagConsumer) {
+ return t -> {
+ tagConsumer.accept(t);
+ return null;
+ };
+ }
+
+}