From 36ed0c82a5ae0d5676416d4e607f5a0a172ad271 Mon Sep 17 00:00:00 2001 From: Dennis Kleber Date: Mon, 25 Jun 2018 13:39:33 +0200 Subject: [PATCH 1/2] extend template for js --- app/controllers/TemplateController.scala | 7 ++++++- app/models/Template.scala | 3 ++- app/services/RenderService.scala | 8 +++++++- app/views/mustache/simple/main.mustache | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/TemplateController.scala b/app/controllers/TemplateController.scala index 4453d2d..6c5ceb4 100644 --- a/app/controllers/TemplateController.scala +++ b/app/controllers/TemplateController.scala @@ -43,7 +43,12 @@ class TemplateController @Inject() ( Logger.debug(path) navigationDAO.findByPath(path).flatMap { case Some(navigation) => Future.successful(Ok(render.buildSimpleHtml(navigation, template.templateData, template.navigationData.active))) - case _ => Future.successful(BadRequest("Navigation not found")) + case _ => + navigationDAO.find("GlobalNav").flatMap { + case Some(navigation) => Future.successful(Ok(render.buildSimpleHtml(navigation, template.templateData, template.navigationData.active))) + case _ => Future.successful(BadRequest("Navigation not found")) + } + } } } diff --git a/app/models/Template.scala b/app/models/Template.scala index 4d02153..d83b538 100644 --- a/app/models/Template.scala +++ b/app/models/Template.scala @@ -9,7 +9,8 @@ case class MetaData ( ) case class TemplateData ( title: String, - content: String + content: String, + head: Option[String] ) case class NavigationData ( diff --git a/app/services/RenderService.scala b/app/services/RenderService.scala index 934e93e..1e220d7 100644 --- a/app/services/RenderService.scala +++ b/app/services/RenderService.scala @@ -22,11 +22,17 @@ class RenderService @Inject() ( def buildSimpleHtml (navigation: Navigation, templateData: TemplateData, active: String): String = { val navbarContent:String = build_navigation(navigation, active) - + val host = templateData.head match { + case Some(head) => + new String(java.util.Base64.getDecoder.decode(head), "UTF-8") + case None => + "" + } scalate.render("mustache/simple/main.mustache", Map( "title" -> templateData.title, "hostURL" -> hostURL, "navbarContent" -> navbarContent, + "host" -> host, "imprintURL" -> imprintURL, "content" -> new String(java.util.Base64.getDecoder.decode(templateData.content), "UTF-8") )).toString diff --git a/app/views/mustache/simple/main.mustache b/app/views/mustache/simple/main.mustache index 99fe64c..4125806 100644 --- a/app/views/mustache/simple/main.mustache +++ b/app/views/mustache/simple/main.mustache @@ -11,6 +11,7 @@ + {{head}}