Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romainreuillon committed Jan 16, 2020
1 parent 5e8445c commit 864091c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
28 changes: 16 additions & 12 deletions site/src/main/scala/scalatex/site/Site.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package scalatex.site

import java.io.FileOutputStream
import java.nio.CharBuffer
import java.nio.file.{Files, StandardCopyOption}
import java.nio.file.{Files, StandardCopyOption, StandardOpenOption}

import ammonite.ops.{Path, _}
import os.SubProcess.{InputStream, OutputStream}
import scalatags.Text.all._
import scalatags.Text.{attrs, tags2}

Expand Down Expand Up @@ -94,27 +96,29 @@ trait Site{
def content: Map[String, Page]

def bundleResources(outputRoot: Path) = {
for {
dest <- Seq(scriptName, stylesName)
path = outputRoot / dest
} new FileOutputStream(path.toIO, true).close()

for {
(ext, dest) <- Seq("js" -> scriptName, "css" -> stylesName)
path = outputRoot / dest
res <- autoResources |? (_.ext == ext)
} {
val is = res.getInputStream
val path = outputRoot / dest
try {
path.toIO.mkdirs()
Files.copy(is, path.wrapped, StandardCopyOption.REPLACE_EXISTING)
} finally is.close()
val content = read(res)

path.toIO.getParentFile.mkdirs()
Files.writeString(path.wrapped, content, StandardOpenOption.CREATE)
}

for {
res <- manualResources
} {
val is = res.getInputStream
val content = read(res)
val path = outputRoot/(res relativeTo resource)
try {
path.toIO.mkdirs()
Files.copy(is, path.wrapped, StandardCopyOption.REPLACE_EXISTING)
} finally is.close()
path.toIO.getParentFile.mkdirs()
Files.writeString(path.wrapped, content, StandardOpenOption.CREATE)
}
}

Expand Down
10 changes: 5 additions & 5 deletions site/src/test/scala/scalatex/site/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,21 @@ object Tests extends TestSuite{
}
'Site{
'simple {
rm! wd/'site/'target/'output
rm! wd / "site" / "target"/ "output"
val site = new scalatex.site.Site {
def content = Map("index.html" -> (defaultHeader, Hello()))
}
site.renderTo(wd/'site/'target/'output)
site.renderTo(wd/ "site" / "target" / "output")

def check() = {
val readText = read! wd/'site/'target/'output/"index.html"
val readText = read! wd / "site" / "target" / "output" /"index.html"
assert(
readText.contains("Hello World"),
readText.contains("I am a cow!"),
readText.contains("<div>"),
readText.contains("<h1>"),
exists(wd/'site/'target/'output/"scripts.js"),
exists(wd/'site/'target/'output/"styles.css")
exists(wd / "site" / "target" / "output" / "scripts.js"),
exists(wd/ "site" / "target" / "output" / "styles.css")
)
}
check()
Expand Down

0 comments on commit 864091c

Please sign in to comment.