Documentation for the Drift package
Folder Structure:
buildersContains the builders for the snippets and dart projects versions (versions.jsonand*.excerpt.jsoninlib).docsContains the markdown files for the documentation.deployThe output of the documentation build.libContains the code snippets for the documentation.testContains the tests for the documentation.webContains some dart which code which is compiled to JavaScript and served with the documentation.mkdocsContains the MkDocs configuration.
Building the Documentation
You will need to make the docs.sh script executable before you can run it. You can do this by running the following command:
chmod +x docs.sh
Run the following command to build the documentation:
docs.sh build
Serving the Documentation
You can also serve the documentation locally and view it in your browser. Changes to the documentation will be reflected in real-time.
Run the following command to serve the documentation:
docs.sh serve
If you would like changes to snippets to be available in real-time, you can run the following command:
docs.sh serve --with-build-runner
Limitations of Serving the Documentation
- The flutter example project will not be built when serving. If you would like the flutter example to be available while serving the docs, you will need to run the
docs.sh build1st.docs.sh build docs.sh serve - The
webfolder will not be watch for changes. If you change code in thewebfolder, you will have to kill the server and restart it.
Understanding the Build Process
Behind the scenes, the docs.sh script does the following:
- Running
webdev:- Creates
versions.jsonwhich will inject the latest version into MkDocs. e.g.^{{ versions.drift }} - Creates
.excerpt.jsonsnippet files inlibwhich MkDocs will use to inject syntax highlighted code into the documentation. e.g.{{ load_snippet('flutter','lib/snippets/setup/database.dart.excerpt.json') }} - Run the
drift_devbuilder to generate the code for the snippets. - Compile the dart code in
webto JavaScript.
- Creates
- Running
mkdocs:- Compile the markdown files in
docsto HTML.
- Compile the markdown files in
- Combine the output of the two steps into the
deployfolder.
Syntax Highlighting
Code which is included in markdown using ``` ``` snippets is highlighted by mkdocs automatically. These colors can be modified by following the instructions in the MkDocs documentation.
Code snippets which are included in the documentation using the {{ load_snippet() }} macro are highlighted too. If they are from a .dart file we use a custom syntax highlighter, otherwise we use the default MkDocs syntax highlighter.
When build_runner runs, it will create a *.excerpt.json next to each snippet file which contains each snippet in styled HTML (dart) or in raw text (all other languages). The {{ load_snippet() }} macro injects the snippets from these *.excerpt.json files. The code for this macro can be found in /docs/mkdocs/main.py.