summaryrefslogtreecommitdiff
path: root/book/src/main/scala/book/BookData.scala
blob: 9fa4d5e9d223614c99d6b0ce398cf8ddb333e267 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package book

import java.io.File

import acyclic.file
import ammonite.all._
import ammonite.ops.Path
import scalatags.Text.TypedTag
import scalatags.Text.all._
object BookData {
  val wd = processWorkingDir
  val cloneRoot = Path(System.getProperty("clone.root"))


  lazy val javaAPIs = {
    import java.io.File


    val roots = Seq(
      "scala-js"/'javalanglib/'src/'main/'scala,
      "scala-js"/'javalib/'src/'main/'scala
    )
    for{
      root <- roots
      file <- ls.rec! cloneRoot/root
      if file.ext == "scala"
    } yield{

      val path = (file - cloneRoot - root).toString.stripSuffix(".scala")
      val filename = path.replace('/', '.')

      val docpath = s"https://docs.oracle.com/javase/7/docs/api/$path.html"
      filename -> docpath
    }
  }
  var counter = 0
  def example(t: TypedTag[String], main: String) = {
    val tagId = "example"+counter
    counter += 1
    Seq(
      t(id:=tagId, display.block, overflow.scroll),
      script(s"$main(document.getElementById('$tagId'))")
    )
  }

  def split = div(cls:="pure-g")
  def more = div(cls:="pure-u-1 pure-u-md-13-24")
  def less = div(cls:="pure-u-1 pure-u-md-11-24")
  def half = div(cls:="pure-u-1 pure-u-md-1-2")


  val hl = new scalatex.site.Highlighter {
    override val pathMappings = Seq(
      cloneRoot/"scala-js" -> "https://github.com/scala-js/scala-js/blob/master",
      cloneRoot/"workbench-example-app" -> "https://github.com/lihaoyi/workbench-example-app/blob/master",
      wd -> "https://github.com/lihaoyi/hands-on-scala-js/blob/master"
    )
    override val suffixMappings = Map(
      "scala" -> "scala",
      "sbt" -> "scala",
      "js" -> "javascript"
    )
    def scala(s: String) = this.highlight(s, "scala")
    def bash(s: String) = this.highlight(s, "bash")
    def html(s: String) = this.highlight(s, "html")
    def xml(s: String) = this.highlight(s, "xml")
    def diff(s: String) = this.highlight(s, "diff")
    def javascript(s: String) = this.highlight(s, "javascript")
  }
}