Skip to content

BasicTemplateSet

Alexander Krutov edited this page Jul 3, 2015 · 15 revisions

Note: It's recommended to familiarize with key concepts before reading this article.

Designation

This is a base class for two predefined template sets used by Radish: SimpleTemplateSet and BootstrapTemplateSet.

The BasicTemplateSet class is needed as a layer because two template sets use the same templating logic, including common tags, replacement rules and template names. The difference between template sets is only in appearance of output content.

If you want to create your own template set to display documentation with custom styles and formatting, without changing logic of templates, you should inherit from BasicTemplateSet.

Templates and Tags

Below is a comprehensive information about templates and their tags defined in BasicTemplateSet (and therefore in two descendant template sets).

Page

Template for whole documentation page. Inherited from AbstractTemplateSet. Tags:

  • {{title}} — title of the documentation page. Will be displayed at the top of the documentation page. To set the title, please use a Title property of BasicTemplateSet
  • {{methods-list}} — list of REST API methods. Will be replaced by rendering results of Method template
  • {{json-methods-list}} — will be replaced by JSON object that contains info about REST API methods. Used for navigation and for searching by methods.
MethodsGroup

Template for displaying information about group of methods. There are two tags defined:

  • {{title}} — for displaying group's title
  • {{description}} — for displaying group's description
Method

Template for displaying information about particular REST API method.

Replacements of following four tags are taken from the values of appropriate properties of MethodAttribute:

  • {{method}} — prints REST API method type defined by MethodAttribute.MethodType, like GET, POST, PUT and etc.
  • {{id}} — prints unique id of a method defined by MethodAttribute.Id
  • {{title}} — prints method title defined by MethodAttribute.Title
  • {{description}} — prints a method description defined by MethodAttribute.Description

Other tags will be replaced by otputs of nested templates:

RequestParametersList

Template for rendering header and a table of request parameters of the method. Header of the table is a text: Request Parameters;. Only one tag is defined:

  • {{request-parameters-list}} — prints the table itself
RequestParameter

Displays particular row from the table of parameters. Information for each row is taken from RequestParameterAttribute. Tags are:

  • {{name}} — prints name of the request parameter as defined by RequestParameterAttribute.Name value
  • {{type}} — prints type of the parameter as defined by RequestParameterAttribute.Type value
  • {{required}} — prints True or False word depend on value of RequestParameterAttribute.Required
  • {{description}} — prints description of the parameter as defined by RequestParameterAttribute.Description value
RequestBodyDescription

Used for displaying documentation section that contains description of the request body. Section has header text: Request. Only one tag is defined:

  • {{description}} — prints the description of the request body
RequestBodyExample

Template for documentation section with an example of REST API method request body. Has title Request example at the top. Uses tags:

  • {{data}} — prints request body data itself, in JSON, XML or raw text form, as defined by RequestBodyExampleAttribute.Data value
  • {{data-format}} — prints request body data format type (Json, Xml or Raw) string depend on RequestBodyExampleAttribute.Format value
  • {{id}} — prints REST API method unique key
ResponseBodyDescription

Used for displaying documentation section that contains description of the response body. Section has header text: Response. Only one tag is defined:

  • {{description}} — prints the description of the response body
ResponseBodyExample

Template for documentation section with an example of REST API method response body. Has title Response example at the top. Uses tags:

  • {{data}} — prints response body data itself, in JSON, XML or raw text form, as defined by ResponseBodyExampleAttribute.Data value
  • {{data-format}} — prints response body data format type (Json, Xml or Raw) string depend on ResponseBodyExampleAttribute.Format value
  • {{id}} — prints REST API method unique key
ResponseCodesList

Template for rendering header and a list of HTTP status codes of the method. Header of the table is a text: Response Codes;. Only one tag is defined:

  • {{response-codes-list}} — prints the list itself
ResponseCode

Displays particular item from the list of response codes. Information for each item is taken from ResponseCodeAttribute. Tags are:

  • {{code}} — prints the HTTP status code as defined by ResponseCodeAttribute.Code value
  • {{description}} — — prints the explanation of HTTP status code as defined by ResponseCodeAttribute.Description value

Summary

To summarize this article, here is a tree of nesting levels of the templates and related tags that were described above. Repeatable sections are marked with * symbol:

Page
├─ Title
├─ MethodsGroup
│  ├─ {{title}}
│  └─ {{description}}
└─ Method*
   ├─ {{method}}
   ├─ {{id}}
   ├─ {{title}}
   ├─ {{description}}
   ├─ RequestParametersList 
   │  └─ RequestParameter*
   │     ├─ {{name}} 
   │     ├─ {{type}}
   │     ├─ {{required}}
   │     └─ {{description}}                      
   ├─ RequestBodyDescription
   │  └─ {{description}}
   ├─ RequestBodyExample
   │  ├─ {{data}}
   │  ├─ {{data-format}}
   │  └─ {{id}}
   ├─ ResponseBodyDescription
   │  └─ {{description}}
   ├─ ResponseBodyExample
   │  ├─ {{data}}
   │  ├─ {{data-format}}
   │  └─ {{id}}
   └─ ResponseCodesList
	  └─ ResponseCode*
		 ├─ {{code}}
		 └─ {{description}}

Clone this wiki locally