clang-uml
integrates inja template engine, with several additional functions which can be used in textual directives within the configuration files, notes and to generate links and tooltips in diagrams.
The following, are the clang-uml
additional template functions:
ltrim(string)
- left trims a stringrtrim(string)
- right trims a stringtrim(string)
- trims a stringsubstr(string, offset, length)
- returns a substring of a string from offset of lengthsplit(string)
- splits a string and returns a list of stringsreplace(string, regex, replacement)
- returns a string with replace matches to regex with replacement stringabbrv(string, length)
- returns a string truncated to length including trailing ellipsiselement(string)
- returns the entire JSON context a given diagram element, including the following properties:name
- name of the elementtype
- type of diagram element (e.g. class
, enum
, package
)namespace
- fully qualified element namespacefull_name
- fully qualified element namecomment
[optional] - elements comment, if anyalias
- internal diagram element alias (e.g. PlantUML alias)alias(string)
- returns a PlantUML alias of an C++ entity represented by string namecomment(string)
- returns a comment of an C++ entity represented by string nameTemplates allow complex postprocessing of the diagrams, for instance creation of customized PlantUML notes in the diagrams from comments in the code. Below is an example of using the above commands to generate notes in the PlantUML diagram from code comments (see also test case t00050):
Text available in the code comment blocks can be accessed in the templates depending on the selected comment parser.
Currently there are 2 available comment parsers:
plain
- defaultclang
- Clang's comment parserThey can be selected using comment_parser
config option.
This parser provides only 2 options to the Jinja context:
comment.raw
- raw comment text, including comment markers such as ///
or /**
comment.formatted
- formatted entire commentThis parser uses Clang comment parsing API to extract commands from the command:
comment.raw
- raw comment text, including comment markers such as ///
or /**
comment.formatted
- formatted entire commentcomment.<command>.<N>
- where command is the command used in the command e.g. brief
, todo
, etc. and N
is the index of the command in the array (each comment can have multiple instances of the same command such as \todo
)comment.text
- entire text of the comment that is not attached to any commandcomment.paragraph.<N>
- array of plain text paragraphs, for instance if you don't use \brief
commands but often provide brief description as first sentence of the comment separated with a new line from the rest of the comment