Closed kenkyee closed 8 years ago
You need one of these included:
For handlebars:
compile group: 'uy.kohesive.kovert', name: 'kovert-template-engine-handlebars', version: '0.13.0'
for freemarker:
compile group: 'uy.kohesive.kovert', name: 'kovert-template-engine-freemarker', version: '0.13.0'
Sample for configuring the engine for Freemarker:
Sample for configuring the engine for Handlebars:
Handlebars config is mostly:
val loader = ClassPathTemplateLoader()
loader.setPrefix("/templates")
val handlebars = Handlebars(loader)
KovertConfig.registerTemplateEngine(KovertHandlebarsTemplateEngine(handlebars), ".html.hbs", "text/html")
Finally got the example to build/run in a separate directory. This is what I had to do:
buildscript { ext.version_shadowjar = '1.2.3' ext.version_logback = '1.1.7' ext.version_slf4j = '1.7.12' ext.version_kovert = '0.13.+' ext.version_freemarker = '2.3.23'
repositories { mavenCentral() jcenter() maven { url 'http://repo.spring.io/plugins-release' } maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin" classpath "com.github.jengelman.gradle.plugins:shadow:$version_shadowjar" }
}
//...
apply plugin: 'java' apply plugin: 'application' apply plugin: 'idea' apply plugin: 'kotlin' apply plugin: 'com.github.johnrengelman.shadow'
//...
repositories { mavenCentral() maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } maven { url 'http://dl.bintray.com/jaysonminard/kohesive' } maven { url 'http://dl.bintray.com/mplatvoet/komponents' } }
dependencies { compile "uy.kohesive.kovert:kovert-vertx:$version_kovert" compile "org.freemarker:freemarker:$version_freemarker"
compile "org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin" compile "org.jetbrains.kotlin:kotlin-reflect:$version_kotlin" compile "org.slf4j:slf4j-api:$version_slf4j" //compile "org.slf4j:slf4j-log4j12:$version_slf4j" testCompile "junit:junit:$version_junit" testCompile "org.jetbrains.kotlin:kotlin-test:$version_kotlin" testRuntime "ch.qos.logback:logback-classic:$version_logback"
}
def mainVerticle = "uy.kohesive.kovert.vertx.boot.KovertVerticle"
// mainClassName = "io.vertx.core.Launcher" mainClassName = "uy.kohesive.kovert.vertx.sample.App" run { args = ["run", mainVerticle] }
jar { manifest { attributes 'Main-Verticle': mainVerticle } }
shadowJar { classifier = 'fat'
mergeServiceFiles { include 'META-INF/services/io.vertx.core.spi.VerticleFactory' }
dependencies { exclude(dependency('io.vertx:codegen')) exclude(dependency('junit:junit')) exclude(dependency('org.mvel:mvel2')) exclude(dependency('log4j:log4j')) } }
Freemarker has type safe templates with code completion using Intellij IDEA, and performance is unlikely unnoticeably different unless you are at Amazon.com level of scale. Are you?
Oops...looks like our comments crossed :-) No, the app isn't going to be that popular...does help that Mustache/Handlebars is popular w/ non-Java webapps though (javascript frameworks).
Don't copy over the freemarker or handlebars code, there is a dependency already for kovert that is there.
See all Kovert dependencies at: http://mvnrepository.com/artifact/uy.kohesive.kovert
Handlebars is popular but not type safe. Freemarker during development can be type checked by the IDE if you include typing comments for parts of the model such as:
[#-- @ftlvariable name="" type="uy.kohesive.kovert.template.freemarker.test.PeopleResults" --]
And in Kotlin world, type safety is usually improtant :-D
You do not need to directly include freemarker or handlebars, the Kovert module for each does that, unless you want to change the version number.
Good point about typesafety...didn't realize that about freemarker :-)
I was just trying to come up w/ a quick way to set up a running example that can be modified instead of starting from scratch....modified my build.gradle and got rid of the copy of the template code:
buildscript {
ext.version_shadowjar = '1.2.3'
ext.version_logback = '1.1.7'
ext.version_slf4j = '1.7.12'
ext.version_kovert = '0.13.+'
ext.version_freemarker = '2.3.23'
repositories {
mavenCentral()
jcenter()
maven {
url 'http://repo.spring.io/plugins-release'
}
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
classpath "com.github.jengelman.gradle.plugins:shadow:$version_shadowjar"
}
}
//...
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'com.github.johnrengelman.shadow'
//...
repositories {
mavenCentral()
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
maven {
url 'http://dl.bintray.com/jaysonminard/kohesive'
}
maven {
url 'http://dl.bintray.com/mplatvoet/komponents'
}
}
dependencies {
compile "uy.kohesive.kovert:kovert-vertx:$version_kovert"
compile "uy.kohesive.kovert:kovert-template-engine-freemarker:$version_kovert"
compile "org.freemarker:freemarker:$version_freemarker"
compile "org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin"
compile "org.jetbrains.kotlin:kotlin-reflect:$version_kotlin"
compile "org.slf4j:slf4j-api:$version_slf4j"
//compile "org.slf4j:slf4j-log4j12:$version_slf4j"
testCompile "junit:junit:$version_junit"
testCompile "org.jetbrains.kotlin:kotlin-test:$version_kotlin"
testRuntime "ch.qos.logback:logback-classic:$version_logback"
}
def mainVerticle = "uy.kohesive.kovert.vertx.boot.KovertVerticle"
// mainClassName = "io.vertx.core.Launcher"
mainClassName = "uy.kohesive.kovert.vertx.sample.App"
run {
args = ["run", mainVerticle]
}
jar {
manifest {
attributes 'Main-Verticle': mainVerticle
}
}
shadowJar {
classifier = 'fat'
mergeServiceFiles {
include 'META-INF/services/io.vertx.core.spi.VerticleFactory'
}
dependencies {
exclude(dependency('io.vertx:codegen'))
exclude(dependency('junit:junit'))
exclude(dependency('org.mvel:mvel2'))
exclude(dependency('log4j:log4j'))
}
}
You can run using the application plugin and not needing anything related to VerticleFactory unless you are running that way for another reason. The App class has a main and starts vert.x and the verticle. ShadowJar is not the best plugin in the world either, I tend to not one-jar at the application level and instead using the application plugin and its ability to tgz a distribution including the startup script.
I was trying to make a build.gradle that was the most flexible...started w/ this initially: http://beckje01.com/blog/2015/05/17/vertx3-and-gradle-application-plugin/
so ideally, it can run w/ the ability to attach a debugger, do a fatjar or build a distribution that you can unzip. I know..so unopinionated ;-)
hmm...might have found a bug too...turned on clustering in the sample.conf...fired up 3 instances...logged into the web site at localhost:8080, then logged out....clicked on log in and it didn't prompt me before logging me in... Checked w/o clustering and this still happens...
how did you "log out"?
Clicked on the logout link on this page: http://localhost:8080/app which looks like it links to http://localhost:8080/logout
So go to http://localhost:8080 click on login then click on logout on the next page then click on login again (should prompt here I think and I didn't tell chrome to remember my login)
The auth stuff in the sample isn't complete, it is work in progress, I'll be looking at it soon. but if it is a separate issue, please don't just add to this issue, it is confusing to have multiple bugs in one ticket.
ok...I'll write it up as a separate ticket. Thanks.
or better directions for integrating w/ an app.
Including only compile "uy.kohesive.kovert:kovert-vertx:0.13.+" isn't enough to pull freemarker in or the small class to use it.
I prefer HandleBars though...beats Freemarker in a bunch of benchmark tests ;-)