complate-http4k

complate integration for HTTP4K

Лицензия

Лицензия

Группа

Группа

com.github.complate
Идентификатор

Идентификатор

complate-http4k
Последняя версия

Последняя версия

0.1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

complate-http4k
complate integration for HTTP4K
Ссылка на сайт

Ссылка на сайт

http://github.com/complate/complate-http4k
Организация-разработчик

Организация-разработчик

com.github.complate
Система контроля версий

Система контроля версий

https://github.com/complate/complate-http4k

Скачать complate-http4k

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.complate/complate-http4k/ -->
<dependency>
    <groupId>com.github.complate</groupId>
    <artifactId>complate-http4k</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.complate/complate-http4k/
implementation 'com.github.complate:complate-http4k:0.1.1'
// https://jarcasting.com/artifacts/com.github.complate/complate-http4k/
implementation ("com.github.complate:complate-http4k:0.1.1")
'com.github.complate:complate-http4k:jar:0.1.1'
<dependency org="com.github.complate" name="complate-http4k" rev="0.1.1">
  <artifact name="complate-http4k" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.complate', module='complate-http4k', version='0.1.1')
)
libraryDependencies += "com.github.complate" % "complate-http4k" % "0.1.1"
[com.github.complate/complate-http4k "0.1.1"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jre8 jar 1.1.51
org.http4k : http4k-core jar 2.35.1

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

complate HTTP4K Adapter

Build Status codecov License

This adapter connects HTTP4K with the templating engine complate.

Usage

Compiling and Installation

Unless this library becomes available via maven central (or others), it can be built and installed to the local maven repo:

./gradlew clean build
./gradlew install

Dependency

Library import:

dependencies {
  compile 'com.github.complate:complate-http4k:0.1.1'
}

HTTP4K Example

Everything that is required to move an existing HTTP4K based application from another templating engine towards complate can be achieved by switching the templates to com.github.complate.ComplateTemplates.

Here is a more-or-less complete (working) base that shows how to use.

dependencies {
  // Kotlin
  compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
  
  // HTTP4K
  compile "org.http4k:http4k-core:2.35.1"
  compile "org.http4k:http4k-server-netty:2.35.1"
  
  // complate Adapter
  compile 'com.github.complate:complate-http4k:0.1.1'
}
package com.github.complate.http4k.demo
  
import com.github.complate.ComplateTemplates
import org.http4k.core.Method
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.routing.bind
import org.http4k.server.Http4kServer
import org.http4k.server.Netty
import org.http4k.server.asServer
import org.http4k.template.TemplateRenderer
import org.http4k.template.ViewModel
import kotlin.concurrent.thread
  
  
val bundles = "src/main/resources/frontend"
  
fun main(args: Array<String>) {
  val app = DemoApplication()
  app.start()
  Runtime.getRuntime().addShutdownHook(thread(start = false) { app.stop() })
}
  
data class Person(val name: String, val age: Int) : ViewModel
  
class DemoApplication {
  private val server: Http4kServer
  private val renderer: TemplateRenderer = ComplateTemplates().HotReload(bundles)
  
  private val routes = org.http4k.routing.routes(
    "/person" bind Method.GET to {
      val viewModel = Person("Bob", 45)
      val renderedView = renderer(viewModel)
      Response(Status.OK).body(renderedView)
    }
  )
  
  init {
    server = routes.asServer(Netty(9000))
  }
  
  fun start() = server.start()
    
  fun stop() = server.stop()
}

TODOs

Caching (file & class path) is not implemented at the moment:

class ComplateTemplates : Templates {
  override fun Caching(baseTemplateDir: String): TemplateRenderer {
    TODO("not implemented")
  }

  override fun CachingClasspath(baseClasspathPackage: String): TemplateRenderer {
    TODO("not implemented")
  }
}

This will hopefully added in a future version of the adapter (most likely v0.2.0).

com.github.complate

Версии библиотеки

Версия
0.1.1