aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-23 17:10:01 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:32:41 +0100
commitdc4bd3d69c1671036dd85be5311c52fd0bc85c4f (patch)
treea79713a8e54497773d2841d5576160a3468ef2f6 /doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala
parent7b2c84b51850a4e64107a99f9780d0ee578a1c4a (diff)
downloaddotty-dc4bd3d69c1671036dd85be5311c52fd0bc85c4f.tar.gz
dotty-dc4bd3d69c1671036dd85be5311c52fd0bc85c4f.tar.bz2
dotty-dc4bd3d69c1671036dd85be5311c52fd0bc85c4f.zip
Add `{% docstring "scala.collection.Seq" %}` support
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala')
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala
index fe6a05bbc..7f85846dc 100644
--- a/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala
@@ -9,6 +9,7 @@ import liqp.TemplateContext
import liqp.nodes.LNode
import java.util.{ Map => JMap }
+import model._
object tags {
@@ -168,4 +169,39 @@ object tags {
case _ => null
}
}
+
+ /** Allows the extraction of docstrings from the given path. E.g:
+ *
+ * ```html
+ * {% docstring "scala.collection.Seq" %}
+ * ```
+ *
+ * In Scaladoc, objects are denoted by a name ending in '$'. This means that
+ * a path that goes through, or targets an object need to appropriately
+ * intersperse these, e.g:
+ *
+ * ```html
+ * {% docstring "scala.collection.Seq$" %}
+ * ```
+ */
+ case class Docstring(params: Map[String, AnyRef]) extends Tag("docstring") {
+ private def find(xs: List[String], ent: Entity with Members): Option[Entity] = xs match {
+ case Nil => None
+ case x :: Nil =>
+ ent.members collect { case e: Entity with Members => e } find (_.path.last == x)
+ case x :: xs =>
+ ent.members collect { case e: Entity with Members => e } find (_.path.last == x) flatMap (find(xs, _))
+ }
+
+ override def render(ctx: TemplateContext, nodes: LNode*): AnyRef = nodes(0).render(ctx) match {
+ case query: String =>
+ params.get("originalDocs").collect {
+ case docs: Map[String, Package] @unchecked =>
+ val search = query.split("\\.")
+ if (search.isEmpty || !docs.contains(search.head)) null
+ else find(search.tail.toList, docs(search.head)).flatMap(_.comment.map(_.body)).getOrElse(null)
+ }.getOrElse(null)
+ case _ => null
+ }
+ }
}