diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-23 16:04:20 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:32:40 +0100 |
commit | 7b2c84b51850a4e64107a99f9780d0ee578a1c4a (patch) | |
tree | 319475329afbef6a27b8a364a3477ad60192cc93 /doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala | |
parent | c3b463a04141e67ee8559c8b422c0229a1a6351b (diff) | |
download | dotty-7b2c84b51850a4e64107a99f9780d0ee578a1c4a.tar.gz dotty-7b2c84b51850a4e64107a99f9780d0ee578a1c4a.tar.bz2 dotty-7b2c84b51850a4e64107a99f9780d0ee578a1c4a.zip |
Generalize table of contents for dottydoc
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala | 37 |
1 files changed, 37 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 868e28bce..fe6a05bbc 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/tags.scala @@ -131,4 +131,41 @@ object tags { } } } + + /** Can be used to render the `sidebar.yml` entries, represented here as + * `Title`. + * + * ```html + * {% renderTitle title, parent %} + * ``` + * + * The rendering currently works on depths up to 2. This means that each + * title can have a subsection with its own titles. + */ + case class RenderTitle(params: Map[String, AnyRef]) extends Tag("renderTitle") with ParamConverter { + private def renderTitle(t: Title, parent: String): String = { + if (!t.url.isDefined && t.subsection.nonEmpty) { + val onclickFunction = + s"""(function(){var child=document.getElementById("${t.title}");child.classList.toggle("show");child.classList.toggle("hide");})();""" + s"""|<a class="toggle-children" onclick='$onclickFunction'>${t.title}</a> + |<ul id="${t.title}" class="${if (parent.toLowerCase == t.title.toLowerCase) "show" else "hide"}"> + | ${t.subsection.map(renderTitle(_, parent)).mkString("<li>", "</li><li>", "</li>")} + |</ul>""".stripMargin + } + else if (t.url.isDefined) { + val url = t.url.get + s"""<a href="$baseurl/$url">${t.title}</a>""" + } + else /*if (t.subsection.nonEmpty)*/ { + /*dottydoc.*/println(s"url was defined for subsection with title: ${t.title}, remove url to get toggleable entries") + t.title + } + } + + override def render(ctx: TemplateContext, nodes: LNode*): AnyRef = + (nodes(0).render(ctx), nodes(1).render(ctx)) match { + case (t: Title, parent: String) => renderTitle(t, parent) + case _ => null + } + } } |