Skip to content

Latest commit

 

History

History
executable file
·
61 lines (50 loc) · 1.63 KB

README.MD

File metadata and controls

executable file
·
61 lines (50 loc) · 1.63 KB

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" }}