diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/plugability/DokkaContext.kt | 4 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/DokkaPlugin.kt | 5 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/extensions.kt | 31 |
3 files changed, 29 insertions, 11 deletions
diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index 0d110f85..e6286f0b 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -105,7 +105,7 @@ private class DokkaContextConfigurationImpl( AskDefault.Never -> actions(point).orEmpty() AskDefault.Always -> actions(point).orEmpty() + DefaultExtensions.get(point, this) AskDefault.WhenEmpty -> - actions(point)?.takeIf { it.isNotEmpty() } ?: DefaultExtensions?.get(point, this) + actions(point)?.takeIf { it.isNotEmpty() } ?: DefaultExtensions.get(point, this) } as List<T> private fun <E : ExtensionPoint<*>> actions(point: E) = extensions[point]?.map { it.action.get(this) } @@ -119,7 +119,7 @@ private class DokkaContextConfigurationImpl( fun install(plugin: DokkaPlugin) { plugins[plugin::class] = plugin plugin.context = this - plugin.internalInstall(this) + plugin.internalInstall(this, this.configuration) } override fun addExtensionDependencies(extension: Extension<*>) { diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index 3f82000d..1fcbd934 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.plugability +import org.jetbrains.dokka.DokkaConfiguration import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty import kotlin.reflect.KProperty1 @@ -36,10 +37,10 @@ abstract class DokkaPlugin { }.also { thisRef.extensionDelegates += property } } - internal fun internalInstall(ctx: DokkaContextConfiguration) { + internal fun internalInstall(ctx: DokkaContextConfiguration, configuration: DokkaConfiguration) { extensionDelegates.asSequence() .filterIsInstance<KProperty1<DokkaPlugin, Extension<*>>>() // should be always true .map { it.get(this) } - .forEach { ctx.addExtensionDependencies(it) } + .forEach { if(it.condition.invoke(configuration)) ctx.addExtensionDependencies(it) } } }
\ No newline at end of file diff --git a/core/src/main/kotlin/plugability/extensions.kt b/core/src/main/kotlin/plugability/extensions.kt index 42bf3900..4cbb61eb 100644 --- a/core/src/main/kotlin/plugability/extensions.kt +++ b/core/src/main/kotlin/plugability/extensions.kt @@ -1,5 +1,7 @@ package org.jetbrains.dokka.plugability +import org.jetbrains.dokka.DokkaConfiguration + data class ExtensionPoint<T : Any> internal constructor( internal val pluginClass: String, internal val pointName: String @@ -12,7 +14,8 @@ abstract class Extension<T : Any> internal constructor( internal val pluginClass: String, internal val extensionName: String, internal val action: LazyEvaluated<T>, - internal val ordering: (OrderDsl.() -> Unit)? = null + internal val ordering: (OrderDsl.() -> Unit)? = null, + internal val condition: DokkaConfiguration.() -> Boolean = { true } ) { override fun toString() = "Extension: $pluginClass/$extensionName" @@ -21,6 +24,8 @@ abstract class Extension<T : Any> internal constructor( else false override fun hashCode() = listOf(pluginClass, extensionName).hashCode() + + abstract fun setCondition(condition: (DokkaConfiguration.() -> Boolean)): Extension<T> } class ExtensionOrdered<T : Any> internal constructor( @@ -28,27 +33,37 @@ class ExtensionOrdered<T : Any> internal constructor( pluginClass: String, extensionName: String, action: LazyEvaluated<T>, - ordering: (OrderDsl.() -> Unit) + ordering: (OrderDsl.() -> Unit), + condition: DokkaConfiguration.() -> Boolean = { true } ) : Extension<T>( extensionPoint, pluginClass, extensionName, action, - ordering -) + ordering, + condition +) { + override fun setCondition(condition: DokkaConfiguration.() -> Boolean) = + ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, ordering!!, condition) +} class ExtensionUnordered<T : Any> internal constructor( extensionPoint: ExtensionPoint<T>, pluginClass: String, extensionName: String, - action: LazyEvaluated<T> + action: LazyEvaluated<T>, + condition: DokkaConfiguration.() -> Boolean = { true } ) : Extension<T>( extensionPoint, pluginClass, extensionName, action, - null -) + null, + condition +) { + override fun setCondition(condition: DokkaConfiguration.() -> Boolean) = + ExtensionUnordered(extensionPoint, pluginClass, extensionName, action, condition) +} internal data class Ordering(val previous: Set<Extension<*>>, val following: Set<Extension<*>>) @@ -66,6 +81,8 @@ class ExtendingDSL(private val pluginClass: String, private val extensionName: S infix fun <T: Any> ExtensionUnordered<T>.order(block: OrderDsl.() -> Unit) = ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, block) + + infix fun <T : Any> Extension<T>.applyIf(condition: DokkaConfiguration.() -> Boolean): Extension<T> = this.setCondition(condition) } @ExtensionsDsl |