NIHVIVO-564 Modifications to directive help output. Included changing template directive iface to an abstract class that provides a default help() method and some utilities.
This commit is contained in:
parent
677dfb18d0
commit
5e8eb80732
7 changed files with 95 additions and 54 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.web.directives;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHelper;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.TemplateDirectiveModel;
|
||||||
|
|
||||||
|
public abstract class BaseTemplateDirectiveModel implements TemplateDirectiveModel {
|
||||||
|
|
||||||
|
public String help(Configuration config) {
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
String name = getDirectiveName();
|
||||||
|
map.put("name", name);
|
||||||
|
|
||||||
|
return mergeToTemplate(map, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getDirectiveName() {
|
||||||
|
String className = this.getClass().getName();
|
||||||
|
String[] nameParts = className.split("\\.");
|
||||||
|
String directiveName = nameParts[nameParts.length-1];
|
||||||
|
directiveName = directiveName.replaceAll("Directive$", "");
|
||||||
|
directiveName = directiveName.substring(0, 1).toLowerCase() + directiveName.substring(1);
|
||||||
|
return directiveName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String mergeToTemplate(Map<String, Object> map, Configuration config) {
|
||||||
|
return new FreemarkerHelper().mergeMapToTemplate("directive-help.ftl", map, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ import freemarker.template.TemplateModel;
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
import freemarker.template.utility.DeepUnwrap;
|
import freemarker.template.utility.DeepUnwrap;
|
||||||
|
|
||||||
public class DumpDataModelDirective implements VitroTemplateDirectiveModel {
|
public class DumpDataModelDirective extends BaseTemplateDirectiveModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DumpDataModelDirective.class);
|
private static final Log log = LogFactory.getLog(DumpDataModelDirective.class);
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ public class DumpDataModelDirective implements VitroTemplateDirectiveModel {
|
||||||
// Send the two lists of strings (variables and directives) to dump-datamodel.ftl.
|
// Send the two lists of strings (variables and directives) to dump-datamodel.ftl.
|
||||||
// That way, the directive dump won't be broken up into two pieces, for example.
|
// That way, the directive dump won't be broken up into two pieces, for example.
|
||||||
Object value = dm.get(var);
|
Object value = dm.get(var);
|
||||||
if (value instanceof VitroTemplateDirectiveModel) {
|
if (value instanceof BaseTemplateDirectiveModel) {
|
||||||
String help = ((VitroTemplateDirectiveModel) value).help(config);
|
String help = ((BaseTemplateDirectiveModel) value).help(config);
|
||||||
directives.put(var, help);
|
directives.put(var, help);
|
||||||
} else {
|
} else {
|
||||||
models.put(var, value);
|
models.put(var, value);
|
||||||
|
@ -92,15 +92,19 @@ public class DumpDataModelDirective implements VitroTemplateDirectiveModel {
|
||||||
@Override
|
@Override
|
||||||
public String help(Configuration config) {
|
public String help(Configuration config) {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
String name = getDirectiveName();
|
||||||
|
map.put("name", name);
|
||||||
|
|
||||||
map.put("usage", "Dump the contents of the template data model.");
|
map.put("usage", "Dump the contents of the template data model.");
|
||||||
|
|
||||||
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
||||||
|
|
||||||
List<String> examples = new ArrayList<String>();
|
List<String> examples = new ArrayList<String>();
|
||||||
examples.add("<@dumpDataModel />");
|
examples.add("<@" + name + " />");
|
||||||
map.put("examples", examples);
|
map.put("examples", examples);
|
||||||
|
|
||||||
return new FreemarkerHelper().mergeMapToTemplate("dump-directive-help.ftl", map, config);
|
return mergeToTemplate(map, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import freemarker.template.TemplateNumberModel;
|
||||||
import freemarker.template.TemplateScalarModel;
|
import freemarker.template.TemplateScalarModel;
|
||||||
import freemarker.template.TemplateSequenceModel;
|
import freemarker.template.TemplateSequenceModel;
|
||||||
|
|
||||||
public class DumpDirective implements VitroTemplateDirectiveModel {
|
public class DumpDirective extends BaseTemplateDirectiveModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DumpDirective.class);
|
private static final Log log = LogFactory.getLog(DumpDirective.class);
|
||||||
|
|
||||||
|
@ -116,6 +116,10 @@ public class DumpDirective implements VitroTemplateDirectiveModel {
|
||||||
|
|
||||||
public String help(Configuration config) {
|
public String help(Configuration config) {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
String name = getDirectiveName();
|
||||||
|
map.put("name", name);
|
||||||
|
|
||||||
map.put("usage", "Dump the contents of a template variable.");
|
map.put("usage", "Dump the contents of a template variable.");
|
||||||
|
|
||||||
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
||||||
|
@ -125,10 +129,10 @@ public class DumpDirective implements VitroTemplateDirectiveModel {
|
||||||
map.put("params", params);
|
map.put("params", params);
|
||||||
|
|
||||||
List<String> examples = new ArrayList<String>();
|
List<String> examples = new ArrayList<String>();
|
||||||
examples.add("<@dump var=\"urls\" />");
|
examples.add("<@" + name + " var=\"urls\" />");
|
||||||
map.put("examples", examples);
|
map.put("examples", examples);
|
||||||
|
|
||||||
return new FreemarkerHelper().mergeMapToTemplate("dump-directive-help.ftl", map, config);
|
return mergeToTemplate(map, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.directives;
|
|
||||||
|
|
||||||
import freemarker.template.Configuration;
|
|
||||||
import freemarker.template.TemplateDirectiveModel;
|
|
||||||
|
|
||||||
public interface VitroTemplateDirectiveModel extends TemplateDirectiveModel {
|
|
||||||
|
|
||||||
public String help(Configuration config);
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Template for displaying directive help -->
|
||||||
|
|
||||||
|
<div class="dump directive">
|
||||||
|
<p><strong>Directive name:</strong> ${name}</p>
|
||||||
|
|
||||||
|
<#if usage??>
|
||||||
|
<p><strong>Usage:</strong> ${usage}</p>
|
||||||
|
|
||||||
|
<#if comments??>
|
||||||
|
<p><strong>Comments:</strong> ${comments}</p>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<h6>Parameters:</h6>
|
||||||
|
<#if params?? && params?keys?has_content>
|
||||||
|
<ul>
|
||||||
|
<#list params?keys as param>
|
||||||
|
<li><strong>${param}:</strong> ${params[param]}</li>
|
||||||
|
</#list>
|
||||||
|
</ul>
|
||||||
|
<#else>
|
||||||
|
<p>none</p>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<h6>Examples:</h6>
|
||||||
|
<#if examples??>
|
||||||
|
<ul>
|
||||||
|
<#list examples as example>
|
||||||
|
<li>${example}</li>
|
||||||
|
</#list>
|
||||||
|
</ul>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#else>
|
||||||
|
<p>No help available for this directive.</p>
|
||||||
|
</#if>
|
||||||
|
</div>
|
|
@ -15,12 +15,10 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h4>DIRECTIVES</h4>
|
<h4>DIRECTIVES</h4>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<#list directives?keys as directive>
|
<#list directives?keys as directive>
|
||||||
<li class="dump directive">
|
<li>${directives[directive]}</li>
|
||||||
<p><strong>Directive name:</strong> ${directive}</p>
|
|
||||||
${directives[directive]!"no help available for this directive"}
|
|
||||||
</li>
|
|
||||||
</#list>
|
</#list>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
|
||||||
|
|
||||||
<#-- Template for dumping directive help -->
|
|
||||||
|
|
||||||
<p><strong>Usage:</strong> ${usage!}</p>
|
|
||||||
|
|
||||||
<#if comments??>
|
|
||||||
<p><strong>Comments:</strong> ${comments}</p>
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
<h6>Parameters:</h6>
|
|
||||||
<#if params?? && params?keys?has_content>
|
|
||||||
<ul>
|
|
||||||
<#list params?keys as param>
|
|
||||||
<li><strong>${param}:</strong> ${params[param]}</li>
|
|
||||||
</#list>
|
|
||||||
</ul>
|
|
||||||
<#else>
|
|
||||||
<p>none</p>
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
<h6>Examples:</h6>
|
|
||||||
<#if examples??>
|
|
||||||
<ul>
|
|
||||||
<#list examples as example>
|
|
||||||
<li>${example}</li>
|
|
||||||
</#list>
|
|
||||||
</ul>
|
|
||||||
</#if>
|
|
Loading…
Add table
Add a link
Reference in a new issue