diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java index ec127a265..5f028ceaf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java @@ -50,8 +50,13 @@ public class DumpHelper { TemplateModel tm = null; try { tm = dataModel.get(varName); - } catch (TemplateModelException tme) { - log.error("Error getting value of template model " + varName + " from data model."); + } catch (TemplateModelException e) { + log.error("Error getting value of template model '" + varName + "' from data model."); + return null; + } + + if (tm == null) { + log.error("No variable '" + varName + "' defined in data model." ); return null; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/HelpDirective.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/HelpDirective.java index 93fcadea5..04ad7af0c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/HelpDirective.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/HelpDirective.java @@ -12,8 +12,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.web.directives.BaseTemplateDirectiveModel; +import edu.cornell.mannlib.vitro.webapp.web.methods.BaseTemplateMethodModel; import freemarker.core.Environment; -import freemarker.template.Configuration; import freemarker.template.SimpleScalar; import freemarker.template.TemplateDirectiveBody; import freemarker.template.TemplateException; @@ -40,27 +40,44 @@ public class HelpDirective extends BaseTemplateDirectiveModel { "The help directive doesn't allow nested content."); } - Object o = params.get("directive"); + Object o = params.get("for"); + + if ( o == null) { + throw new TemplateModelException( + "Must specify 'for' argument."); + } + if ( !(o instanceof SimpleScalar)) { throw new TemplateModelException( - "Value of parameter 'directive' must be a string."); - } + "Value of parameter 'for' must be a string."); + } - String directiveName = ((SimpleScalar)o).getAsString(); + String name = ((SimpleScalar)o).getAsString(); TemplateHashModel dataModel = env.getDataModel(); Map dm = (Map) DeepUnwrap.permissiveUnwrap(dataModel); - Object value = dm.get(directiveName); + Object value = dm.get(name); - if (! (value instanceof BaseTemplateDirectiveModel) ) { + if (value == null) { throw new TemplateModelException( - directiveName + " must be the name of a directive."); + "Value of parameter '" + name + "' must be the name of a directive or method"); } - - Configuration config = env.getConfiguration(); - Map map = new HashMap(); - - String help = ((BaseTemplateDirectiveModel) value).help(directiveName, env); + + String help; + String type; + if (value instanceof BaseTemplateDirectiveModel) { + help = ((BaseTemplateDirectiveModel) value).help(name, env); + type = "directive"; + } else if (value instanceof BaseTemplateMethodModel) { + help = ((BaseTemplateMethodModel) value).help(name, env); + type = "method"; + } else { + throw new TemplateModelException( + "Value of parameter '" + name + "' must be the name of a directive or method"); + } + + Map map = new HashMap(); map.put("help", help); + map.put("type", type); try { map.put("stylesheets", dataModel.get("stylesheets")); @@ -69,25 +86,25 @@ public class HelpDirective extends BaseTemplateDirectiveModel { } DumpHelper helper = new DumpHelper(env); - helper.writeDump("help.ftl", map, directiveName); + helper.writeDump("help.ftl", map, name); } - + @Override public String help(String name, Environment env) { Map map = new HashMap(); - + map.put("name", name); - map.put("effect", "Output help for directive or method."); + map.put("effect", "Output help for a directive or method."); Map params = new HashMap(); - params.put("var", "name of directive/method"); + params.put("for", "name of directive or method"); map.put("params", params); List examples = new ArrayList(); - examples.add("<@" + name + " directive=\"dump\" />"); - examples.add("<@" + name + " method=\"profileUrl\" />"); + examples.add("<@" + name + " for=\"dump\" />"); + examples.add("<@" + name + " for=\"profileUrl\" />"); map.put("examples", examples); return mergeToHelpTemplate(map, env); diff --git a/webapp/web/templates/freemarker/body/partials/dump/help.ftl b/webapp/web/templates/freemarker/body/partials/dump/help.ftl index 1e8c13b76..9594bc751 100644 --- a/webapp/web/templates/freemarker/body/partials/dump/help.ftl +++ b/webapp/web/templates/freemarker/body/partials/dump/help.ftl @@ -1,9 +1,9 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> -<#-- Template for displaying directive help --> +<#-- Template for displaying help for a template directive or method -->
-

Template directive help

+

Template ${type} help

${help}
diff --git a/webapp/web/templates/freemarker/body/samples.ftl b/webapp/web/templates/freemarker/body/samples.ftl index abb444bbb..9e8ae4989 100644 --- a/webapp/web/templates/freemarker/body/samples.ftl +++ b/webapp/web/templates/freemarker/body/samples.ftl @@ -133,14 +133,12 @@ ${stylesheets.addFromTheme("/css/sstest.css", "/css/sstest2.css")} ${scripts.addFromTheme("/js/jstest.js")} ${scripts.add("/js/script1.js", "/js/script2.js", "/js/script3.js")} - <@dumpAll /> -<@help directive="dump" /> +<@help for="dump" /> + +<@help for="profileUrl" /> <@describe var="stylesheets" /> -<@describe var="scripts" /> - -<@describe var="headScripts" />