summaryrefslogtreecommitdiff
path: root/book/src/main/scala/book/Utils.scala
blob: 0b435a3ea9deb5f09a2a3fb73fa0e7919ebdc8a7 (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
package book


import scala.collection.mutable
import scalatags.Text.all._

case class Node(name: String, children: mutable.Buffer[Node])
object Utils{
  val autoResources = Seq(
    "META-INF/resources/webjars/highlightjs/8.2-1/highlight.min.js",
    "META-INF/resources/webjars/highlightjs/8.2-1/styles/idea.min.css",
    "META-INF/resources/webjars/highlightjs/8.2-1/languages/scala.min.js",
    "META-INF/resources/webjars/highlightjs/8.2-1/languages/javascript.min.js",
    "META-INF/resources/webjars/highlightjs/8.2-1/languages/bash.min.js",
    "css/pure-min.css",
    "css/layouts/side-menu.css",
    "js/ui.js"
  )
  
  val manualResources = Seq(
    "images/javascript-the-good-parts-the-definitive-guide.jpg",
    "example-fastopt.js"
  )
  
  val includes = for(res <- Utils.autoResources) yield {
    if (res.endsWith(".js"))
      script(src:=res)
    else if (res.endsWith(".css"))
      link(rel:="stylesheet", href:=res)
    else
      raw("")
  }
  println(includes)
  var indent = 1
  val headers = Seq(h1, h2, h3, h4, h5, h6)
  val structure = Node("Hands-on Scala.js", mutable.Buffer.empty)
  var current = structure
  case class sect(name: String){
    indent += 1
    val newNode = Node(name, mutable.Buffer.empty)
    current.children.append(newNode)
    val prev = current
    current = newNode
    def apply(args: Frag*) = {
      val res = Seq(
        headers(indent-1)(cls:="content-subhead", id:=munge(name), name) +: args:_*
      )
      indent -= 1
      current = prev
      res
    }
  }
  def munge(name: String) = {
    name.replace(" ", "")
  }

}