info.bliki.wiki.template.extension.Allmacros Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bliki-core Show documentation
Show all versions of bliki-core Show documentation
This is the core project.
The newest version!
package info.bliki.wiki.template.extension;
import info.bliki.wiki.model.IWikiModel;
import info.bliki.wiki.template.AbstractTemplateFunction;
import info.bliki.wiki.template.ITemplateFunction;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* A template parser function for {{ #all_macros: ... }}
syntax.
* The function lists all available template functions documentation. To show
* the documentation of a function, the ITemplateFunction#getFunctionDoc() must
* be implemented.
*
* This function isn't included in the default parser functions map. Use
* Configuration.addTemplateFunction("#all_macros", Allmacros.CONST)
* to add the template to your configuration.
*/
public class Allmacros extends AbstractTemplateFunction {
public final static ITemplateFunction CONST = new Allmacros();
public Allmacros() {
}
@Override
public String getFunctionDoc() {
return "Returns all macros";
}
@Override
public String parseFunction(List parts, IWikiModel model, char[] src, int beginIndex, int endIndex, boolean isSubst) throws IOException {
Map t = model.getTemplateMap();
StringBuilder sb = new StringBuilder(16);
String doc;
sb.append("Template name Implemented in class Description ");
for (Map.Entry e : t.entrySet()) {
sb.append("");
sb.append(e.getKey());
sb.append(" ");
ITemplateFunction tf = e.getValue();
Class cl1 = tf.getClass().getEnclosingClass();
if (cl1 == null)
cl1 = tf.getClass();
String s1 = cl1.getCanonicalName();
sb.append(s1);
sb.append(" ");
doc = tf.getFunctionDoc();
if (doc == null) {
sb.append("No documentation available");
} else {
sb.append(doc);
}
sb.append(" ");
}
sb.append("
");
return sb.toString();
}
}