tpasはsbt project上で動かせるテンプレートエンジンwrapperと
生成ルール記述DSLを提供するsbt pluginです
- project/build.properties
sbt.version=1.3.6
- project/plugins.sbt
resolvers += "tpas repo" at "https://keisunagawa.github.io/tpas/repo/"
addSbtPlugin("me.kerfume" % "tpas" % "0.2.0")
- templates/Hello.tpl.scala (or your scala code template.)
class {{ ctx.name }} {
def hello(): Unit = println("hello, {{ message }}.")
}
- build.sbt, add gen template dsl
enablePlugins(me.kerfume.tpas.Tpas)
import me.kerfume.tpas.dsl._
defTpasTask("genHello").setParser { arg =>
val json =
s"""{
| "message": "${arg}"
|}""".stripMargin
minimum(
dest = "tpas_example.hello.Hello",
template = "Hello.tpl.scala",
valuesJson = json
)
}.build
$ sbt "genHello world"
$ cat src/main/scala/tpas_example/hello/Hello.scala
package tpas_example.hello
class Hello {
def hello(): Unit = println("hello, .")
}
other example see example
see wiki