Skip to content

Commit

Permalink
Merge pull request #50 from InkApplications/tweaks
Browse files Browse the repository at this point in the history
Script convenience methods and partial calls
  • Loading branch information
ReneeVandervelde authored Oct 6, 2024
2 parents 10ac6f6 + 8557602 commit 26f522e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 48 deletions.
29 changes: 25 additions & 4 deletions render-static-html/api/render-static-html.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@ public abstract interface class ink/ui/render/statichtml/InkUiBuilder {
public abstract fun addPageHeader (Lkotlin/jvm/functions/Function1;)V
public abstract fun addStyle (Ljava/lang/String;)V
public abstract fun elementRenderer (Link/ui/render/statichtml/renderer/ElementRenderer;)V
public abstract fun getCodeBlocks ()Z
public abstract fun getContentBreak ()Z
public abstract fun getInkFooter ()Z
public abstract fun getResourceBaseUrl ()Ljava/lang/String;
public abstract fun getSectioned ()Z
public abstract fun getTitle ()Ljava/lang/String;
public abstract fun include (Ljava/lang/String;)V
public abstract fun resource (Ljava/lang/String;)Ljava/lang/String;
public abstract fun setCodeBlocks (Z)V
public abstract fun setContentBreak (Z)V
public abstract fun setInkFooter (Z)V
public abstract fun setResourceBaseUrl (Ljava/lang/String;)V
public abstract fun setSectioned (Z)V
public abstract fun setTitle (Ljava/lang/String;)V
}

public final class ink/ui/render/statichtml/InkUiConfig : kotlin/script/experimental/api/ScriptCompilationConfiguration {
Expand All @@ -45,6 +57,7 @@ public abstract class ink/ui/render/statichtml/InkUiScript : ink/ui/render/stati
public final fun getSectioned ()Z
public final fun getTitle ()Ljava/lang/String;
public fun include (Ljava/lang/String;)V
public fun resource (Ljava/lang/String;)Ljava/lang/String;
public final fun setCodeBlocks (Z)V
public final fun setContentBreak (Z)V
public final fun setInkFooter (Z)V
Expand All @@ -58,10 +71,6 @@ public final class ink/ui/render/statichtml/InkUiScript$Companion {
public static synthetic fun evalFile$default (Link/ui/render/statichtml/InkUiScript$Companion;Ljava/io/File;[Link/ui/render/statichtml/renderer/ElementRenderer;[Ljava/lang/String;ILjava/lang/Object;)Lkotlin/script/experimental/api/ResultWithDiagnostics;
}

public final class ink/ui/render/statichtml/MainKt {
public static final fun main ([Ljava/lang/String;)V
}

public abstract class ink/ui/render/statichtml/PartialScript : ink/ui/render/statichtml/InkUiBuilder {
public fun <init> (Link/ui/render/statichtml/InkUiScript;)V
public fun addBody (Link/ui/structures/layouts/UiLayout;)V
Expand All @@ -72,8 +81,20 @@ public abstract class ink/ui/render/statichtml/PartialScript : ink/ui/render/sta
public fun addPageHeader (Lkotlin/jvm/functions/Function1;)V
public fun addStyle (Ljava/lang/String;)V
public fun elementRenderer (Link/ui/render/statichtml/renderer/ElementRenderer;)V
public fun getCodeBlocks ()Z
public fun getContentBreak ()Z
public fun getInkFooter ()Z
public fun getResourceBaseUrl ()Ljava/lang/String;
public fun getSectioned ()Z
public fun getTitle ()Ljava/lang/String;
public fun include (Ljava/lang/String;)V
public fun resource (Ljava/lang/String;)Ljava/lang/String;
public fun setCodeBlocks (Z)V
public fun setContentBreak (Z)V
public fun setInkFooter (Z)V
public fun setResourceBaseUrl (Ljava/lang/String;)V
public fun setSectioned (Z)V
public fun setTitle (Ljava/lang/String;)V
}

public final class ink/ui/render/statichtml/renderer/BreadcrumbRendererKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import ink.ui.structures.layouts.UiLayout
import kotlinx.html.TagConsumer

interface InkUiBuilder {
val resourceBaseUrl: String
var title: String?
var sectioned: Boolean
var contentBreak: Boolean
var inkFooter: Boolean
var codeBlocks: Boolean
var resourceBaseUrl: String
fun addPageHeader(element: UiElement)
fun addPageHeader(block: TagConsumer<*>.() -> Unit)
fun addBody(block: TagConsumer<*>.() -> Unit)
Expand All @@ -16,4 +21,5 @@ interface InkUiBuilder {
fun elementRenderer(elementRenderer: ElementRenderer)
fun addPageFooter(element: UiElement)
fun addPageFooter(block: TagConsumer<*>.() -> Unit)
fun resource(name: String): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ abstract class InkUiScript(
private var styles: MutableList<String> = mutableListOf()
private var scripts: MutableList<String> = mutableListOf()
private val document = createHTMLDocument()
var title: String? = null
var sectioned: Boolean = false
var contentBreak: Boolean = false
var inkFooter: Boolean = false
var codeBlocks: Boolean = false
final override var title: String? = null
final override var sectioned: Boolean = false
final override var contentBreak: Boolean = false
final override var inkFooter: Boolean = false
final override var codeBlocks: Boolean = false
final override var resourceBaseUrl: String = "https://ui.inkapplications.com/res"
set(value) {
field = value
Expand Down Expand Up @@ -80,9 +80,16 @@ abstract class InkUiScript(
).valueOrThrow()
}

override fun resource(name: String): String {
if (resourceBaseUrl.isBlank()) {
return name
}
return "$resourceBaseUrl/$name"
}

private fun getStyles(): List<String> {
return listOf(
"$resourceBaseUrl/css/main-2.0.css",
resource("css/main-2.0.css"),
) + styles
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ object ListRenderer: ElementRenderer {
Positioning.Center -> "justify-content: center"
}
element.items.forEach { item ->
div {
renderWith(item, consumer, parent)
when (element.groupingStyle) {
GroupingStyle.Unified -> renderWith(item, consumer, parent)
else -> div {
renderWith(item, consumer, parent)
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions structures/api/structures.api
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public final class ink/ui/structures/elements/DividerElement : ink/ui/structures
public final class ink/ui/structures/elements/ElementList : ink/ui/structures/elements/UiElement$Static {
public fun <init> (Ljava/util/List;Link/ui/structures/Positioning;Link/ui/structures/GroupingStyle;Link/ui/structures/elements/Orientation;)V
public synthetic fun <init> (Ljava/util/List;Link/ui/structures/Positioning;Link/ui/structures/GroupingStyle;Link/ui/structures/elements/Orientation;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> ([Link/ui/structures/elements/UiElement;Link/ui/structures/Positioning;Link/ui/structures/GroupingStyle;Link/ui/structures/elements/Orientation;)V
public synthetic fun <init> ([Link/ui/structures/elements/UiElement;Link/ui/structures/Positioning;Link/ui/structures/GroupingStyle;Link/ui/structures/elements/Orientation;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Link/ui/structures/Positioning;
public final fun component3 ()Link/ui/structures/GroupingStyle;
Expand Down Expand Up @@ -483,6 +485,7 @@ public final class ink/ui/structures/layouts/CenteredElementLayout : ink/ui/stru

public final class ink/ui/structures/layouts/FixedGridLayout : ink/ui/structures/layouts/UiLayout {
public fun <init> (ILjava/util/List;)V
public fun <init> ([Link/ui/structures/layouts/FixedGridLayout$GridItem;I)V
public final fun component1 ()I
public final fun component2 ()Ljava/util/List;
public final fun copy (ILjava/util/List;)Link/ui/structures/layouts/FixedGridLayout;
Expand Down Expand Up @@ -526,6 +529,8 @@ public final class ink/ui/structures/layouts/PageLayout : ink/ui/structures/layo
public final class ink/ui/structures/layouts/ScrollingListLayout : ink/ui/structures/layouts/UiLayout {
public fun <init> (Ljava/util/List;Link/ui/structures/GroupingStyle;)V
public synthetic fun <init> (Ljava/util/List;Link/ui/structures/GroupingStyle;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> ([Link/ui/structures/elements/UiElement;Link/ui/structures/GroupingStyle;)V
public synthetic fun <init> ([Link/ui/structures/elements/UiElement;Link/ui/structures/GroupingStyle;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Link/ui/structures/GroupingStyle;
public final fun copy (Ljava/util/List;Link/ui/structures/GroupingStyle;)Link/ui/structures/layouts/ScrollingListLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ data class ElementList(
* Direction of flow for the elements.
*/
val orientation: Orientation = Orientation.Vertical,
): UiElement.Static
): UiElement.Static {
constructor(
vararg items: UiElement,
positioning: Positioning = Positioning.Start,
groupingStyle: GroupingStyle = GroupingStyle.Items,
orientation: Orientation = Orientation.Vertical,
): this(
items = items.toList(),
positioning = positioning,
groupingStyle = groupingStyle,
orientation = orientation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ data class FixedGridLayout(
*/
val items: List<GridItem>,
): UiLayout {
constructor(
vararg items: GridItem,
columns: Int,
): this(
columns = columns,
items = items.toList(),
)

/**
* An individual item to display in the grid.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ data class ScrollingListLayout(
* Signifiers for indicating how the elements are related to each other.
*/
val groupingStyle: GroupingStyle = GroupingStyle.Items,
): UiLayout
): UiLayout {
constructor(
vararg items: UiElement,
groupingStyle: GroupingStyle = GroupingStyle.Items,
): this(
items = items.toList(),
groupingStyle = groupingStyle,
)
}

0 comments on commit 26f522e

Please sign in to comment.