preslavrachev / ktor-pebble

Ktor Pebble Template Feature

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ktor Pebble Template Feature

A feature to use the Pebble template engine with ktor.

Installation

Add dependency to gradle

Add to the repositories block in the build.gradle file:

maven { url  "https://dl.bintray.com/jeffsmithdev/maven" }

Include the artifact:

compile 'com.tlogx.ktor:ktor-pebble:0.0.1'

Install the feature in ktor:

install(Pebble) {
        install(Pebble) {
            templateDir = "" // resource path,  i.e templateDir = "templates/"
            strictVariables = true // throw exception if variables are missing
            defaultLocale = Locale.US // override Locale.getDefault()
        }
}

Usage

When Pebble is configured, you can call the call.respond method with a PebbleContent instance:

routing {
    get("/") {
                    val model = mapOf(
                            "title" to "Ktor Pebble Test Page",
                            "description" to "A Ktor feature to use the pebble template engine by Mitchell Bösecke",
                            "myDogs" to listOf("Bebe", "Dot", "Brownie", "Bella")
                    )
                    call.respond(PebbleContent("example.peb", model, "e"))
    }
}

Todo

  • Add additional pebble configuration options

Releases

0.0.1

  • Basic functionality

Notes

About

Ktor Pebble Template Feature


Languages

Language:Kotlin 100.0%