added a little experimental spike of a text and markup based template library for internal DSLs for templating (which external DSLs like Jade / Razor / Velocity / Erb / JSP style) could layer on top of. Mails to follow shortly :)

This commit is contained in:
James Strachan
2011-12-23 13:40:03 +00:00
parent f64c02c80a
commit db76e28c6d
7 changed files with 369 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
namespace std.template
import std.*
import std.template.io.*
import std.io.*
import std.util.*
import std.test.*
import java.util.*
class EmailTemplate(var name: String = "James", var time: Date = Date()) : TextTemplate() {
override fun render() {
print("Hello there $name and how are you? Today is $time. Kotlin rocks")
}
}
/**
TODO compile error
class MoreDryTemplate(var name: String = "James", var time: Date = Date()) : TextTemplate() {
override fun render() {
+"Hey there $name and how are you? Today is $time. Kotlin rocks"
}
}
*/
class TemplateCoreTest() : TestSupport() {
fun testDefaultValues() {
val text = EmailTemplate().renderToText()
assert {
println(text)
text.startsWith("Hello there James")
}
}
fun testDifferentValues() {
val text = EmailTemplate("Andrey").renderToText()
assert {
println(text)
text.startsWith("Hello there Andrey")
}
}
/*
TODO compile error
fun testMoreDryTemplate() {
val text = MoreDryTemplate("Alex").renderToText()
assert {
println(text)
text.startsWith("Hey there Alex")
}
}
*/
}