-
Notifications
You must be signed in to change notification settings - Fork 3
06 Functions
github-actions[bot] edited this page May 31, 2025
·
8 revisions
A function is a piece of dart code that performs a specific task. So a function can basically do anything that dart code can do.
A function can be used anywhere in an tag expression. Wherever that particular task should be performed.
An example of a function call: cos(pi) Should result in: -1
Function & Parameter & argument names:
- are case sensitive
- must start with a lower case letter, optionally followed by (lower or upper case) letters and or digits.
- conventions: use lowerCamelCase
- must be unique and does not match a other tag syntax
Parameters vs Arguments
- Parameters are the names used in the function definition.
- Arguments are the actual values passed when calling the function.
Parameters:
- A function can have zero or more parameters
- Parameters are defined as either mandatory or optional
- Optional parameters can have a default value
Arguments:
- Multiple arguments are separated with a comma, e.g. single argument:
cos(pi)
multiple arguments:volume(10,20,30)
- There are different types of arguments
- Positional Arguments: These are passed in the order the function defines them. e.g.:
volume(10, 20, 30)
- Named Arguments: You can specify which parameter you're assigning a value to, regardless of order. e.g.:
volume(l=30, h=10, w=20)
- Positional Arguments: These are passed in the order the function defines them. e.g.:
- Arguments can set a parameter only once
- You can mix positional arguments and named arguments, but positional arguments must come first
- Named arguments remove ambiguity: If you want to skip an optional argument or specify one out of order, you must name it explicitly
Argument values:
- must match the expected parameter type. e.g.
area(length='hello', width='world')
will result in a failure - may be a tag expression such as a variable, constant, operation, function, or combination. e.g.
cos(2*pi)
You can use prepackaged [template_engine] functions or add your own custom functions by manipulating the TemplateEngine.functionGroups field.
See Example.
description: | Imports, parses and renders a template file | |||
return type: | IntermediateRenderResult | |||
expression example: | {{importTemplate('test/src/parser/tag/expression/function/import/to_import.md.template')}} | |||
code example: | import_template_test.dart | |||
parameter: | source | String | mandatory | The project path of the template file |
description: | Imports a file as is (without parsing and rendering) | |||
return type: | String | |||
expression example: | {{importPure('test/src/template_engine_template_example_test.dart')}} | |||
code example: | import_pure_test.dart | |||
parameter: | source | String | mandatory | The project path of the file. This path can be a absolute or relative file path or URI. |
description: | A markdown code block that imports a code file. | |||
return type: | Object | |||
expression example: | {{importCode('test/src/template_engine_template_example_test.dart')}} | |||
parameter: | source | String | mandatory | The project path of the code file to importThis path can be a absolute or relative file path or URI. |
parameter: | language | String | optional (default="") | You can specify the language to optimize syntax highlighting, e.g. html, dart, ruby |
parameter: | sourceHeader | boolean | optional (default=true) | Adds the source path as a header |
description: | A markdown code block that imports a dart code file. | |||
return type: | Object | |||
expression example: | {{importDartCode('test/src/template_engine_template_example_test.dart')}} | |||
parameter: | source | String | mandatory | The project path of the dart code file to import.This path can be a absolute or relative file path or URI. |
parameter: | sourceHeader | boolean | optional (default=true) | Adds the source path as a header |
description: | A markdown code block that imports dat documentation comments for a given library member from a dart code file.:
|
|||
return type: | Object | |||
expression example: | {{ImportDartDoc('test/src/template_engine_template_example_test.dart')}} | |||
parameter: | source | String | mandatory | A reference to a piece of your Dart source code.
This could be anything from a whole dart file to one of its members.
Format: <DartFilePath>#<DartMemberPath>
Examples:
|
description: | Imports a JSON file and decode it to a Map, which could be assigned it to a variable. | |||
return type: | Map | |||
expression example: | {{json=importJson('test/src/parser/tag/expression/function/import/person.json')}}{{json.person.child.name}} | |||
code example: | import_json_test.dart | |||
parameter: | source | String | mandatory | The project path of the JSON file. This path can be a absolute or relative file path or URI. |
description: | Imports a XML file and decode it to a Map, which could be assigned it to a variable. | |||
return type: | Map | |||
expression example: | {{xml=importXml('test/src/parser/tag/expression/function/import/person.xml')}}{{xml.person.child.name}} | |||
code example: | import_xml_test.dart | |||
parameter: | source | String | mandatory | The project path of the XML file. This path can be a absolute or relative file path or URI. |
description: | Imports a YAML file and decode it to a Map, which could be assigned it to a variable. | |||
return type: | Map | |||
expression example: | {{yaml=importYaml('test/src/parser/tag/expression/function/import/person.yaml')}}{{yaml.person.child.name}} | |||
code example: | import_yaml_test.dart | |||
parameter: | source | String | mandatory | The project path of the YAML file. This path can be a absolute or relative file path or URI. |
description: | Creates a license text for the given type, year and copyright holder | |||
return type: | String | |||
expression example: | {{ license(type='type value', name='name value') }} | |||
parameter: | type | String | mandatory | Type of license, currently supported: MIT, BSD3 |
parameter: | name | String | mandatory | Name of the copyright holder |
parameter: | year | int | optional | Year of the copyright. It wil use the current year if not defined |
description: | Markdown table of content with links to all markdown chapters (e.g. # chapter, ## paragraph, ## sub paragraph) of a template file or all template files in a folder. | |||
return type: | Object | |||
expression example: | {{ tableOfContents('path value') }} | |||
parameter: | path | String | mandatory | A relative project path (always with slash forward) to a template file (e.g.: doc/template/README.md.template) or a folder with template files (e.g.: doc/template/doc/wiki) |
parameter: | includeFileLink | boolean | optional (default=true) | If the title links should be preceded with a link to the file |
parameter: | gitHubWiki | boolean | optional (default=false) | Will remove the .md extension from the links so that they work correctly inside gitHub wiki pages |
description: | A markdown text of milestones on GitHub. You could use this for the CHANGELOG.md file. | |||
return type: | Object | |||
expression example: | {{gitHubMileStones('test/src/template_engine_template_example_test.dart')}} | |||
parameter: | state | String | optional (default="all") | The state of the milestones, either: open, closed, all |
description: | Gives the relative path of the current template | |||
return type: | String | |||
expression example: | {{templateSource()}} | |||
code example: | template_test.dart |
description: | Returns the path of the template file being used. Prefer to use this function over the 'templateSource' because 'inputPath' always resolves to a path | |||
return type: | String | |||
expression example: | {{inputPath()}} should render: doc/example.md |
description: | Returns the path of the file being created from the template | |||
return type: | String | |||
expression example: | {{outputPath()}} should render: doc/example.md |
description: | Returns a URI of Creates a uri from an address. | |||
return type: | Uri | |||
expression example: | {{ referenceUri(???) }} | |||
parameter: | ref | dynamic | mandatory | The ref (reference) can be:
|
description: | Returns a URI of a web page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a wiki page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubWikiUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a stars page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubStarsUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of an issue page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubIssuesUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a milestone page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubMilestonesUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a releases page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubReleasesUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a pull request page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubPullRequestsUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of a raw code page of your project on github.com | |||
return type: | Uri | |||
expression example: | {{ gitHubRawUri('suffix value') }} | |||
parameter: | suffix | String | mandatory | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the home page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the change log page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevChangeLogUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the version page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevVersionsUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the example page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevExampleUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the install page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevInstallUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the score page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevScoreUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a URI of the license page of your project on pub.dev | |||
return type: | Uri | |||
expression example: | {{ pubDevLicenseUri() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
description: | Returns a markdown hyperlink of Creates a uri from an address. | |||
return type: | MarkDownLink | |||
expression example: | {{ referenceLink(???) }} | |||
parameter: | ref | dynamic | mandatory | The ref (reference) can be:
|
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a web page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a wiki page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubWikiLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a stars page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubStarsLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of an issue page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubIssuesLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a milestone page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubMilestonesLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a releases page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubReleasesLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a pull request page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubPullRequestsLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of a raw code page of your project on github.com | |||
return type: | MarkDownLink | |||
expression example: | {{ gitHubRawLink('suffix value') }} | |||
parameter: | suffix | String | mandatory | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the home page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the change log page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevChangeLogLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the version page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevVersionsLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the example page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevExampleLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the install page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevInstallLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the score page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevScoreLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Returns a markdown hyperlink of the license page of your project on pub.dev | |||
return type: | MarkDownLink | |||
expression example: | {{ pubDevLicenseLink() }} | |||
parameter: | suffix | String | optional | A suffix to append to the URI (e.g. path, query, fragment, etc) |
parameter: | text | String | optional | The text of the hyperlink. An appropriate text will be provided if no text is defined |
description: | Creates markdown for a customizable badge image | |||
return type: | String | |||
expression example: | {{customBadge(tooltip='GitHub License' label='license' message='MIT' link='https://github.com/domain-centric/documentation_builder/blob/main/LICENSE')}} should render: [](https://github.com/domain-centric/documentation_builder/blob/main/LICENSE) | |||
parameter: | toolTip | String | optional | This text becomes visible when hoovering over a badge |
parameter: | label | String | mandatory | The label is the left text of the badge and is often lower case text |
parameter: | message | String | mandatory | The label is the left message is the right text of the badge and can have a fill color |
parameter: | color | String | optional (default="informational") | The message is the right text of the [Badge] and can have fill color.
The color can be defined in different ways:
As color name:
|
parameter: | link | String | mandatory | A Uri that points to a web site page. |
description: | Creates markdown for a badge of an existing Dart or Flutter package on pub.dev | |||
return type: | String | |||
expression example: | {{ pubPackageBadge() }} should render: [](https://pub.dev/packages/documentation_builder) | |||
parameter: | toolTip | String | optional (default="Pub Package") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge of the scores on pub.dev | |||
return type: | String | |||
expression example: | {{ pubScoresBadge() }} should render: [ | |||
parameter: | toolTip | String | optional (default="Pub Scores") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for all pub.dev badges | |||
return type: | Object | |||
expression example: | {{ allPubBadges() }} |
description: | Creates markdown for a badge of a project on github.com | |||
return type: | Object | |||
expression example: | {{ gitHubBadge() }} should render: [](https://github.com/domain-centric/documentation_builder) | |||
parameter: | toolTip | String | optional (default="Project on github.com") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge of the Wiki pages of a project on GitHub.com | |||
return type: | Object | |||
expression example: | {{ gitHubWikiBadge() }} should render: [](https://github.com/domain-centric/documentation_builder/wiki) | |||
parameter: | toolTip | String | optional (default="Project Wiki pages on github.com") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge with the amount of stars on github.com | |||
return type: | Object | |||
expression example: | {{ gitHubStarsBadge() }} should render: [](https://github.com/domain-centric/documentation_builder/stargazers) | |||
parameter: | toolTip | String | optional (default="Stars ranking on github.com") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge with the amount of open issues on github.com | |||
return type: | Object | |||
expression example: | {{ gitHubIssuesBadge() }} should render: [](https://github.com/domain-centric/documentation_builder/issues) | |||
parameter: | toolTip | String | optional (default="Open issues on github.com") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge with the amount of open pull requests on github.com | |||
return type: | Object | |||
expression example: | {{ gitHubPullRequestsBadge() }} should render: [](https://github.com/domain-centric/documentation_builder/pull) | |||
parameter: | toolTip | String | optional (default="Open pull requests on github.com") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for a badge with the amount of open pull requests on github.com | |||
return type: | Object | |||
expression example: | {{ gitHubLicenseBadge() }} should render: [](https://github.com/domain-centric/documentation_builder/blob/main/LICENSE) | |||
parameter: | toolTip | String | optional (default="Project License") | This text becomes visible when hoovering over a badge |
description: | Creates markdown for all github.com badges | |||
return type: | Object | |||
expression example: | {{ allGitHubBadges() }} |
description: | Creates markdown for all pub.dev and github.com badges | |||
return type: | Object | |||
expression example: | {{ allPubGitHubBadges() }} |
description: | Returns the natural exponent e, to the power of the value | |||
return type: | number | |||
expression example: | {{exp(7)}} should render: 1096.6331584284585 | |||
code example: | exp_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the natural logarithm of the value | |||
return type: | number | |||
expression example: | {{log(7)}} should render: 1.9459101490553132 | |||
code example: | log_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the sine of the radians | |||
return type: | number | |||
expression example: | {{sin(7)}} should render: 0.6569865987187891 | |||
code example: | sin_test.dart | |||
parameter: | radians | number | mandatory |
description: | Returns the values arc sine in radians | |||
return type: | number | |||
expression example: | {{asin(0.5)}} should render: 0.5235987755982989 | |||
code example: | asin_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the cosine of the radians | |||
return type: | number | |||
expression example: | {{cos(7)}} should render: 0.7539022543433046 | |||
code example: | cos_test.dart | |||
parameter: | radians | number | mandatory |
description: | Returns the values arc cosine in radians | |||
return type: | number | |||
expression example: | {{acos(0.5)}} should render: 1.0471975511965979 | |||
code example: | acos_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the the tangent of the radians | |||
return type: | number | |||
expression example: | {{tan(7)}} should render: 0.8714479827243188 | |||
code example: | tan_test.dart | |||
parameter: | radians | number | mandatory |
description: | Returns the values arc tangent in radians | |||
return type: | number | |||
expression example: | {{atan(0.5)}} should render: 0.4636476090008061 | |||
code example: | atan_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the positive square root of the value. | |||
return type: | number | |||
expression example: | {{sqrt(9)}} should render: 3.0 | |||
code example: | sqrt_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the a rounded number. | |||
return type: | number | |||
expression example: | {{round(4.445)}} should render: 4 | |||
code example: | round_test.dart | |||
parameter: | value | number | mandatory |
description: | Returns the length of a string | |||
return type: | number | |||
expression example: | {{length("Hello")}} should render: 5 | |||
code example: | length_test.dart | |||
parameter: | string | String | mandatory |
description: | Generates markdown documentation of all the tags within a TemplateEngine | |||
return type: | String | |||
expression example: | {{ tagDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of all the data types that can be used within a ExpressionTag of a TemplateEngine | |||
return type: | String | |||
expression example: | {{ dataTypeDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of all the constants that can be used within a ExpressionTag of a TemplateEngine | |||
return type: | String | |||
expression example: | {{ constantDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of variables that can be used within a ExpressionTag of a TemplateEngine | |||
return type: | String | |||
expression example: | {{ variableDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of all the functions that can be used within a ExpressionTag of a TemplateEngine | |||
return type: | String | |||
expression example: | {{ functionDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of all the operators that can be used within a ExpressionTag of a TemplateEngine | |||
return type: | String | |||
expression example: | {{ operatorDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |
description: | Generates markdown documentation of all the examples. This could be used to generate example.md file. | |||
return type: | String | |||
expression example: | {{ exampleDocumentation() }} | |||
parameter: | titleLevel | number | optional (default=1) | The level of the tag title |