key concepts - AlexanderKrutov/Radish GitHub Wiki

To create documentation page, Radish uses own simple but extensible template engine, based on four concepts:

Template, Tag, Replacement Rule and Template Set.

Template Set

Template Set is a combination of Templates, Tags and Replacement Rules. In the source code template set is represented by a class inherited from AbstractTemplateSet or its descendants:

// this is a template set
public class CustomTemplateSet : AbstractTemplateSet { ... }

// this is also template set
public class AnotherCustomTemplateSet : BasicTemplateSet { ... }

// and this is too
public class ThirdCustomTemplateSet : SimpleTemplateSet { ... }

Template should contain at least one template (Page from AbstractTemplateSet).

Template

Template is a HTML page (or part) with regular HTML markup, embedded CSS or/and JavaScript and special metatags, or just Tags. In the source code, template is a string property of a template set class:

public class CustomTemplateSet : AbstractTemplateSet 
{ 
    // this is template
    public string CustomTemplate { get; set; }
}

Value of the property is a HTML content of the template. Usually content is set in the template set constructor. You can use embedded text resources or files to store content of templates.

Tag

Tag is a string wrapped with double curly braces:

{{tag}} — this is a tag;
{{i-am-tag-too}} — this is also a tag.

Tag is a part of a template content.

Replacement Rule

Replacement Rule is a logical construction for replacement some Tag into valid HTML content according to optionally passed parameters. Replacement rules are defined in template set class (usually in constructor) like:

this.AddRule<CustomTemplateSet>(ts => ts.CustomTemplate, "tag", Rule_Handler);

Here we have just defined a rule for tag {{tag}} of template CustomTemplate. Rule_Handler is a Rule Handler function that will be called by Radish when it meets {{tag}} inside the template CustomTemplate.

Signature of a rule handler is:

string Rule_Handler(DocumentorContext context, params object[] parameters) { ... }

First argument is a DocumentorContext instance (needed for access to REST API methods list and its attributes) and other parameters are optional and can be passed in the handler from an outer rule handler. The rule handler function contains some logic of replacement and returns a string that will be placed instead of the tag.

⚠️ **GitHub.com Fallback** ⚠️