documentation_builder
Generates documentation files from template files. This can be useful when you write documentation for a Dart or Flutter project and want to reuse/import files or Dart documentation comments.
It can generate any type of text file e.g.:
- README.md
- LICENSE
- CHANGELOG.md
- Example files
- GitHub wiki files
- or any other text file
documentation_builder is not intended to generate API documentation. Use dartdoc instead.
Features
documentation_builder uses the template_engine package with additional functions for documentation. The most commonly used functions for documentation are:
Breaking Changes
documentation_builder 1.0.0 has had major improvements over earlier versions:
- It uses the DocumentationTemplateEngine which is an extended version of the TemplateEngine from the template_engine package
- Less error prone: The builder will keep running even if one of the templates fails to parse or render.
- Better error messages with the position within a template file.
- Expressions in template file tags can be nested
- More features: The DocumentationTemplateEngine can be extended with custom:
- dataTypes
- constants
- functionGroups
- operatorGroups
- More consistent template syntax: now all functions
- The input and output file is determined by parameters in the build.yaml file, which is:
- Easier to understand than the old DocumentationBuilder conventions
- More flexible: It can now be configured in the build.yaml file
- Each generated file can have an optional header text which can be configured in the build.yaml per output file suffix.
This resulted in the following breaking changes:
-
Tags
old syntax new syntax {ImportFile file:'OtherTemplateFile.md.template' title='# Other Template File'} # Other Template File
{{importTemplate('OtherTemplateFile.md.template')}}{ImportCode file:'file_to_import.txt' title='# Code example'} # Code example
{{importCode('file_to_import.txt')}}{ImportDartCode file:'file_to_import.dart' title='# Dart code example'} # Dart code example
{{importDartCode('file_to_import.dart')}}{ImportDartDoc path='lib\my_lib.dart|MyClass' title='# My Class'} # My Class
{{importDartDoc('lib\my_lib.dart|MyClass')}}{TableOfContents title='# Table of contents example'} # Table of contents
{{tableOfContents(path='doc/template/doc/wiki')}}{MitLicense name='John Doe'} {{license(type='MIT', name='John Doe')}} See the function documentation for more details on these and new functions
-
Links
old syntax new syntax [GitHub] {{gitHubLink()}} [GitHubWiki] {{gitHubWikiLink()}} [GitHubStars] {{gitHubStarsLink()}} [GitHubIssues] {{gitHubIssuesLink()}} [GitHubMilestones] {{gitHubMilestonesLink()}} [GitHubReleases] {{gitHubReleasesLink()}} [GitHubPullRequests] {{gitHubPullRequestsLink()}} [GitHubRaw] {{referenceLink('ref')}} or{{gitHubRawLink()}} [PubDev] {{pubDevLink()}} [PubDevChangeLog] {{pubDevChangeLogLink()}} [PubDevVersions] {{pubDevVersionsLink()}} [PubDevExample] {{pubDevExampleLink()}} [PubDevInstall] {{pubDevInstallLink()}} [PubDevScore] {{pubDevScoreLink()}} [PubDevLicense] {{pubDevLicenseLink()}} PubDev package links {{referenceLink()}} Dart code links {{referenceLink('ref')}} Markdown file links [title](URI) See the function documentation for more details on these and new functions
-
Badges
old syntax new syntax [CustomBadge title='title' ...] [title]({{customBadge()}}) [PubPackageBadge title='title'] [title]({{pubPackageBadge()}}) [GitHubBadge title='title'] [title]({{gitHubBadge()}}) [GitHubWikiBadge title='title'] [title]({{gitHubWikiBadge()}}) [GitHubStarsBadge title='title'] [title]({{gitHubStarsBadge()}}) [GitHubIssuesBadge title='title'] [title]({{gitHubIssuesBadge()}}) [GitHubPullRequestsBadge title='title'] [title]({{gitHubPullRequestsBadge()}}) [GitHubLicenseBadge title='title'] [title]({{gitHubLicenseBadge()}}) See the function documentation for more details on these and new functions
-
Github-Wiki pages are now generated somewhere in the project folder (e.g. doc\wiki) and need to be copied to GitHub. This could be done using GitHub actions (e.g. after each commit). For more information see Automatically Publishing Wiki pages
Examples
The documentation_builder's own documentation was generated by itself and serves as a showcase.
You can view the templates files and the generated output on https://github.com and https://pub.dev:
README.md
LICENSE
CHANGELOG.md
example.md
Wiki pages
- Template examples (click on the raw button to see the generated markdown)
- Rendered examples
Getting Started
The easy way
The simplest way to use the documentation_builder package is to use it as a command line tool.
To install it, run dart pub global activate documentation_builder
from the command line.
After installation you can use the following commands:
documentation_builder help
Shows available commands.documentation_builder setup
Sets up a project to use the documentation_builder:- Adds build_runner as dev dependency if needed
- Adds documentation_builder as dev dependency if needed
- Adds or updates build.yaml
- Adds template files if needed
- Adds github publish-wiki workflow if needed
documentation_builder build
Generates documentation files from template files by startingbuild_runner build
.
The hard way: step by step
- Read the Wiki documentation
- Install documentation_builder developer dependencies in in your project:
build_runner is a tool to run file generators like documentation_builderdart pub add --dev build_runner dart pub add --dev documentation_builder
- Configure the documentation_builder
Add a build.yaml file to the root of your project with the following lines (or merge lines if build.yaml file already exists):
For more information on the build.yaml file see build_configtargets: $default: sources: - doc/** - lib/** - bin/** - web/** - test/** - pubspec.* - $package$ builders: documentation_builder|documentation_builder: enabled: True # options: # input_path: # An expression where to find template files # Defaults to 'doc/template/{{filePath}}.template' # output_path: # An expression where to store the result files # Defaults to '{{filePath}}' # file_headers: # A map of file output suffixes and the file header template to be added (which can be null), defaults to: # LICENSE: null # LICENSE.md: null # .md: '[//](https://pub.dev/packages///): "# (This file was generated from: {{inputPath()}} using the documentation_builder package)" # .dart: "// This file was generated from: {{inputPath()}} using the documentation_builder package"
- Create 'doc/template' folders in the root of your project
- Create template files in the "doc/template" folder. See examples
- Generate the documentation files
- Publish the documentation files