Created
October 26, 2011 12:45
-
-
Save takezoe/1316239 to your computer and use it in GitHub Desktop.
Patch for xsbt-scalate-precompile-plugin to support nested directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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 } | |
+ } | |
} | |
} | |
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
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:
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.