aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/plugability/extensions.kt
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-02-04 11:53:31 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-11 10:15:32 +0100
commit1882138d0558d0465c97f34ac86a7b5102de0191 (patch)
tree9391587f8992856437c8f37ba4fdfca98bc4ff85 /core/src/main/kotlin/plugability/extensions.kt
parent62a2848a1187c61c62907a000f8bc3b3199923e3 (diff)
downloaddokka-1882138d0558d0465c97f34ac86a7b5102de0191.tar.gz
dokka-1882138d0558d0465c97f34ac86a7b5102de0191.tar.bz2
dokka-1882138d0558d0465c97f34ac86a7b5102de0191.zip
Adds conditional plugin linking
Diffstat (limited to 'core/src/main/kotlin/plugability/extensions.kt')
-rw-r--r--core/src/main/kotlin/plugability/extensions.kt31
1 files changed, 24 insertions, 7 deletions
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