Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Patch for xsbt-scalate-precompile-plugin to support nested directory.
--- ScalatePlugin.scala.org 2011-10-26 21:35:49.000000000 +0900
+++ ScalatePlugin.scala 2011-10-26 21:03:04.000000000 +0900
@@ -35,9 +35,11 @@
engine.generateScala(source).source
}
- private def generate (engine: TemplateEngine, template: File, outputdir: File, log: Logger) = {
+ private def generate (engine: TemplateEngine, template: File, outputdir: File, log: Logger): File = {
log.info(" compiling template: " + template)
- IO.write(scala(template, outputdir), code(engine, template))
+ val outputFile = scala(template, outputdir)
+ IO.write(outputFile, code(engine, template))
+ outputFile
}
private def scalateLoggingConfigValue: Initialize[File] =
@@ -58,16 +60,30 @@
System.setProperty("logback.configurationFile", logConfig.toString)
val engine = new org.fusesource.scalate.TemplateEngine()
- engine.packagePrefix = ""
- for (dir <- inputDirs)
- if (dir.listFiles != null)
- for (template <- dir.listFiles.filter(changed(_, outputDir)))
- generate(engine, template, outputDir, out.log)
-
- outputDir.listFiles match {
- case null => Seq()
- case (files) => files.toList
+ inputDirs.map { dir =>
+ generateScalateSourceInDirectory(out, engine, dir, outputDir, "")
+ }.flatMap { e => e }
+ }
+
+ def generateScalateSourceInDirectory(out : TaskStreams,
+ engine : org.fusesource.scalate.TemplateEngine,
+ dir : File, outputDir : File, packageName : String): Seq[File] = {
+ dir.listFiles match {
+ case null => Seq()
+ case child => {
+ dir.listFiles.map { child =>
+ if(child.isDirectory){
+ generateScalateSourceInDirectory(out, engine, child, new File(outputDir, child.getName),
+ if(packageName.isEmpty) child.getName else packageName + "." + child.getName)
+ } else if(changed(child, outputDir)){
+ engine.packagePrefix = packageName
+ Seq(generate(engine, child, outputDir, out.log))
+ } else {
+ Seq()
+ }
+ }.flatMap { e => e }
+ }
}
}
Owner

takezoe commented Oct 26, 2011

xsbt-scalate-precompile-plugin is a sbt plug-in that pre-compiles Scalate templates before packaging war. This plug-in is very useful when we use Scalate but it has one serious problem in the latest version 1.5.

We can configure the directory that placed templates as following:

scalateTemplateDirectories in Compile <<= (scalateTemplateDirectories in Compile, baseDirectory) {
  (dirs, basedir) => dirs ++ Seq(new File(basedir, "/src/main/webapp/WEB-INF"))
}

However xsbt-scalate-precompile-plugin does not process templates in the nested directory. For example, it can't handle the layout template (which have to be placed into WEB-INF/scalate/layouts) correctly.

This patch fixes this problem. xsbt-scalate-precompile-plugin can process the nested directory correctly by this patch.

Owner

takezoe commented Oct 30, 2011

This patch was taken in xsbt-scalate-precompile-plugin 1.6. So this problem will be fixed in the 1.6.
https://github.com/zentrope/xsbt-scalate-precompile-plugin/issues/4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment