TemplateModel tm = nameExp.getAsTemplateModel(env);
if (tm == Macro.DO_NOTHING_MACRO) return; // shortcut here.
if (tm instanceof Macro) {
Macro macro = (Macro) tm;
if (macro.isFunction()) {
throw new TemplateException("Routine " + macro.getName()
+ " is a function. A function can only be called " +
"within the evaluation of an expression.", env);
}
env.render(macro, args, bodyParameters, nestedBlock);
}
else if (tm instanceof TemplateDirectiveModel) {
Map<String, TemplateModel> argMap
= args != null
? args.getParameterMap(tm, env)
: new HashMap<String, TemplateModel>();
List<String> paramNames;
if(bodyParameters == null) {
paramNames = Collections.emptyList();
}
else {
paramNames = bodyParameters.getParamNames();
}
env.render(nestedBlock, (TemplateDirectiveModel) tm, argMap, paramNames);
}
else if (tm instanceof TemplateTransformModel) {
Map<String, TemplateModel> argMap
= args != null
? args.getParameterMap(tm, env)
: new HashMap<String, TemplateModel>();
env.render(nestedBlock, (TemplateTransformModel) tm, argMap);
}
else {
assertNonNull(tm, nameExp, env);
throw new TemplateException(getStartLocation() + ": " + nameExp +
" is not a user-defined directive.", env);
}
}