Commit 3ab8f781 authored by Peter van 't Hof's avatar Peter van 't Hof Committed by GitHub
Browse files

Merge pull request #36 from biopet/fix-BIOPET-610

compiling ssp-template files with scalate
parents dc6dc49c 800cc879
...@@ -20,7 +20,7 @@ import nl.lumc.sasc.biopet.core.ToolCommandFunction ...@@ -20,7 +20,7 @@ import nl.lumc.sasc.biopet.core.ToolCommandFunction
import nl.lumc.sasc.biopet.utils.summary.Summary import nl.lumc.sasc.biopet.utils.summary.Summary
import nl.lumc.sasc.biopet.utils.{ IoUtils, Logging, ToolCommand } import nl.lumc.sasc.biopet.utils.{ IoUtils, Logging, ToolCommand }
import org.broadinstitute.gatk.utils.commandline.Input import org.broadinstitute.gatk.utils.commandline.Input
import org.fusesource.scalate.{ TemplateEngine, TemplateSource } import org.fusesource.scalate.TemplateEngine
import scala.collection.mutable import scala.collection.mutable
import scala.language.postfixOps import scala.language.postfixOps
...@@ -236,9 +236,7 @@ object ReportBuilder { ...@@ -236,9 +236,7 @@ object ReportBuilder {
/** Single template render engine, this will have a cache for all compile templates */ /** Single template render engine, this will have a cache for all compile templates */
protected val engine = new TemplateEngine() protected val engine = new TemplateEngine()
engine.allowReload = false
/** Cache of temp file for templates from the classpath / jar */
private[report] var templateCache: Map[String, File] = Map()
/** This will give the total number of pages including all nested pages */ /** This will give the total number of pages including all nested pages */
def countPages(page: ReportPage): Int = { def countPages(page: ReportPage): Int = {
...@@ -254,15 +252,6 @@ object ReportBuilder { ...@@ -254,15 +252,6 @@ object ReportBuilder {
def renderTemplate(location: String, args: Map[String, Any] = Map()): String = { def renderTemplate(location: String, args: Map[String, Any] = Map()): String = {
Logging.logger.info("Rendering: " + location) Logging.logger.info("Rendering: " + location)
val templateFile: File = templateCache.get(location) match { engine.layout(location, args)
case Some(template) => template
case _ =>
val tempFile = File.createTempFile("ssp-template", new File(location).getName)
tempFile.deleteOnExit()
IoUtils.copyStreamToFile(getClass.getResourceAsStream(location), tempFile)
templateCache += location -> tempFile
tempFile
}
engine.layout(TemplateSource.fromFile(templateFile), args)
} }
} }
\ No newline at end of file
...@@ -79,11 +79,8 @@ class ReportBuilderTest extends TestNGSuite with Matchers { ...@@ -79,11 +79,8 @@ class ReportBuilderTest extends TestNGSuite with Matchers {
@Test @Test
def testRenderTemplate: Unit = { def testRenderTemplate: Unit = {
ReportBuilder.templateCache = Map()
ReportBuilder.templateCache shouldBe empty
ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "test")) shouldBe "test" ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "test")) shouldBe "test"
ReportBuilder.templateCache.size shouldBe 1
ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "bla")) shouldBe "bla" ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "bla")) shouldBe "bla"
ReportBuilder.templateCache.size shouldBe 1
} }
} }
...@@ -127,6 +127,22 @@ ...@@ -127,6 +127,22 @@
</executions> </executions>
<!-- ... (see other usage or goals for details) ... --> <!-- ... (see other usage or goals for details) ... -->
</plugin> </plugin>
<plugin>
<groupId>org.scalatra.scalate</groupId>
<artifactId>maven-scalate-plugin_2.10</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>precompile</goal>
</goals>
<configuration>
<contextClass>org.fusesource.scalate.DefaultRenderContext</contextClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
...@@ -280,4 +296,12 @@ ...@@ -280,4 +296,12 @@
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>
<dependencies>
<dependency>
<groupId>org.scalatra.scalate</groupId>
<artifactId>scalate-core_2.10</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</project> </project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment