From 32b4a9c331d9a078aa50db554667ca908eb8a344 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 27 Apr 2016 17:28:45 +0200 Subject: Add initial return values to members - to be updated This commit adds return values to defs and vals - but does not provide a link to these. This is to be continued --- dottydoc/js/src/html/Layout.scala | 122 +++++++++++++------------------------- dottydoc/js/src/html/Member.scala | 76 ++++++++++++++++++++++++ dottydoc/js/static/index.css | 11 +++- 3 files changed, 128 insertions(+), 81 deletions(-) create mode 100644 dottydoc/js/src/html/Member.scala (limited to 'dottydoc/js') diff --git a/dottydoc/js/src/html/Layout.scala b/dottydoc/js/src/html/Layout.scala index cdd80586e..77f405576 100644 --- a/dottydoc/js/src/html/Layout.scala +++ b/dottydoc/js/src/html/Layout.scala @@ -10,56 +10,54 @@ import org.scalajs.dom.html.{Anchor, Div} object IndexLayout { import model.Entities._ import CustomTags._ + import MemberLayout._ - def layout(ent: Entity) = entity(ent) - - def entity(m: Entity) = + def layout(m: Entity) = div( + cls := "mdl-layout mdl-js-layout mdl-layout--fixed-drawer", 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 := "related mdl-navigation", - companion(m), - a(cls := "mdl-navigation__link", href := m.sourceUrl, "Source") - ), - span( - cls := "mdl-layout-title", - id := "docs-title", - "Docs" - ), - searchView, - packageView + cls := "mdl-layout__drawer", + span( + cls := "mdl-layout-title subtitle", + m.path.dropRight(1).mkString(".") + ), + span( + cls := "mdl-layout-title", + m.name + ), + nav( + cls := "related mdl-navigation", + companion(m), + a(cls := "mdl-navigation__link", href := m.sourceUrl, "Source") ), - main( - cls := "mdl-layout__content", - div( - cls := "page-content", - div(raw(m.comment.fold("")(_.body))), - m match { - case e: Entity with Members => - Seq( - h5("Members"), - div( - cls := "mld-grid", - e.members - .collect { case x: Entity with Modifiers if !x.isPrivate => x} - .flatMap(member) - ) + span( + cls := "mdl-layout-title", + id := "docs-title", + "Docs" + ), + searchView, + packageView + ), + main( + cls := "mdl-layout__content", + div( + cls := "page-content", + div(raw(m.comment.fold("")(_.body))), + m match { + case e: Entity with Members => + Seq( + h5("Members"), + div( + cls := "mld-grid", + e.members + .collect { case x: Entity with Modifiers if !x.isPrivate => x} + .flatMap(member(_, m)) ) - case _ => () - } - ) + ) + case _ => () + } ) ) + ) def searchView = div( cls := "search-container", @@ -99,40 +97,4 @@ object IndexLayout { ) }.getOrElse(span()) } - - def member(m: Entity) = { - def toggleBetween(short: Div, and: Div): Unit = - if (and.style.display == "none") { - and.style.display = "block" - short.style.display = "none" - } else { - and.style.display = "none" - short.style.display = "block" - } - - m match { - case m: Entity with Modifiers => - val shortComment = div( - cls := "mdl-cell mdl-cell--12-col summary-comment", - raw(m.comment.fold("")(_.short)) - ).render - val fullComment = div( - cls := "mdl-cell mdl-cell--12-col full-comment", - style := "display: none;", - raw(m.comment.fold("")(_.body)) - ).render - val divs = div( - cls := "mdl-cell mdl-cell--12-col member", - onclick := { () => toggleBetween(shortComment, and = fullComment) }, - div( - cls := "mdl-cell mdl-cell--12-col", - h6(m.modifiers.mkString(" ") + " " + m.kind + " " + m.name) - ), - shortComment, - fullComment - ) - Seq(divs) - case _ => Nil - } - } } diff --git a/dottydoc/js/src/html/Member.scala b/dottydoc/js/src/html/Member.scala new file mode 100644 index 000000000..9dc5d4da2 --- /dev/null +++ b/dottydoc/js/src/html/Member.scala @@ -0,0 +1,76 @@ +package dotty.tools.dottydoc +package js +package html + +import scalatags.JsDom.all._ +import scalatags.JsDom.TypedTag +import org.scalajs.dom +import org.scalajs.dom.html.{Anchor, Div} + +object MemberLayout { + import model.Entities._ + import CustomTags._ + + def member(m: Entity, parent: Entity) = { + def toggleBetween(short: Div, and: Div): Unit = + if (and.style.display == "none") { + and.style.display = "block" + short.style.display = "none" + } else { + and.style.display = "none" + short.style.display = "block" + } + + m match { + case m: Entity with Modifiers => + val shortComment = div( + cls := "mdl-cell mdl-cell--12-col summary-comment", + raw(m.comment.fold("")(_.short)) + ).render + + val fullComment = div( + cls := "mdl-cell mdl-cell--12-col full-comment", + style := "display: none;", + raw(m.comment.fold("")(_.body)) + ).render + + + val hasLongerFullComment = m.comment.fold(false) { c => + c.short.length + 5 < c.body.length + } + + val divs = div( + cls := + s""" + mdl-cell mdl-cell--12-col member + ${if (hasLongerFullComment) "member-fullcomment" else ""} + """, + onclick := { () => toggleBetween(shortComment, and = fullComment) }, + div( + cls := "mdl-cell mdl-cell--12-col", + span(cls := "member-name", m.modifiers.mkString(" ") + " " + m.kind + " " + m.name), + returnValue(m, parent) + ), + shortComment, + fullComment + ) + Seq(divs) + case _ => Nil + } + } + + def returnValue(m: Entity with Modifiers, parent: Entity) = { + // shortens: "Option.this.A" => "A" + def shorten(s: String): String = s.split('.').toList match { + case x :: Nil => x + case x :: xs if x == parent.name => xs.last + case xs => s + } + + m match { + case v: Val => span(cls := "return-value", ": " + shorten(v.returnValue)) + case d: Def => span(cls := "return-value", ": " + shorten(d.returnValue)) + case _ => span() + } + } +} diff --git a/dottydoc/js/static/index.css b/dottydoc/js/static/index.css index 9ac1ec8ec..7423198b9 100644 --- a/dottydoc/js/static/index.css +++ b/dottydoc/js/static/index.css @@ -8,7 +8,7 @@ span.subtitle { padding-top: 32px; } -div.member:hover { +div.member.member-fullcomment:hover { cursor: pointer; } @@ -37,3 +37,12 @@ span#docs-title { line-height: normal; padding-top: 2em; } + +span.member-name, span.return-value { + font-family: "Roboto","Helvetica","Arial",sans-serif; + font-weight: 400; + font-size: 16px; + margin: 24px 0 16px; + letter-spacing: .04em; + line-height: 24px; +} -- cgit v1.2.3