in riff-raff/app/controllers/Application.scala [186:269]
def documentation(resource: String) = {
if (resource.endsWith(".png")) {
assets.at("/docs", resource)
} else {
authAction { request =>
if (resource.endsWith("/index")) {
Redirect(
routes.Application.documentation(resource.stripSuffix("index"))
)
} else {
val markDownLines = getMarkdownLines(resource)
if (markDownLines.isEmpty) {
NotFound(
views.html.notFound(config, menu)(
request,
s"No documentation found for $resource"
)
)
} else {
val markDown = markDownLines.mkString("\n")
val title = getMarkdownTitle(markDownLines).getOrElse(resource)
val (next, prev) = getNextPrevFromHeader(resource, markDownLines)
val breadcrumbs = {
val hierarchy =
resource.split('/').filterNot(_.isEmpty).dropRight(1)
hierarchy.foldLeft(
List(
Link(
"Documentation",
routes.Application.documentation(""),
""
)
)
) { (acc, crumb) =>
acc ++ Link(
List(acc.last.url.stripSuffix("/"), crumb)
.filterNot(_.isEmpty)
.mkString("", "/", "/")
)
} ++ Some(
Link(
title,
routes.Application.documentation(resource),
resource
)
)
}
resource match {
case "magenta-lib/types" | "magenta-lib/types.md" =>
val sections =
DeployTypeDocs.generateDocs(deploymentTypes).map {
case (dt, docs) =>
val typeDocumentation =
views.html.documentation.deploymentTypeSnippet(docs)
(dt.name, typeDocumentation)
}
Ok(
views.html.documentation.markdownBlocks(config, menu)(
request,
"Deployment Types",
breadcrumbs,
sections
)
)
case _ =>
Ok(
views.html.documentation.markdown(config, menu)(
request,
s"Documentation: $title",
markDown,
breadcrumbs,
prev,
next
)
)
}
}
}
}
}
}