Commits

Sam Adams  committed 0063f71

Fix template model access

  • Participants
  • Parent commits be7f023

Comments (0)

Files changed (4)

File chempound-webapi/src/main/java/net/chempound/webapp/output/Page.java

 package net.chempound.webapp.output;
 
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class Page {
 
-    private final Map<String, Object> model;
-    private final List<String> headers;
+    private final URI uri;
+    private String templatePath;
+    private final Map<String, Object> model = new HashMap<String, Object>();
+    private final List<String> headers = new ArrayList<String>();
+    private final List<String> stylesheets = new ArrayList<String>();
 
-    private String templatePath;
-
-    public Page(final Map<String, Object> model, final List<String> headers) {
-        this.model = model;
-        this.headers = headers;
+    public Page(final URI uri) {
+        this.uri = uri;
     }
 
     public void setTemplatePath(final String templatePath) {
         headers.add(header);
     }
 
+    public void addStylesheet(final String stylesheet) {
+        stylesheets.add(stylesheet);
+    }
+
     public String getTemplatePath() {
         return templatePath;
     }
+
+    public URI getUri() {
+        return uri;
+    }
+
+    public Map<String, Object> getModel() {
+        model.put("uri", uri);
+        model.put("templatePath", templatePath);
+        model.put("headers", headers);
+        model.put("stylesheets", stylesheets);
+        return model;
+    }
 }

File chempound-webapp/src/main/java/net/chempound/webapp/splashpage/SplashPageGenerator.java

 
 import javax.inject.Inject;
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 
 /**
  * @author Sam Adams
             }
         }
 
-        final Map<String,Object> map = new HashMap<String, Object>();
-        final List<String> headers = new ArrayList<String>();
-        final Page page = new Page(map, headers);
-        map.put("uri", aggregationUri);
-
+        final Page page = new Page(aggregationUri);
         writer.write(model, aggregationUri, page);
 
-        map.put("uri", aggregationUri);
-        map.put("template", page.getTemplatePath());
-        if (!headers.isEmpty()) {
-            map.put("headers", headers);
-        }
-
         final Template template = freemarker.getTemplate("splash.ftl");
-        return new TemplateRepresentation(template, map, MediaType.TEXT_HTML);
+        return new TemplateRepresentation(template, page.getModel(), MediaType.TEXT_HTML);
     }
 
     private static boolean isCollection(final Model model, final URI aggregationUri) {

File chempound-webapp/src/main/resources/net/chempound/templates/include/layout.ftl

 <#-- @ftlvariable name="@" type="net.chempound.webapp.GlobalData" -->
+<#-- @ftlvariable name="" type="net.chempound.webapp.output.Page" -->
 <#macro basic
     title="Chempound Repository"
 >
 <#list STYLESHEETS as stylesheet>
     <link rel="stylesheet" href="${stylesheet}"/>
 </#list>
-<#if style??>
-    <style type="text/css">
-        ${style}
-    </style>
+<#if stylesheets??>
+<#list stylesheets as stylesheet>
+    <link rel="stylesheet" href="${stylesheet}"/>
+</#list>
 </#if>
 <#if headers??>
-<#assign headersTemplate = headers?interpret>
-<@headersTemplate />
+<#list headers as header>
+<#assign headerTemplate = header?interpret>
+<@headerTemplate />
+</#list>
 </#if>
 </head>
 

File chempound-webapp/src/main/resources/net/chempound/templates/splash.ftl

     title=title!uri
 >
 
-<#include template>
+<#include templatePath>
 
 </@layout.basic>