Explore Templates
The template we will be running is in the tutorial-database-documenter folder.
table.tmpl
is the template we will be running. Templates.json
is a file that is used by monstarillo to tell it which templates to run and what to do with the output of the templates.
Let’s take a look at the templates.json
file
{
"templates": [
{
"templateFile": "{{getTag .Tags \"TemplateRoot\"}}/tutorial-database-documenter/table.tmpl",
"generatedFileName": "{{ .CurrentTable.GetCamelCaseTableName}}.md",
"generatedFolderName": "tables",
"minimumGeneratedFileLength": 0,
"outputPath": "{{getTag .Tags \"OutputPath\"}}/",
"overwriteFile": true
}
],
"tags": [
{
"tagName": "TemplateRoot",
"value": "/home/patrick/code/templates"
},
{
"tagName": "OutputPath",
"value": "/home/patrick/code-gen-output/postgres-chinhook-db-md"
}
]
}
There is one template in the array of templates and two tags in the array of tags. A tag is a variable that can be referenced in a template that is defined in the template.json file. The first tag is TemplateRoot. The TemplateRoot tag’s value should be set to the location of the templates folder that was created when you cloned the repository. The OutputPath tag’s value should be set to the folder that you want the generated code to be placed in.
Let’s take a look at the template.
templateFile : The location of the template we are going to run.
generatedFileName : The name of the file to be generated by the template. In this case we will be naming each file with each table’s camel cased tabel name.
generatedFolderName : The name of the folder to put the generated code in. In this case we will be putting the generated code in a folder named tables.
minimumGeneratedFileLength : Monstarillo will only create a file if it’s length is greater than this value or if the value is set to 0.
outputPath : The folder to put the generated code in. In this case we will be placing the generated code in a folder set by the tag OutputPath
overwriteFile : Do we want monstarillo to overwrite a generated file if it already exists.