Gunslingor
03/22/2020, 3:11 AMspierce7
03/22/2020, 5:17 AMIf my JS is in my frontend and my templates are in my backend how could I ever organize by module?I’m not sure what you mean. If you want you can generate the html on the server, or you could generate it on the client side, whichever has the best pros / cons for what you are doing.
StringBuilder
.Gunslingor
03/23/2020, 12:41 AMdocument.getElementById("projection")?.innerHTML = createHTML {blah blah}
The above was going beyond just a long html string, it was generating each element with JS not HTML. Still not sure how to link these generated templates back in to the JS stuff but I presume that will present itself along the way?
Really wondering if my goal of programming everything in one multiplatform kotlin project is futile, lol.class DoublePaneView(val paneA: String, val paneB: String) {
val view = createHTML().div {
div {
paneA
}
div {
paneB
}
}
}
I considered using yoursspierce7
03/23/2020, 1:29 AMfun BodyContext.doublePaneView() {
div {
div {
paneA()
}
div {
paneB()
}
}
}
fun BodyContext.paneA() {
div(
style = {
displayFlex()
flexDirection(FlexDirection.COLUMN)
}
) {
+"Panel A"
}
}
fun BodyContext.paneB() {
div {
+"Panel B"
}
}
fun main() {
StringHtmlOutput().html {
body {
doublePaneView()
}
}
}
Gunslingor
03/23/2020, 1:33 AMspierce7
03/23/2020, 1:35 AMyou really think your plugin is better maintained than kotlinx though?I just found myself super frustrated with kotlinx. And the library had longstanding issues from 3+ years ago, and they weren’t going to get solved.
Gunslingor
03/23/2020, 1:42 AMspierce7
03/23/2020, 2:10 AMGunslingor
03/23/2020, 2:17 AMspierce7
03/23/2020, 2:21 AMGunslingor
03/23/2020, 3:36 AMfunction DoublePaneView$view$lambda($receiver) {
visitTag(new DIV_init(attributesMapOf('class', 'd-inline-block col-md-6 col-sm-12'), $receiver.consumer), visit$lambda(DoublePaneView$view$lambda$lambda));
visitTag(new DIV_init(attributesMapOf('class', 'd-inline-block col-md-6 col-sm-12'), $receiver.consumer), visit$lambda(DoublePaneView$view$lambda$lambda_0));
return Unit;
}
When I do the same html in the backend, I find the following string in the file \build\libs\FL-backend-1.0-SNAPSHOT\com\company
t ' real-body " !d-inline-block col-md-6 col-sm-12 • left_pane —
So I could (a) output the from js html templates I think that the backend consumes, (b) I could let JS do all the html building like the example above, or (c) I could generate the templates in the backend and get them packaged into this file I don't understand.... I'd like to understand it but I don't know what it is really. Not sure how to make a work but suspect gradle is supposed to control it. Can you confirm b is too slow in the long term, it seems fast now but I don't know? And if you have any hints or sources so I can better understand what that jar is, how it gets made by gradle and how my html ends up inside it... would be appreciated.spierce7
03/23/2020, 7:41 PMWhen I do the same html in the backend, I find the following string in the file \build\libs\FL-backend-1.0-SNAPSHOT\com\companyI have no idea what you are looking at
Gunslingor
03/23/2020, 7:46 PMspierce7
03/23/2020, 8:34 PMGunslingor
03/23/2020, 11:33 PMspierce7
03/24/2020, 12:54 AMGunslingor
03/24/2020, 12:56 AMspierce7
03/24/2020, 1:02 AMfun BodyContext.doublePaneView() {
div {
div {
paneA()
}
div {
paneB()
}
}
}
fun BodyContext.paneA() {
div(
style = {
displayFlex()
flexDirection(FlexDirection.COLUMN)
}
) {
+"Panel A"
}
}
fun BodyContext.paneB() {
div {
+"Panel B"
}
}
Gunslingor
03/24/2020, 1:06 AMspierce7
03/24/2020, 1:06 AMpublic final class SimpleBenchmarkMainKt {
public static final void doublePaneView_caaDT_8/* $FF was: doublePaneView-caaDT-8*/(@NotNull HtmlWriter $this$doublePaneView) {
Intrinsics.checkParameterIsNotNull($this$doublePaneView, "$this$doublePaneView");
String id$iv = (String)null;
String classes$iv = (String)null;
Function1 style$iv = (Function1)null;
int var5 = false;
ElementUtilKt.writeNormalElementStart($this$doublePaneView, "div", id$iv, classes$iv, style$iv);
int var7 = false;
String id$iv = (String)null;
String classes$iv = (String)null;
Function1 style$iv = (Function1)null;
int var12 = false;
ElementUtilKt.writeNormalElementStart($this$doublePaneView, "div", id$iv, classes$iv, style$iv);
int var14 = false;
paneA-caaDT-8($this$doublePaneView);
ElementUtilKt.writeNormalElementEnd($this$doublePaneView, "div");
id$iv = (String)null;
classes$iv = (String)null;
style$iv = (Function1)null;
var12 = false;
ElementUtilKt.writeNormalElementStart($this$doublePaneView, "div", id$iv, classes$iv, style$iv);
var14 = false;
paneB-caaDT-8($this$doublePaneView);
ElementUtilKt.writeNormalElementEnd($this$doublePaneView, "div");
ElementUtilKt.writeNormalElementEnd($this$doublePaneView, "div");
}
public static final void paneA_caaDT_8/* $FF was: paneA-caaDT-8*/(@NotNull HtmlWriter $this$paneA) {
Intrinsics.checkParameterIsNotNull($this$paneA, "$this$paneA");
Function1 style$iv = (Function1)null.INSTANCE;
String id$iv = (String)null;
String classes$iv = (String)null;
int var5 = false;
ElementUtilKt.writeNormalElementStart($this$paneA, "div", id$iv, classes$iv, style$iv);
int var7 = false;
BodyContext.unaryPlus-impl($this$paneA, (CharSequence)"Panel A");
ElementUtilKt.writeNormalElementEnd($this$paneA, "div");
}
public static final void paneB_caaDT_8/* $FF was: paneB-caaDT-8*/(@NotNull HtmlWriter $this$paneB) {
Intrinsics.checkParameterIsNotNull($this$paneB, "$this$paneB");
String id$iv = (String)null;
String classes$iv = (String)null;
Function1 style$iv = (Function1)null;
int var5 = false;
ElementUtilKt.writeNormalElementStart($this$paneB, "div", id$iv, classes$iv, style$iv);
int var7 = false;
BodyContext.unaryPlus-impl($this$paneB, (CharSequence)"Panel B");
ElementUtilKt.writeNormalElementEnd($this$paneB, "div");
}
}
public final class DivDslKt$div$1 extends Lambda implements Function1 {
public static final DivDslKt$div$1 INSTANCE = new DivDslKt$div$1();
// $FF: synthetic method
// $FF: bridge method
public Object invoke(Object var1) {
this.invoke(((BodyContext)var1).unbox-impl());
return Unit.INSTANCE;
}
public final void invoke(@NotNull HtmlWriter $receiver) {
Intrinsics.checkParameterIsNotNull($receiver, "$receiver");
}
public DivDslKt$div$1() {
super(1);
}
}
Gunslingor
03/24/2020, 1:08 AMspierce7
03/24/2020, 1:08 AMGunslingor
03/24/2020, 1:09 AMspierce7
03/24/2020, 1:09 AMGunslingor
03/24/2020, 1:09 AMspierce7
03/24/2020, 1:12 AMclass Person(var name: String? = null, var age: Int? = null)
fun person(func: Person.() -> Unit): Person {
val person = Person()
person.func()
return Person()
}
fun main() {
person {
name = "John Doe"
age = 30
}
}
Gunslingor
03/24/2020, 1:18 AMspierce7
03/24/2020, 1:19 AMchildren
list to the object, and a child
extension function:@DslMarker
annotation class PersonDsl
@PersonDsl
class Person(
var name: String? = null,
var age: Int? = null,
val children: MutableList<Person> = mutableListOf()
)
@PersonDsl
inline fun person(func: Person.() -> Unit): Person {
val person = Person()
person.func()
return Person()
}
@PersonDsl
inline fun Person.child(func: Person.() -> Unit) {
children += person(func)
}
fun main() {
person {
name = "Grandma"
age = 75
child {
name = "Dad"
age = 30
child {
name = "Baby"
age = 1
}
}
}
}
Gunslingor
03/24/2020, 1:20 AMspierce7
03/24/2020, 1:20 AMPerson
objects.Gunslingor
03/24/2020, 1:21 AMspierce7
03/24/2020, 1:21 AMStringBuilder
:@DslMarker
annotation class HtmlDsl
@HtmlDsl
inline fun StringBuilder.html(func: StringBuilder.() -> Unit) {
append("<html>")
func()
append("</html>")
}
@HtmlDsl
inline fun StringBuilder.body(func: StringBuilder.() -> Unit) {
append("<body>")
func()
append("</body>")
}
@HtmlDsl
inline fun StringBuilder.div(func: StringBuilder.() -> Unit) {
append("<div>")
func()
append("</div>")
}
fun main() {
StringBuilder().html {
body {
div {
}
}
}
}
Gunslingor
03/24/2020, 1:27 AMspierce7
03/24/2020, 1:28 AMGunslingor
03/24/2020, 1:28 AMspierce7
03/24/2020, 1:29 AMGunslingor
03/24/2020, 1:29 AMspierce7
03/24/2020, 1:29 AMGunslingor
03/24/2020, 1:30 AMspierce7
03/24/2020, 1:30 AMGunslingor
03/24/2020, 1:31 AMspierce7
03/24/2020, 1:31 AMGunslingor
03/24/2020, 1:31 AMspierce7
03/24/2020, 1:32 AMGunslingor
03/24/2020, 1:32 AMspierce7
03/24/2020, 1:32 AMGunslingor
03/24/2020, 2:45 AM