Skip to content

Commit

Permalink
Fix StringTemplate indent bug for snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
gsechaud committed Jan 27, 2017
1 parent b856119 commit e198253
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.lightbend.paradox.template

import java.io.File
import java.io.{ File, OutputStreamWriter, FileOutputStream }
import java.util.{ Map => JMap }
import org.stringtemplate.v4.misc.STMessage
import org.stringtemplate.v4.{ STErrorListener, STRawGroupDir, ST }
import org.stringtemplate.v4.{ STErrorListener, STRawGroupDir, ST, NoIndentWriter }
import collection.concurrent.TrieMap

object CachedTemplates {
Expand Down Expand Up @@ -54,7 +54,10 @@ class PageTemplate(directory: File, name: String = PageTemplate.DefaultName, sta
t.add("page", contents)
case None => sys.error(s"StringTemplate '$name' was not found for '$target'. Create a template or set a theme that contains one.")
}
template.write(target, errorListener)
val osWriter = new OutputStreamWriter(new FileOutputStream(target))
val noIndentWriter = new NoIndentWriter(osWriter)
template.write(noIndentWriter) // does not take into account the errorListener any more...
osWriter.close
target
}

Expand Down
6 changes: 6 additions & 0 deletions plugin/src/sbt-test/paradox/snippet-noindent-writer/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lazy val root = (project in file(".")).
enablePlugins(ParadoxPlugin).
settings(
paradoxTheme := None,
name := "snippet-indent"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div>
<div>
<pre class="prettyprint"><code class="language-scala">object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say(&quot;hello&quot;)
}</code></pre>
</div>
</div>

<pre class="prettyprint"><code class="language-scala">object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say(&quot;hello&quot;)
}</code></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<div>
$page.content$
</div>
</div>

$page.content$
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #hello_example
object Hello extends App {
def say(str: String): Unit = {
println(str)
}

say("hello")
}
// #hello_example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@@snip[Hello](code-samples/Hello.scala)
3 changes: 3 additions & 0 deletions plugin/src/sbt-test/paradox/snippet-noindent-writer/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> paradox

$ must-mirror target/paradox/site/main/index.html expected/index.html

0 comments on commit e198253

Please sign in to comment.