Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
3ab8f781
Commit
3ab8f781
authored
Mar 19, 2017
by
Peter van 't Hof
Committed by
GitHub
Mar 19, 2017
Browse files
Merge pull request #36 from biopet/fix-BIOPET-610
compiling ssp-template files with scalate
parents
dc6dc49c
800cc879
Changes
3
Hide whitespace changes
Inline
Side-by-side
biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
View file @
3ab8f781
...
...
@@ -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.
{
IoUtils
,
Logging
,
ToolCommand
}
import
org.broadinstitute.gatk.utils.commandline.Input
import
org.fusesource.scalate.
{
TemplateEngine
,
TemplateSource
}
import
org.fusesource.scalate.TemplateEngine
import
scala.collection.mutable
import
scala.language.postfixOps
...
...
@@ -236,9 +236,7 @@ object ReportBuilder {
/** Single template render engine, this will have a cache for all compile templates */
protected
val
engine
=
new
TemplateEngine
()
/** Cache of temp file for templates from the classpath / jar */
private
[
report
]
var
templateCache
:
Map
[
String
,
File
]
=
Map
()
engine
.
allowReload
=
false
/** This will give the total number of pages including all nested pages */
def
countPages
(
page
:
ReportPage
)
:
Int
=
{
...
...
@@ -254,15 +252,6 @@ object ReportBuilder {
def
renderTemplate
(
location
:
String
,
args
:
Map
[
String
,
Any
]
=
Map
())
:
String
=
{
Logging
.
logger
.
info
(
"Rendering: "
+
location
)
val
templateFile
:
File
=
templateCache
.
get
(
location
)
match
{
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
)
engine
.
layout
(
location
,
args
)
}
}
\ No newline at end of file
biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/report/ReportBuilderTest.scala
View file @
3ab8f781
...
...
@@ -79,11 +79,8 @@ class ReportBuilderTest extends TestNGSuite with Matchers {
@Test
def
testRenderTemplate
:
Unit
=
{
ReportBuilder
.
templateCache
=
Map
()
ReportBuilder
.
templateCache
shouldBe
empty
ReportBuilder
.
renderTemplate
(
"/template.ssp"
,
Map
(
"arg"
->
"test"
))
shouldBe
"test"
ReportBuilder
.
templateCache
.
size
shouldBe
1
ReportBuilder
.
renderTemplate
(
"/template.ssp"
,
Map
(
"arg"
->
"bla"
))
shouldBe
"bla"
ReportBuilder
.
templateCache
.
size
shouldBe
1
}
}
pom.xml
View file @
3ab8f781
...
...
@@ -127,6 +127,22 @@
</executions>
<!-- ... (see other usage or goals for details) ... -->
</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>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
...
...
@@ -280,4 +296,12 @@
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>
org.scalatra.scalate
</groupId>
<artifactId>
scalate-core_2.10
</artifactId>
<version>
1.7.0
</version>
</dependency>
</dependencies>
</project>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment