diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-11 19:06:50 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:31:06 +0100 |
commit | 280312716753fb226794ff9e2f9259d9c9e8d942 (patch) | |
tree | 60d45346f9ba240e9603db1c075ad6741c39887b /doc-tool/src/dotty/tools/dottydoc/staticsite | |
parent | 4f177580ff08eeea183cdcfec53eba2888162157 (diff) | |
download | dotty-280312716753fb226794ff9e2f9259d9c9e8d942.tar.gz dotty-280312716753fb226794ff9e2f9259d9c9e8d942.tar.bz2 dotty-280312716753fb226794ff9e2f9259d9c9e8d942.zip |
Make `Page#yaml` be `Map[String, String | List[String]]`
YAML front matter can be lists, unfortunately we don't have union types
in scala 2
Diffstat (limited to 'doc-tool/src/dotty/tools/dottydoc/staticsite')
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala | 15 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala index 556818007..965ded4f8 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala @@ -9,7 +9,7 @@ import dotc.config.Printers.dottydoc import com.vladsch.flexmark.html.HtmlRenderer import com.vladsch.flexmark.parser.Parser import com.vladsch.flexmark.ext.front.matter.AbstractYamlFrontMatterVisitor -import _root_.java.util.{ Map => JMap } +import _root_.java.util.{ Map => JMap, List => JList } case class IllegalFrontMatter(message: String) extends Exception(message) @@ -20,7 +20,7 @@ trait Page { def pageContent: String def params: Map[String, AnyRef] - def yaml(implicit ctx: Context): Map[String, String] = { + def yaml(implicit ctx: Context): Map[String, AnyRef] = { if (_yaml eq null) initFields() _yaml } @@ -30,7 +30,7 @@ trait Page { _html } - protected[this] var _yaml: Map[String, String] = _ + protected[this] var _yaml: Map[String, AnyRef /* String | JList[String] */] = _ protected[this] var _html: String = _ protected[this] def initFields()(implicit ctx: Context) = { val md = Parser.builder(ctx.docbase.markdownOptions).build.parse(pageContent) @@ -40,7 +40,10 @@ trait Page { _yaml = updatedYaml { yamlCollector .getData().asScala - .mapValues(_.asScala.headOption.getOrElse("")) + .mapValues { + case xs if xs.size == 1 => xs.get(0) + case xs => xs + } .toMap } @@ -67,11 +70,11 @@ trait Page { * removes "layout" from the parameters if it exists. We don't want to * preserve the layout from the previously expanded template */ - private def updatedYaml(newYaml: Map[String, String]): Map[String, String] = + private def updatedYaml(newYaml: Map[String, AnyRef]): Map[String, AnyRef] = params .get("page") .flatMap { - case page: Map[String, String] @unchecked => + case page: Map[String, AnyRef] @unchecked => Some(page - "layout" ++ newYaml) case _ => None } diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala index 8aee6f346..f2ecc6350 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala @@ -262,7 +262,7 @@ case class Site(val root: JFile, val docs: JList[_]) extends ResourceFinder { * expansion of the template with all its layouts and includes. */ def render(page: Page, params: Map[String, AnyRef] = Map.empty)(implicit ctx: Context): String = - page.yaml.get("layout").flatMap(layouts.get(_)) match { + page.yaml.get("layout").flatMap(xs => layouts.get(xs.toString)) match { case None => page.html case Some(layout) => |