Anonymous avatar Anonymous committed 6da90e9

Refactoring templates in preparation for supporting alternative skins

Comments (0)

Files changed (12)

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

         model.put("templatePath", templatePath);
         model.put("headers", headers);
         model.put("stylesheets", stylesheets);
+        model.put("_", this);
         return model;
     }
 }

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

 import com.hp.hpl.jena.rdf.model.Resource;
 import com.hp.hpl.jena.rdf.model.ResourceFactory;
 import com.hp.hpl.jena.vocabulary.RDF;
+import freemarker.core.Macro;
 import freemarker.template.Template;
 import net.chempound.datastore.TripleStore;
 import net.chempound.rdf.CPTerms;
         final Page page = new Page(aggregationUri);
         writer.write(model, aggregationUri, page);
 
-        final Template template = freemarker.getTemplate("splash.ftl");
+        final Template template = freemarker.getTemplate(page.getTemplatePath());
         return new TemplateRepresentation(template, page.getModel(), MediaType.TEXT_HTML);
     }
 

chempound-webapp/src/main/resources/net/chempound/templates/default/collection.ftl

+<@layout.css>/css/crystal/crystal.css</@layout.css>
+<@layout.header><!-- test --></@layout.header>
+<@layout.page>
 <div class="collection">
 <#if title??><h1 class="title">${title}</h1></#if>
 <#list aggregation.aggregatedResources as resource>
     <@macro.snippet items[resource.uri] />
     </div>
 </#list>
-</div>
+</div>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/feed-index.ftl

-<@layout.basic
+<@layout.page
     title="Atom Feeds"
 >
 
 
 </#list>
 
-</@layout.basic>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/include/default-skin.ftl

+<!DOCTYPE html>
+<html>
+<head>
+    <title>${title}</title>
+<#list STYLESHEETS as stylesheet>
+    <link rel="stylesheet" href="${stylesheet}"/>
+</#list>
+<#if stylesheets?has_content>
+    <#list stylesheets as stylesheet>
+        <link rel="stylesheet" href="${stylesheet}"/>
+    </#list>
+</#if>
+<#if headers?has_content>
+    <#list headers as header>
+        <#assign headerTemplate = header?interpret>
+        <@headerTemplate />
+    </#list>
+</#if>
+</head>
+
+<body>
+
+<header>
+    <div class="content">
+        <h1>${@.data.title}</h1>
+    </div>
+</header>
+
+<nav>
+    <div class="content">
+        <ul>
+            <li><a href="${URI_BASE}/" class="first">Home</a></li>
+            <li><a href="${URI_BASE}/content/">Browse</a></li>
+            <li><a href="${URI_BASE}/search/">Search</a></li>
+            <li><a href="${URI_BASE}/sparql/">SPARQL</a></li>
+            <li><a href="${URI_BASE}/feeds/">Feeds</a></li>
+        </ul>
+        <div class="clear"></div>
+    </div>
+</nav>
+
+<article>
+    <div class="content">
+
+    ${content}
+
+    <!-- content ends -->
+    </div>
+</article>
+
+<footer>
+    <p></p>
+</footer>
+
+<#if @.data.googleAnalyticsId??>
+<!-- change the UA-XXXXX-X to be your site's ID -->
+<script>
+    var _gaq = [['_setAccount', '${@.data.googleAnalyticsId}'], ['_trackPageview']];
+    (function(d, t) {
+        var g = d.createElement(t),
+                s = d.getElementsByTagName(t)[0];
+        g.async = true;
+        g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+        s.parentNode.insertBefore(g, s);
+    })(document, 'script');
+</script>
+</#if>
+
+</body>
+</html>

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"
+<#-- @ftlvariable name="_" type="net.chempound.webapp.output.Page" -->
+
+<#macro css><#local path><#nested/></#local>${_.addStylesheet(path)}</#macro>
+<#macro header><#local header><#nested/></#local>${_.addHeader(header)}</#macro>
+
+<#macro page
+title="Chempound Repository"
 >
-<!DOCTYPE html>
-<html>
-<head>
-    <title>${title}</title>
-<#list STYLESHEETS as stylesheet>
-    <link rel="stylesheet" href="${stylesheet}"/>
-</#list>
-<#if stylesheets?has_content>
-<#list stylesheets as stylesheet>
-    <link rel="stylesheet" href="${stylesheet}"/>
-</#list>
-</#if>
-<#if headers?has_content>
-<#list headers as header>
-<#assign headerTemplate = header?interpret>
-<@headerTemplate />
-</#list>
-</#if>
-</head>
-
-<body>
-
-<header>
-    <div class="content">
-        <h1>${@.data.title}</h1>
-    </div>
-</header>
-
-<nav>
-    <div class="content">
-        <ul>
-            <li><a href="${URI_BASE}/" class="first">Home</a></li>
-            <li><a href="${URI_BASE}/content/">Browse</a></li>
-            <li><a href="${URI_BASE}/search/">Search</a></li>
-            <li><a href="${URI_BASE}/sparql/">SPARQL</a></li>
-            <li><a href="${URI_BASE}/feeds/">Feeds</a></li>
-        </ul>
-<#--
-        <ul style="float: right">
-            <li><a href="${URI_BASE}/help/" class="first">Help</a></li>
-        </ul>
--->
-        <div class="clear"></div>
-    </div>
-</nav>
-
-<article>
-    <div class="content">
-
-<#escape x as x?html>
-<#nested>
-</#escape>
-
-<!-- content ends -->
-
-    </div>
-</article>
-
-<footer>
-    <p></p>
-</footer>
-
-<#if @.data.googleAnalyticsId??>
-<!-- change the UA-XXXXX-X to be your site's ID -->
-<script>
-var _gaq = [['_setAccount', '${@.data.googleAnalyticsId}'], ['_trackPageview']];
-(function(d, t) {
-    var g = d.createElement(t),
-        s = d.getElementsByTagName(t)[0];
-    g.async = true;
-    g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-    s.parentNode.insertBefore(g, s);
-})(document, 'script');
-</script>
-</#if>
-
-</body>
-</html>
+<#local content><#nested/></#local>
+<#include "default-skin.ftl"/>
 </#macro>

chempound-webapp/src/main/resources/net/chempound/templates/index.ftl

 <#-- @ftlvariable name="@" type="net.chempound.webapp.GlobalData" -->
-<@layout.basic>
+<@layout.page>
 
 <h1>${@.data.frontPageTitle}</h1>
 
 </div>
 </#list>
 
-</@layout.basic>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/search-form.ftl

-<@layout.basic
+<@layout.page
     title="Search"
 >
 
 	});
 </script>
 
-</@layout.basic>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/search-result.ftl

-<@layout.basic
+<@layout.page
     title="Search Results"
 >
 
     </div>
 </#list>
 
-</@layout.basic>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/sparql-form.ftl

-<@layout.basic
+<@layout.page
     title="SPARQL Query"
 >
 
     </p>
 </form>
 
-</@layout.basic>
+</@layout.page>

chempound-webapp/src/main/resources/net/chempound/templates/sparql-result.ftl

 <#-- @ftlvariable name="results" type="com.hp.hpl.jena.query.ResultSet" -->
-<@layout.basic
+<@layout.page
     title="SPARQL Query Results"
 >
 
 </#list>
 </table>
 
-</@layout.basic>
+</@layout.page>

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

 <#-- @ftlvariable name="aggregation" type="net.chempound.rdf.chempound.ChempoundAggregation" -->
-<@layout.basic
+<@layout.page
     title=title!uri
 >
 
 <#include templatePath>
 
-</@layout.basic>
+</@layout.page>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.