From 349a62f88b9ec27ffc4036c2e39358fb27a83b4e Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 19 Oct 2016 14:08:48 +0200 Subject: [PATCH] Introduce write forwarders on `Writer` to enable selective overriding --- .../lightbend/paradox/ParadoxProcessor.scala | 10 ++++---- .../lightbend/paradox/markdown/Writer.scala | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/com/lightbend/paradox/ParadoxProcessor.scala b/core/src/main/scala/com/lightbend/paradox/ParadoxProcessor.scala index f35ec9a3..c2747bab 100644 --- a/core/src/main/scala/com/lightbend/paradox/ParadoxProcessor.scala +++ b/core/src/main/scala/com/lightbend/paradox/ParadoxProcessor.scala @@ -76,16 +76,16 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer) private val page = loc.tree.label val getTitle = page.title - val getContent = writer.write(page.markdown, context) + val getContent = writer.writeContent(page.markdown, context) lazy val getBase = page.base lazy val getHome = link(Some(loc.root)) lazy val getPrev = link(loc.prev) lazy val getNext = link(loc.next) - lazy val getBreadcrumbs = writer.writeFragment(Breadcrumbs.markdown(leadingBreadcrumbs, loc.path), context) - lazy val getNavigation = writer.writeFragment(pageToc.root(loc), context) + lazy val getBreadcrumbs = writer.writeBreadcrumbs(Breadcrumbs.markdown(leadingBreadcrumbs, loc.path), context) + lazy val getNavigation = writer.writeNavigation(pageToc.root(loc), context) lazy val hasSubheaders = page.headers.nonEmpty - lazy val getToc = writer.writeFragment(headerToc.headers(loc), context) + lazy val getToc = writer.writeToc(headerToc.headers(loc), context) lazy val getProperties = context.properties.asJava @@ -99,7 +99,7 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer) lazy val getHref: String = location.map(href).orNull lazy val getHtml: String = location.map(link).orNull lazy val getTitle: String = location.map(title).orNull - lazy val isActive: Boolean = location.map(active).getOrElse(false) + lazy val isActive: Boolean = location.exists(active) private def link(location: Location[Page]): String = { val node = if (active(location)) diff --git a/core/src/main/scala/com/lightbend/paradox/markdown/Writer.scala b/core/src/main/scala/com/lightbend/paradox/markdown/Writer.scala index 7d9a7eab..3c843ca3 100644 --- a/core/src/main/scala/com/lightbend/paradox/markdown/Writer.scala +++ b/core/src/main/scala/com/lightbend/paradox/markdown/Writer.scala @@ -35,6 +35,30 @@ class Writer(serializer: Writer.Context => ToHtmlSerializer) { verbatimSerializers.asJava, serializerPlugins(context).asJava)) + /** + * Write main content. + */ + def writeContent(node: Node, context: Writer.Context): String = + writeFragment(node, context) + + /** + * Write breadcrumbs fragment. + */ + def writeBreadcrumbs(node: Node, context: Writer.Context): String = + writeFragment(node, context) + + /** + * Write navigation fragment. + */ + def writeNavigation(node: Node, context: Writer.Context): String = + writeFragment(node, context) + + /** + * Write navigation fragment. + */ + def writeToc(node: Node, context: Writer.Context): String = + writeFragment(node, context) + /** * Write markdown to HTML, in the context of a page. */