-
-
Notifications
You must be signed in to change notification settings - Fork 1
Typal Methods
With Typal, a package that facilitates management of types in external files, methods are defined using XML schema. Documentary works together with Typal to embed the descriptions of methods into the documentation.
Keeping types in a separate file not only allows to embed them into documentation, but also into the source code using Typal's template feature. This is needed when packages are compiled using Closure Compiler, and the JSDoc annotations are lost after compilation. Using the templates and information about methods, it becomes possible to restore editor run-time JSDoc for package consumers.
For example, a method can be defined in the following way:
<types ns="_namespace">
<method async name="runSoftware" return="string">
<arg string name="path">The path to the file.</arg>
<arg opt type="_namespace.Config" name="config">
The configuration object.
</arg>
This function will run the software, and return results.
</method>
<type name="Config" desc="The config for the program.">
<prop name="View" type="Container">
The view component connected to the store.
</prop>
<prop name="actions" type="Object">
Possible actions for the reducer.
</prop>
<prop boolean name="static" opt>
Whether to render the page as HTML file.
</prop>
<fn name="render" return="string">
<arg name="component" type="Container">
The JSX component to render.
</arg>
The renderning function.
</fn>
</type>
</types>
And it can be placed into the source code using the <typedef>
component:
<typedef narrow level="3">wiki/Typal-Methods/api.xml</typedef>
The types found inside of the XML file(s) will be linked across the full compiled documentation, either a single README file, or multiple Wiki pages.
Example Of Method Embed | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
This function will run the software, and return results.
|
There are some properties that can be passed to the typedef
component:
- noArgTypesInToc: Don't print types of arguments in the table of contents.
- slimFunctions: Don't print arguments' description and types in the types' tables.
The same type can be placed into the source code by creating a template.
The template uses the @methodType marker to indicate the type of the method. |
const _runSoftware = require('./depack')
/**
* @methodType {_namespace.runSoftware}
*/
function runSoftware() {
} |
Typal then parses the types file, and updates the template to place annotations into the compiled file.
Command used: typal template.js -T output.js -t api.xml .
|
const _runSoftware = require('./depack')
/**
* This function will run the software, and return results.
* @param {string} path The path to the file.
* @param {_namespace.Config=} [config] The configuration object.
* @return {Promise<string>}
*/
function runSoftware() {
} |
To provide custom designs of headings for methods, follow this guide.
TODO: implement custom designs of descriptions and tables.