Coder Social home page Coder Social logo

ktor-pebble's Introduction

Ktor Pebble Template Feature

This project is archived due to ktor natively supporting pebble templates


A feature to use the Pebble template engine with ktor.

Note: Version 0.0.5 and above is for ktor 1.3+, Version 0.0.4 is for <= 1.2**

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.6'

Install the feature in ktor with optional config:

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()
            cacheActive = true // flag to activate/deactivate template caching
            allowGetClass = false // throws an exception if you try to access the class/getClass attribute
            greedyMatchMethod = false  // greedy matching mode for finding java method
        }
}

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.6

  • Updated ktor to 1.5.0, kotlin to 1.4.21 and pebble to 3.1.4

0.0.5

  • Updated ktor to 1.3.0

0.0.4

  • Updated kotlin (1.3.50), ktor (1.2.4) and pebble (3.1.0) - Thanks Richard Scorer

0.0.3

  • Added additional pebble configuration options
  • Upgraded pebble to v2.4.0

0.0.2

  • Kotlin 1.3 support and minor code fixes/improvements - Thanks Preslav Rachev

0.0.1

  • Basic functionality

Notes

ktor-pebble's People

Contributors

code0x378 avatar rscorer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ktor-pebble's Issues

Is there a way to add a variable to every response template?

I'd like to add, for example, "version" to every response that goes out, so that I can use it in my shared footer and without having to manually add it. There doesn't seem to be a built in way to do this, unless I missed it. Does this exist? Should I instead make a custom ktor-pebble implementation that allows me to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.