Repository navigation
AbstractTemplateSet
This is is a base abstract class for all template sets used by Radish.
If you would like to control whole process of creating documentation content, like using custom templates with own replacement rules and tags, you should inherit from AbstractTemplateSet, but in most cases customization of the documentation output (like changing CSS styles and markup, or adding custom tags to existing templates) can be done with overriding BasicTemplateSet methods or even with inheritance from one of SimpleTemplateSet or BootstrapTemplateSet classes.
Hierarchy of template sets classes in Radish library is:
┌─────────────────────┐
│ AbstractTemplateSet │
└─────────────────────┘
↑
│
┌─────────────────────┐
│ BasicTemplateSet │
└─────────────────────┘
↑ ↑
│ │
┌─────────────────────┐ ┌──────────────────────┐
│ SimpleTemplateSet │ │ BootstrapTemplateSet │
└─────────────────────┘ └──────────────────────┘
AbstractTemplateSet has only one method required to be implemented in descendants:
public abstract class AbstractTemplateSet
{
// ...
public abstract string Page { get; set; }
// ...
}The Page getter should return template for whole documentation page. Simpliest implementation of AbstractTemplateSet looks like:
public class CustomTemplateSet : AbstractTemplateSet
{
// overriding 'Page' template
public override string Page { get set; }
public CustomSimpliestTemplateSet() : base()
{
// set 'Page' template content
Page =
"<html><body>" +
"Hello world from Radish!" +
"</body></html>";
}
}This template set will produce static HTML page with a text:
Hello world from Radish!
In the example above we do not use any tags and replacement rules. Let's modify the code by adding a tag {{tag}} to the Page template and introduce a replacement rule that will replace the tag with a "Here was a tag" text:
public class CustomTemplateSet : AbstractTemplateSet
{
// overriding 'Page' template
public override string Page { get set; }
public CustomSimpliestTemplateSet() : base()
{
// set 'Page' template content with tag '{{tag}}'
Page =
"<html><body>" +
"Hello world from Radish!<br>" +
"{{tag}}" +
"</body></html>";
// adding replacement rule with handler 'MyRuleHandler'
this.AddRule(ts => ts.Page, "tag", MyRuleHandler);
}
// handler will be executed each time when Radish meets "{{tag}}" in the 'Page' template
private string MyRuleHandler(DocumentorContext context, params object[] parameters)
{
return "Here was a tag";
}
}And this will give us:
Hello world from Radish!
Here was a tag
Let's go deeper now and modify the rule handler in order to render something useful, for example, amount of REST API methods defined with Radish attributes. For these purposes each handler has DocumentorContext instance passed as first argument of the function:
Back to main page of the documentation.