Hello,
I need to generate some scala code as a pre-compilation phase (i.e.
something that takes input text files, and generate code files
_before_ the compile phase, much like lexers and parser generators -
think antlr and similar-)
In the Microsoft world, this is done using T4, which is basically
something really similar to the good old asp (text + tags which
contain code, whose result will be substituted after running the
code).
http://msdn.microsoft.com/en-us/library/vstudio/bb126445.aspx (looks
familiar? :) )
I came across scalate and while I understand this is not its main
purpose, I would like to use ssp in the same way as T4.
Something like this:
From hello.ssp
-------------
def printHello {
val greeting = <%= List("Hello", ", ", "world").mkString %>
println(greeting)
-------------
To hello.scala
def printHello {
val greeting = "Hello, world"
println(greeting)
I have tried this approach using a very simple command line program
(two lines, TemplateEngine and layout) and it works, but obviously I
would like it to be automated and turn it into a maven plugin, so I do
not need to remember to run the program before building the project.
Question #1: has anyone used scalate in this way? Is it a bad idea?
Question #2: I looked at the maven-scalate-plugin; the "precompile"
Mojo uses scalate types only through reflection. Why is it so? If I
want to introduce my new "transform" Mojo, should I follow the same
pattern? Programming using reflection is a pain I would avoid, if not
necessary.
Thank you,
Lorenzo Dematte'