Skip to content

Commit

Permalink
feature: add global pkl functions and vals
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFruxz committed Apr 8, 2024
1 parent c03d68d commit 62ae3cd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/kotlin/dev/fruxz/ascend/extension/pkl/Pkl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.fruxz.ascend.extension.pkl

import org.pkl.config.java.ConfigEvaluator
import org.pkl.config.java.ConfigEvaluatorBuilder
import org.pkl.config.kotlin.forKotlin

/**
* This lazily computed value returns a Kotlin instance of
* the apple/pkl ConfigEvaluator preconfigured instance.
* @see ConfigEvaluator
* @see ConfigEvaluatorBuilder
* @see forKotlin
* @author Fruxz
* @since 2024.2
*/
val pkl by lazy { ConfigEvaluator.preconfigured().forKotlin() }

/**
* This function builds a new Kotlin instance of the apple/pkl ConfigEvaluator
* using the preconfigured() function and applies the [builder] function to it.
* @see ConfigEvaluator
* @see ConfigEvaluatorBuilder
* @see forKotlin
* @param builder the function to apply to the preconfigured ConfigEvaluatorBuilder
* @return the new Kotlin instance of the ConfigEvaluator
* @author Fruxz
* @since 2024.2
*/
fun buildPkl(builder: ConfigEvaluatorBuilder.() -> Unit) = ConfigEvaluatorBuilder.preconfigured().apply(builder).forKotlin()

/**
* This function builds a new Kotlin instance of the apple/pkl ConfigEvaluator
* using the unconfigured() function and applies the [builder] function to it.
* @see ConfigEvaluator
* @see ConfigEvaluatorBuilder
* @see forKotlin
* @param builder the function to apply to the unconfigured ConfigEvaluatorBuilder
* @return the new Kotlin instance of the ConfigEvaluator
* @author Fruxz
* @since 2024.2
*/
fun buildUnconfiguredPkl(builder: ConfigEvaluatorBuilder.() -> Unit) = ConfigEvaluatorBuilder.unconfigured().apply(builder).forKotlin()

0 comments on commit 62ae3cd

Please sign in to comment.