Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Making a Template Engine for Kotlin

E9a8393b5ad337ea9103d50169aa6d32?s=47 Lukas
February 16, 2018
530

Making a Template Engine for Kotlin

E9a8393b5ad337ea9103d50169aa6d32?s=128

Lukas

February 16, 2018
Tweet

Transcript

  1. Making a Template Engine for Kotlin M3 Techtalk #87 2018/2/16

    M3 Inc., Lukas Prasuhn
  2. About Me - Software Engineer @ M3 - 12 in

    Japan from Germany - Github: https://github.com/lukasjapan - Tech I like - Raspberry Pi - Kotlin/Java - Ruby - ... - Creator of “bt-speaker” - Bluetooth speaker Daemon for Raspberry Pi
  3. - Template Engine for Kotlin - Features - HAML style

    - High Performance - Type-Safe!! - Spring Integration - https://github.com/lukasjapan/koreander
  4. HAML Style - Whitespace ident based syntax ↓

  5. High Performance - Transpile into Kotlin Code - Compile to

    JVM Bytecode - Render by passing the View Model Template Kotlin Code Compiled JVM Code HTML View Model
  6. Type Safety Template Kotlin Code Compiled JVM Code HTML View

    Model Defining the ViewModel type Type checks, etc Because of Kotlins KType, type erasure is not an issue! forced cast
  7. Kotlin Script - Implementation of JSR-223 - (Scripting for the

    Java Platform) - Kotlin implementation - Run arbitrary Kotlin code - Compiled Scripts
  8. Spring Integration - https://github.com/lukasjapan/koreander-spring/ - https://github.com/lukasjapan/koreander-spring/blob/master/src/main/kotlin/de/cvguy/kotlin/koreander/ spring/example/KoreanderExample.kt

  9. Steps for parsing templates - (Tokenizing) - Splitting input by

    white-space, newlines, etc - Lexing - Give meaning to the tokens - Parsing - Take the tokens and check for correct syntax - Build the code out of the Tokens
  10. Deploying a Java Library - JFrog - create maven repository

    - apply plugin to gradle - upload .jar - possibility to sync with JCenter - Including library
  11. Example - View Model is forced - data class recommended

  12. Demo