aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/js/src/html/Layout.scala
blob: 59d27a15d550388533c960e4d6d4c4564ceff995 (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
71
package dotty.tools.dottydoc
package js
package html

import scalatags.JsDom.all._

object Index {
  import model.Entities._
  import CustomTags._

  def layout(ent: Entity) = ent match {
    case x: Entity with Members with Modifiers => packageMember(x)
  }

  def packageMember(m: Entity with Members with Modifiers) =
    div(
      cls := "mdl-layout mdl-js-layout mdl-layout--fixed-drawer",
      div(
        cls := "mdl-layout__drawer",
        span(
          cls := "mdl-layout-title subtitle",
          m.path.dropRight(1).mkString(".")
        ),
        span(
          cls := "mdl-layout-title",
          m.name
        ),
        nav(
          cls := "mdl-navigation",
          a(cls := "mdl-navigation__link", href := companionHref(m).map(_.path.last + ".html").getOrElse(""), "Companion " + m.name),
          a(cls := "mdl-navigation__link", href := m.sourceUrl, "Source")
        ),
        span(
          cls := "mdl-layout-title",
          "Packages"
        )
      ),
      main(
        cls := "mdl-layout__content",
        div(
          cls := "page-content",
          div(raw(m.comment.fold("")(_.body))),
          div(
            cls := "mld-grid",
            m.members
             .collect { case x: Entity with Modifiers if !x.isPrivate => x}
             .flatMap(member)
          )
        )
      )
    )

  def companionHref(m: Entity): Option[PackageMember] = {
    val pack = m.path.dropRight(1).mkString(".")
    println(pack)
    ParsedIndex.packages.get(pack)
      .flatMap(_.children.find(e => e.name == m.name && e.path.last != m.path.last))
  }

  def member(m: Entity) = m match {
    case m: Entity with Modifiers => Seq(
        div(
          cls := "mdl-cell mdl-cell--12-col",
          h6(m.modifiers.mkString(" ") + " " + m.kind + " " + m.name)
        ),
        div(
          cls := "mdl-cell mdl-cell--12-col",
          raw(m.comment.fold("")(_.body)))
    )
  }
}