Skip to content

Commit 4b250f4

Browse files
authored
Merge pull request #140 from xmlet/development
New workflow action and new fragments support in htmlflow-kotlin
2 parents 0e3f5d2 + 56a9672 commit 4b250f4

File tree

11 files changed

+314
-71
lines changed

11 files changed

+314
-71
lines changed

.github/workflows/format-check.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Spotless Check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- development
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
11+
jobs:
12+
format-check:
13+
name: Spotless Check
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v1
22+
with:
23+
java-version: 17
24+
- name: Check code formatting with Spotless
25+
run: mvn spotless:check -B
26+
- name: Comment on failed formatting
27+
if: failure() && github.event_name == 'pull_request'
28+
uses: thollander/actions-comment-pull-request@v1
29+
with:
30+
message: |
31+
Please run `mvn spotless:apply` locally to fix the formatting issues, then commit and push the changes.
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

flowifier/src/test/java/htmlflow/flowifier/FlowifierTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
6060
}
6161
}
6262

63-
@Test
64-
public void testFlowifierTuerSourceforgeHomepage() throws Exception {
65-
testFlowifier("https://tuer.sourceforge.io/en/");
66-
}
67-
6863
@Test
6964
public void testFlowifierWithGamboa() throws Exception {
7065
testFlowifier("https://gamboa.pt/");

htmlflow-core/src/main/java/htmlflow/HtmlPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.xmlet.htmlapifaster.Div;
3737
import org.xmlet.htmlapifaster.Element;
3838
import org.xmlet.htmlapifaster.Html;
39+
import org.xmlet.htmlapifaster.Span;
3940
import org.xmlet.htmlapifaster.Tr;
4041

4142
/**
@@ -85,6 +86,10 @@ public final Tr<HtmlPage> tr() {
8586
return new Tr<>(this);
8687
}
8788

89+
public final Span<HtmlPage> span() {
90+
return new Span<>(this);
91+
}
92+
8893
/**
8994
* Returns a new instance of HtmlFlow with the same properties of this object but with indented
9095
* set to the value of isIndented parameter.

htmlflow-core/src/main/java/htmlflow/visitor/PreprocessingVisitorAsync.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ public <M, E extends Element> void visitAwait(
6464
*/
6565
indentAndAdvanceStaticBlockIndex();
6666
}
67-
6867
}

htmlflow-core/src/test/java/htmlflow/test/TestDivDetails.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testDivDetailsWithoutBinding() {
105105
public void testDivDetailsBinding() {
106106
ByteArrayOutputStream mem = new ByteArrayOutputStream();
107107
HtmlView view = HtmlFlow
108-
.view(new PrintStream(mem), HtmlLists::taskDetailsTemplate);
108+
.view(new PrintStream(mem), HtmlLists::taskDetailsTemplate);
109109

110110
expectedTaskViews
111111
.keySet()
@@ -120,33 +120,21 @@ public void testDivDetailsBinding() {
120120
expectedTaskViews
121121
.get(taskHtml.obj)
122122
.forEach(
123-
line ->
124-
assertEquals(line,
125-
actual.next()));
123+
line ->
124+
assertEquals(line,
125+
actual.next()));
126126
});
127127
}
128128

129-
private static class TaskHtml {
130-
final Task obj;
131-
final Stream<String> html;
132-
public TaskHtml(Task obj, Stream<String> html) {
133-
this.obj = obj;
134-
this.html = html;
135-
}
136-
static TaskHtml of(Task t, Stream<String> html) {
137-
return new TaskHtml(t, html);
138-
}
139-
}
140-
141129
@Test
142130
public void testWritePartialViewToPrintStream() {
143131
ByteArrayOutputStream mem = new ByteArrayOutputStream();
144132
HtmlTables
145-
.taskListViewHeader(HtmlFlow.doc(new PrintStream(mem)));
133+
.taskListViewHeader(HtmlFlow.doc(new PrintStream(mem)));
146134

147135
Iterator<String> iter = NEWLINE
148-
.splitAsStream(mem.toString())
149-
.iterator();
136+
.splitAsStream(mem.toString())
137+
.iterator();
150138

151139
Utils
152140
.loadLines("partialViewHeader.html")
@@ -156,4 +144,32 @@ public void testWritePartialViewToPrintStream() {
156144
assertEquals(expected, actual);
157145
});
158146
}
147+
148+
@Test
149+
public void testThatSpanElementCanBeUsedOnHtmlDocAsRootElement() {
150+
StringBuilder mem = new StringBuilder();
151+
HtmlFlow.doc(mem).span().text("I am the root element of an HTML fragment!").__();
152+
Iterator<String> actual = NEWLINE
153+
.splitAsStream(mem.toString().trim())
154+
.iterator();
155+
Stream
156+
.of("<span>", "I am the root element of an HTML fragment!", "</span>")
157+
.forEach(expected -> {
158+
assertEquals(expected, actual.next().trim());
159+
});
160+
}
161+
162+
private static class TaskHtml {
163+
final Task obj;
164+
final Stream<String> html;
165+
166+
public TaskHtml(Task obj, Stream<String> html) {
167+
this.obj = obj;
168+
this.html = html;
169+
}
170+
171+
static TaskHtml of(Task t, Stream<String> html) {
172+
return new TaskHtml(t, html);
173+
}
174+
}
159175
}

htmlflow-kotlin/src/main/kotlin/htmlflow/HtmlFlowExtensions.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ package htmlflow
44
import htmlflow.continuations.HtmlContinuationSuspendableTerminationNode
55
import htmlflow.visitor.HtmlVisitor
66
import htmlflow.visitor.PreprocessingVisitor
7+
import org.xmlet.htmlapifaster.Div
78
import org.xmlet.htmlapifaster.Element
89
import org.xmlet.htmlapifaster.Html
10+
import org.xmlet.htmlapifaster.Span
911
import org.xmlet.htmlapifaster.Text
12+
import org.xmlet.htmlapifaster.Tr
1013

1114
/** Alternative close tag function for `__()`. */
1215
inline val <T : Element<*, Z>, Z : Element<*, *>> T.l: Z
@@ -20,10 +23,13 @@ inline val HtmlPage.html: Html<HtmlPage>
2023
}
2124

2225
/** Root builder of HTML element with lambda with receiver. */
23-
inline fun HtmlPage.html(block: Html<HtmlPage>.() -> Unit): HtmlPage {
24-
(this.visitor as HtmlVisitor).write(HtmlPage.HEADER)
25-
return Html(self()).also { it.block() }.l
26-
}
26+
inline fun HtmlPage.html(block: Html<HtmlPage>.() -> Unit): HtmlPage = this.html().apply(block).l
27+
28+
inline fun HtmlPage.div(block: Div<HtmlPage>.() -> Unit): HtmlPage = this.div().apply(block).l
29+
30+
inline fun HtmlPage.tr(block: Tr<HtmlPage>.() -> Unit): HtmlPage = this.tr().apply(block).l
31+
32+
inline fun HtmlPage.span(block: Span<HtmlPage>.() -> Unit): HtmlPage = this.span().apply(block).l
2733

2834
/** Text node property. */
2935
inline var <T : Element<T, Z>, Z : Element<*, *>> T.text: T

htmlflow-kotlin/src/main/kotlin/htmlflow/HtmlViewVisitorSuspend.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import htmlflow.continuations.HtmlContinuationSuspendable
44
import htmlflow.visitor.HtmlVisitorSuspending
55
import java.util.function.BiConsumer
66
import org.xmlet.htmlapifaster.Element
7-
import org.xmlet.htmlapifaster.SuspendConsumer
87
import org.xmlet.htmlapifaster.async.AwaitConsumer
98

109
/**

htmlflow-kotlin/src/main/kotlin/htmlflow/HtmlViewVisitorSuspendHot.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package htmlflow
33
import htmlflow.visitor.HtmlVisitorSuspending
44
import java.util.function.BiConsumer
55
import org.xmlet.htmlapifaster.Element
6-
import org.xmlet.htmlapifaster.SuspendConsumer
76
import org.xmlet.htmlapifaster.async.AwaitConsumer
87

98
/**

htmlflow-kotlin/src/main/kotlin/htmlflow/PreprocessingVisitorSuspend.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,10 @@ class PreprocessingVisitorSuspend(isIndented: Boolean) : PreprocessingVisitorAsy
8383
}
8484

8585
/**
86-
* Follows a different visit approach not inherited from the parent class, because
87-
* it is a Java class that we want to keep free of kotlin dependencies like suspend functions.
86+
* Follows a different visit approach not inherited from the parent class, because it is a Java
87+
* class that we want to keep free of kotlin dependencies like suspend functions.
8888
*/
89-
fun <E : Element<*, *>, M> visitSuspending(
90-
element: E,
91-
suspendAction: SuspendConsumer<E, M>,
92-
) {
89+
fun <E : Element<*, *>, M> visitSuspending(element: E, suspendAction: SuspendConsumer<E, M>) {
9390
/** Creates an HtmlContinuation for a suspending block. */
9491
val suspCont: HtmlContinuation =
9592
HtmlContinuationSuspending(

0 commit comments

Comments
 (0)