aboutsummaryrefslogtreecommitdiff
path: root/dottydoc
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-04-27 17:28:45 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:20 +0200
commit32b4a9c331d9a078aa50db554667ca908eb8a344 (patch)
treea2a25f7756ae430861b9ae37d1feca55efd2507c /dottydoc
parent46ac1bfe42d408dffd74a89bd2d9e3d13b68ee12 (diff)
downloaddotty-32b4a9c331d9a078aa50db554667ca908eb8a344.tar.gz
dotty-32b4a9c331d9a078aa50db554667ca908eb8a344.tar.bz2
dotty-32b4a9c331d9a078aa50db554667ca908eb8a344.zip
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
Diffstat (limited to 'dottydoc')
-rw-r--r--dottydoc/js/src/html/Layout.scala122
-rw-r--r--dottydoc/js/src/html/Member.scala76
-rw-r--r--dottydoc/js/static/index.css11
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala4
-rw-r--r--dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/Entity.scala2
-rw-r--r--dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala4
6 files changed, 136 insertions, 83 deletions
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;
+}
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
index b585c2745..2d3496f6f 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
@@ -87,11 +87,11 @@ object Phases {
/** def */
case d: DefDef =>
- Def(d.name.toString, flags(d), path(d))
+ Def(d.name.toString, flags(d), path(d), returnType(d.tpt))
/** val */
case v: ValDef if !v.symbol.is(Flags.ModuleVal) =>
- Val(v.name.toString, flags(v), path(v))
+ Val(v.name.toString, flags(v), path(v), returnType(v.tpt))
case x => {
//dottydoc.println(s"Found unwanted entity: $x (${x.pos}, ${comment})\n${x.show}")
diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/Entity.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/Entity.scala
index 675bc8319..5acdfee33 100644
--- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/Entity.scala
+++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/Entity.scala
@@ -99,6 +99,7 @@ object Entities {
name: String,
modifiers: List[String],
path: List[String],
+ returnValue: String,
var comment: Option[Comment] = None
) extends Entity with Modifiers {
override val kind = "def"
@@ -109,6 +110,7 @@ object Entities {
name: String,
modifiers: List[String],
path: List[String],
+ returnValue: String,
var comment: Option[Comment] = None
) extends Entity with Modifiers {
override val kind = "val"
diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala
index 09510a1f8..9de1cf6ad 100644
--- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala
+++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala
@@ -34,4 +34,8 @@ object EntityFactories {
pathList(ref)
}
+
+ // TODO: should be updated to link to local entities
+ def returnType(t: Tree)(implicit ctx: Context): String =
+ t.show
}