aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/test/SourceFileOps.scala
blob: 37520921d5aec11a7cfb29fd74f5ab0d2e7a3ba2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package dotty.tools
package dottydoc
package staticsite

import dotc.util.SourceFile
import java.io.{ BufferedWriter, OutputStreamWriter }
import io.VirtualFile
import scala.io.Codec

import model.Package

trait SourceFileOps {
  import scala.collection.JavaConverters._
  val site = new Site(new java.io.File("../doc-tool/resources/"), "test-site", Map.empty)

  def stringToSource(path: String, sourceCode: String): SourceFile = {
    val virtualFile = new VirtualFile(path, path)
    val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
    writer.write(sourceCode)
    writer.close()

    new SourceFile(virtualFile, Codec.UTF8)
  }

  def markdownPage(
    sourceCode: String,
    path: String = "test-page",
    params: Map[String, AnyRef] = Map.empty,
    includes: Map[String, Include] = Map.empty,
    docs: Map[String, Package] = Map.empty
  ) = new MarkdownPage(
    path,
    stringToSource(path, sourceCode),
    params,
    includes,
    docs
  )

  def htmlPage(
    sourceCode: String,
    path: String = "test-page",
    params: Map[String, AnyRef] = Map.empty,
    includes: Map[String, Include] = Map.empty,
    docs: Map[String, Package] = Map.empty
  ) = new HtmlPage(
    path,
    stringToSource(path, sourceCode),
    params,
    includes
  )
}