Skip to content
/ ko-te Public

Ko(tlin)-Te(mplate engine). Kotlin Multiplatform Template Engine (WIP)

License

Notifications You must be signed in to change notification settings

LimeBeck/ko-te

Repository files navigation

GitHub Workflow Status GitHub last commit GitHub Maven Central

Ko-te (Kotlin Template Engine)

Pure-kotlin template engine for all platforms

Example

import dev.limebeck.templateEngine.KoTeRenderer
import kotlin.test.assertEquals

val renderer = KoTeRenderer()

val simpleTextTemplate = """
    Hello, {{ name }}!
    Object value: "{{ object.value[0] }}"
""".trimIndent()

val data = mapOf(
    "name" to "World",
    "object" to mapOf(
        "value" to listOf("Simple string")
    )
)

val expectedOutput = """
    Hello, World!
    Object value: "Simple string"
""".trimIndent()

assertEquals(expectedOutput, renderer.render(simpleTextTemplate, data).getValueOrNull())

Reference template

Variable access: {{ variable }}
Key access: {{ object.value }}
Index access: {{ array[0] }}
Function call with round brackets syntax: {{ uppercase(variable) }}
Variable assign: {{ let newVariable = "value" }}
Multiline block: {{
    let first = 20
    let second = 30
    first + second
}}
Conditional template: {{if( 1 == 2 )}} true {{ else }} false {{ endif }}
Conditional value: {{
    if( 1 == 2 ) 
        true 
    else 
        false 
    endif 
}}
Conditional block: {{ if(value) }} Value is true {{ else }} Value is false {{ endif }}
Import: {{ import import "resourceName" }}

About

Ko(tlin)-Te(mplate engine). Kotlin Multiplatform Template Engine (WIP)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages