We use the embed-code tool (Go version) to embed code snippets to markdown pages. Take a look on its README file to know how it works.
Firstly, we need to download the last available executable of embed-code.
Originally, this tool was written as a plugin for Jekyll, but now it is also
available as a binary executable written in Go.
- Open embed-code repository.
- Go to the
bindirectory and download an executable suitable for you OS. - Put it in the
docs/_bindirectory of this repository.
The docs/_code directory contains the source code, which is embedded into the pages
of the spine.io documentation:
examples— contains examples selected from the repositories underspine-examplesorganization. These repositories are added to this project as Git submodules.samples— smaller pieces of code embedded to the site.
To get the latest version of the code snippets, update the submodules:
git submodule update --remoteAs for now, there is the docs/_settings/v1.embed-code.yml config file for Spine v1.
First, update the code snippets, and then migrate the updated snippets to the documentation files using the tool. The most important points here are:
- Choose the correct config file (or create / modify one).
- Check out the correct branch in the repository with snippets.
- Make sure the used Spine version in snippets matches your expectations.
- After code embedding, please always review the changes made to
.mdor.htmlfiles.
-
Update the snippet in the appropriate repository.
-
Make sure it builds successfully.
-
Go to the
SpineEventEngine/documentationproject. -
Navigate to the
docs/_bindirectory. -
Execute the binary based on your operating system and architecture:
./embed-code-<os> -config-path="config-of-your-choice.yml" -mode="embed".For example:
./embed-code-macos -config-path="../_settings/v1.embed-code.yml" -mode="embed"
-
Make sure the project you're going to add has a top-level
buildAllGradle task.See the build script of Hello Example for the declaration of such a task. This task must be present in both single- and multi-module Gradle example projects that are going to be used for embedding into this site.
See the declaration of
buildAlltask for more details. -
Add the example code as a submodule for this project:
git submodule add https://github.com/spine-examples/<example-name> docs/_code/examples/<example-name>
Please make sure the new submodule goes under the
docs/_code/examplesdirectory, as shown in the command line template above. -
Include the build of the added project into the
settings.gradle.ktsfile. -
Insert code embedding directives where needed in the
docs/content/folder. -
Navigate to the
docs/_bindirectory. -
Execute:
./embed-code -config-path="config-of-your-choice.yml" -mode="embed".For example:
./embed-code-macos -config-path="../_settings/v1.embed-code.yml" -mode="embed"
- Add the code under
docs/_code/samples/srcdirectory. - Make sure tests for the new code pass.
- Add the new piece using the
embed-codeguide. - Include the build of the added project into the
settings.gradle.ktsfileincludeBuild("./docs/_code/samples").
-
Remove the snippet in the appropriate repository.
-
Remove its code embeddings from the markdown files.
-
Make sure there are no embeddings of the removed snippet anymore:
./embed-code-<os> -config-path="config-of-your-choice.yml" -mode="check".For example:
./embed-code-macos -config-path="../_settings/v1.embed-code.yml" -mode="check"
If you encounter an error indicating that the executable file cannot be run,
it likely does not have execution permissions. To grant execution rights
on Linux or macOS, run the following command from the _code directory:
chmod +x embed-code-macos