playpants.tool.TwirlGen.scala Maven / Gradle / Ivy
package playpants
import java.io.File
object TwirlGen {
case class Params(sources: Seq[File] = Seq.empty,
sourceDir: File = new File("."),
templateImports: Seq[String] = Seq.empty,
target: File = new File("."))
def main(args: Array[String]): Unit = {
val parser = new scopt.OptionParser[Params]("twirl-gen") {
head("twirl-gen", "1.0")
opt[Seq[File]]("sources") valueName("") action {
(sources, c) => c.copy(sources = sources)
} text("comma separated list of source files")
opt[File]("source_dir") valueName("") action {
(sourceDir, c) => c.copy(sourceDir = sourceDir)
} text("Root directory for sources (to determine package name)")
opt[Seq[String]]("template_imports") valueName("") action {
(templateImports, c) => c.copy(templateImports = templateImports)
} text("Comma separated list of imports.")
opt[File]("target") required() valueName("") action {
(target, c) => c.copy(target = target)
} text("directory to write generated sources")
}
parser.parse(args, Params()) match {
case None => System.exit(1)
case Some(params) =>
params.sources.foreach {
source =>
val imports = params.templateImports.map {
f => s"import $f\n"
}.mkString
val r = play.twirl.compiler.TwirlCompiler.compile(
source, params.sourceDir, params.target, "play.twirl.api.HtmlFormat",
additionalImports=imports)
println(s"HELLO: $source $r")
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy