Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ fun pluginId(pluginName: String, version: String) = "$pluginName:$pluginName.gra
dependencies {
implementation(libs.nexus.publish)
implementation(pluginId("org.jetbrains.kotlin.multiplatform", "2.1.0"))
implementation(pluginId("net.kigawa.renlin-compiler", "1.3.8"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
kotlin("multiplatform")

id("net.kigawa.renlin-compiler")
}


Expand Down
14 changes: 8 additions & 6 deletions generate/src/jvmMain/kotlin/generator/DslGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class DslGenerator(
fun generate() {
// DSLクラスの生成
(tagCategories.map { it.allowedCategories } +
tagCategories.flatMap { it.allowedCategories.categories }.map { AllowedCategories(it) })
tagCategories.flatMap { it.allowedCategories.categories }.map { AllowedCategories(it) })
.filter { it.categories.isNotEmpty() }
.forEach { allowedCategories ->
val dslName = allowedCategories.connectedStr() + "Dsl"
if (!processedDsls.contains(dslName)) {
processedDsls.add(dslName)
val categories = allowedCategories.categories

val extends = categories
.filter { it.trim() + "Dsl" != dslName.trim() }
.map { "${it}Dsl<CATEGORY_DSL>" } +
"StatedDsl<CATEGORY_DSL>"

val imports = mutableListOf<String>()

Expand All @@ -35,16 +38,15 @@ class DslGenerator(
allowedCategories.connectedStr()
}"
}
import net.kigawa.renlin.dsl.StatedDsl


/**
* DSL for ${categories.joinToString(", ")}
*/
interface ${dslName}<CATEGORY_DSL : ${allowedCategories.connectedStr()}>${
if (categories.size <= 1) ""
else (categories.filter { it.trim() != dslName.trim() }
.joinToString(separator = ",", prefix = ":")
{ "\n ${it}Dsl<CATEGORY_DSL>" })
(extends.joinToString(separator = ",", prefix = ":")
{ "\n $it" })
}
""".trimIndent()

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Gradle
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4096M"
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8
kotlin.daemon.jvmargs=-Xmx4096M
org.gradle.caching=true
# https://github.com/gradle/gradle/issues/22779 le sigh
#org.gradle.configuration-cache=true
Expand Down
9 changes: 9 additions & 0 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/AutoFill.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.kigawa.renlin

/**
* Marks a parameter for automatic value injection when passed as null.
* When applied to a function parameter, the plugin will automatically generate and inject a value if null is passed for this parameter.
*/
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
annotation class AutoFill
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.kigawa.renlin.component

import net.kigawa.renlin.AutoFill
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.tag.Tag
import net.kigawa.renlin.w3c.category.ContentCategory

interface Component0<out TAG: Tag<in CONTENT_CATEGORY>, CONTENT_CATEGORY: ContentCategory>: Component<TAG> {
fun render(parentDsl: StatedDsl<out CONTENT_CATEGORY>, key: String?)
fun render(parentDsl: StatedDsl<out CONTENT_CATEGORY>, @AutoFill key: String?)

}
113 changes: 57 additions & 56 deletions renlin/src/commonMain/kotlin/net/kigawa/renlin/dsl/StatedDsl.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kigawa.renlin.dsl

import net.kigawa.hakate.api.state.State
import net.kigawa.renlin.AutoFill
import net.kigawa.renlin.component.*
import net.kigawa.renlin.state.DslState
import net.kigawa.renlin.tag.Fragment
Expand All @@ -25,7 +26,7 @@ import net.kigawa.renlin.w3c.element.TagNode
*
* @param CONTENT_CATEGORY このDSLが生成できるHTMLコンテンツのカテゴリ
*/
interface StatedDsl< CONTENT_CATEGORY: ContentCategory>: Dsl {
interface StatedDsl<CONTENT_CATEGORY: ContentCategory>: Dsl {
/**
* 現在のDSLに関連付けられた状態。
* この状態はDSLの動作と描画を制御します。
Expand Down Expand Up @@ -58,66 +59,66 @@ interface StatedDsl< CONTENT_CATEGORY: ContentCategory>: Dsl {


operator fun <TAG: Tag<in CONTENT_CATEGORY>> Component0<TAG, in CONTENT_CATEGORY>.invoke(
key: String? = null,
@AutoFill key: String? = null,
) = this.render(this@StatedDsl, key)

/**
* コンポーネントを呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param block コンポーネントの内容を定義するブロック
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, DSL> Component1<TAG, in CONTENT_CATEGORY, DSL>.invoke(
key: String? = null, block: DSL,
) {
return [email protected](this@StatedDsl, block, key)
}
/**
* コンポーネントを呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param block コンポーネントの内容を定義するブロック
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, DSL> Component1<TAG, in CONTENT_CATEGORY, DSL>.invoke(
@AutoFill key: String? = null, block: DSL,
) {
return [email protected](this@StatedDsl, block, key)
}

/**
* Component2を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2> Component2<TAG, in CONTENT_CATEGORY, ARG1, ARG2>.invoke(
arg1: ARG1, arg2: ARG2, key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, key)
}
/**
* Component2を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2> Component2<TAG, in CONTENT_CATEGORY, ARG1, ARG2>.invoke(
arg1: ARG1, arg2: ARG2, @AutoFill key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, key)
}

/**
* Component3を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @param arg3 第3引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2, ARG3> Component3<TAG, in CONTENT_CATEGORY, ARG1, ARG2, ARG3>.invoke(
arg1: ARG1, arg2: ARG2, arg3: ARG3, key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, arg3, key)
}
/**
* Component3を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @param arg3 第3引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2, ARG3> Component3<TAG, in CONTENT_CATEGORY, ARG1, ARG2, ARG3>.invoke(
arg1: ARG1, arg2: ARG2, arg3: ARG3, @AutoFill key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, arg3, key)
}

/**
* Component4を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @param arg3 第3引数
* @param arg4 第4引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2, ARG3, ARG4> Component4<TAG, in CONTENT_CATEGORY, ARG1, ARG2, ARG3, ARG4>.invoke(
arg1: ARG1, arg2: ARG2, arg3: ARG3, arg4: ARG4, key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, arg3, arg4, key)
}
/**
* Component4を呼び出し、レンダリングするための演算子オーバーロード。
*
* @param key コンポーネントの一意のキー(オプション)
* @param arg1 第1引数
* @param arg2 第2引数
* @param arg3 第3引数
* @param arg4 第4引数
* @return コンポーネントのレンダリング結果
*/
operator fun <TAG: Tag<in CONTENT_CATEGORY>, ARG1, ARG2, ARG3, ARG4> Component4<TAG, in CONTENT_CATEGORY, ARG1, ARG2, ARG3, ARG4>.invoke(
arg1: ARG1, arg2: ARG2, arg3: ARG3, arg4: ARG4, @AutoFill key: String? = null,
) {
return [email protected](this@StatedDsl, arg1, arg2, arg3, arg4, key)
}


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.kigawa.renlin.state

import net.kigawa.renlin.AutoFill
import net.kigawa.renlin.w3c.event.WebPointerEvent
import kotlin.reflect.KClass
import kotlin.reflect.typeOf
Expand Down Expand Up @@ -42,7 +43,7 @@ data class DslStateData(
* @param T 追加データの値の型
* @param key 追加データの一意のキー
*/
inline fun <reified T : Any> setAdditionalData(contextClass: KClass<*>, value: T, key: String? = null) {
inline fun <reified T : Any> setAdditionalData(contextClass: KClass<*>, value: T, @AutoFill key: String? = null) {
removeAdditionalData<T>(contextClass)
additionalData = additionalData + AdditionalDslStateData(
contextClass, typeOf<T>(), key, value
Expand All @@ -55,7 +56,7 @@ data class DslStateData(
* @param T 追加データの値の型
* @param key 追加データの一意のキー
*/
inline fun <reified T : Any> removeAdditionalData(contextClass: KClass<*>,key: String? = null) {
inline fun <reified T : Any> removeAdditionalData(contextClass: KClass<*>, @AutoFill key: String? = null) {
additionalData = additionalData.filter {
it.contextClass != contextClass || it.valueType != typeOf<T>() || it.key != key
}
Expand All @@ -71,7 +72,7 @@ data class DslStateData(
* @return 一致するデータが見つかった場合はその値、見つからない場合はnul
*
*/
inline fun <reified T : Any> getAdditionalData(contextClass: KClass<*>, key: String? = null): T? {
inline fun <reified T : Any> getAdditionalData(contextClass: KClass<*>, @AutoFill key: String? = null): T? {
@Suppress("UNCHECKED_CAST")
return additionalData
.firstOrNull {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.kigawa.renlin.w3c.category

import net.kigawa.renlin.AutoFill
import net.kigawa.renlin.dsl.StatedDsl
import net.kigawa.renlin.tag.text
import net.kigawa.renlin.w3c.category.native.PhrasingContent


fun <CONTENT_CATEGORY : PhrasingContent> StatedDsl<out CONTENT_CATEGORY>.t(str: String, key: String? = null) {
fun <CONTENT_CATEGORY: PhrasingContent> StatedDsl<out CONTENT_CATEGORY>.t(str: String, @AutoFill key: String? = null) {
text.render(this, {
[email protected] = str
}, key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.native.AutocapitalizeInheritingFormContent
import net.kigawa.renlin.dsl.StatedDsl


/**
* DSL for AutocapitalizeInheritingFormContent
*/
interface AutocapitalizeInheritingFormContentDsl<CATEGORY_DSL : AutocapitalizeInheritingFormContent>
interface AutocapitalizeInheritingFormContentDsl<CATEGORY_DSL : AutocapitalizeInheritingFormContent>:
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.integration.AutocapitalizeInheritingFormFlowFormAssociatedPalpable
import net.kigawa.renlin.dsl.StatedDsl


/**
Expand All @@ -11,4 +12,5 @@ interface AutocapitalizeInheritingFormFlowFormAssociatedPalpableDsl<CATEGORY_DSL
FlowContentDsl<CATEGORY_DSL>,
PalpableContentDsl<CATEGORY_DSL>,
FormAssociatedContentDsl<CATEGORY_DSL>,
AutocapitalizeInheritingFormContentDsl<CATEGORY_DSL>
AutocapitalizeInheritingFormContentDsl<CATEGORY_DSL>,
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.native.EmbeddedContent
import net.kigawa.renlin.dsl.StatedDsl


/**
* DSL for EmbeddedContent
*/
interface EmbeddedContentDsl<CATEGORY_DSL : EmbeddedContent>
interface EmbeddedContentDsl<CATEGORY_DSL : EmbeddedContent>:
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.integration.EmbeddedFlowPalpablePhrasing
import net.kigawa.renlin.dsl.StatedDsl


/**
Expand All @@ -11,4 +12,5 @@ interface EmbeddedFlowPalpablePhrasingDsl<CATEGORY_DSL : EmbeddedFlowPalpablePhr
FlowContentDsl<CATEGORY_DSL>,
PhrasingContentDsl<CATEGORY_DSL>,
EmbeddedContentDsl<CATEGORY_DSL>,
PalpableContentDsl<CATEGORY_DSL>
PalpableContentDsl<CATEGORY_DSL>,
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.native.FlowContent
import net.kigawa.renlin.dsl.StatedDsl


/**
* DSL for FlowContent
*/
interface FlowContentDsl<CATEGORY_DSL : FlowContent>
interface FlowContentDsl<CATEGORY_DSL : FlowContent>:
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.integration.FlowFormAssociatedInteractivePalpablePhrasing
import net.kigawa.renlin.dsl.StatedDsl


/**
Expand All @@ -12,4 +13,5 @@ interface FlowFormAssociatedInteractivePalpablePhrasingDsl<CATEGORY_DSL : FlowFo
PhrasingContentDsl<CATEGORY_DSL>,
InteractiveContentDsl<CATEGORY_DSL>,
PalpableContentDsl<CATEGORY_DSL>,
FormAssociatedContentDsl<CATEGORY_DSL>
FormAssociatedContentDsl<CATEGORY_DSL>,
StatedDsl<CATEGORY_DSL>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.kigawa.renlin.w3c.category.dsl


import net.kigawa.renlin.w3c.category.integration.FlowInteractivePalpablePhrasing
import net.kigawa.renlin.dsl.StatedDsl


/**
Expand All @@ -11,4 +12,5 @@ interface FlowInteractivePalpablePhrasingDsl<CATEGORY_DSL : FlowInteractivePalpa
FlowContentDsl<CATEGORY_DSL>,
PhrasingContentDsl<CATEGORY_DSL>,
PalpableContentDsl<CATEGORY_DSL>,
InteractiveContentDsl<CATEGORY_DSL>
InteractiveContentDsl<CATEGORY_DSL>,
StatedDsl<CATEGORY_DSL>
Loading
Loading