diff --git a/plug-in-development/index.html b/plug-in-development/index.html index 7c65a81..36de0d6 100644 --- a/plug-in-development/index.html +++ b/plug-in-development/index.html @@ -302,14 +302,13 @@ class Info(val publish: Boolean)
@Directive -public fun myConfig(init: Info.() -> Unit) : Info { - val info = Info() - info.init() - return info -} -+public fun myConfig(init: Info.() -> Unit) = Info().apply { + init() + this +}
- The @Directive
annotation is not enforced but you should always use it in order to help future tools (e.g. an IDEA plug-in) identify Kobalt directives so they can be treated differently from regular Kotlin functions.
+ The @Directive
annotation is not enforced but you should always use it in order to help future tools (e.g. an IDEA plug-in) identify Kobalt directives so they can be treated differently from regular Kotlin functions. The code above defines a myConfig
function that accepts a closure as an argument. It creates an Info
+ object, calls the init()
function on it (which runs all the code inside that closure) and then return that Info
object.
Users can now specify the following in their build file: @@ -320,8 +319,7 @@ import.com.example.plugin.myConfig myConfig { publish = true -} - +}
If you need access to the project being built, just declare an additional parameter of type Project
to your directive and have the user pass that project: