Simplet - .NET Template Bundler
A simple templating engine to generate valid C# classes from static text files. Convert your text files into code that can be checked at compile-time.
Installation
Install the library via dotnet
on the CLI:
dotnet tool install --global simplet
Usage
You'll need to have a config file. Let's name our config file sample.json
. The following content is sufficient:
{
"target": "dist",
"sources": [
{
"includes": [
"templates/*.html"
]
}
]
}
This creates a new project in the directory dist
. All HTML files from the templates
directory will be converted to C# classes. As a follow up we may run
dotnet build dist
To create a DLL containing the generated classes.
A full configuration file could look as follows:
"name": "BigCo.Templates.Sample",
"target": "dist",
"framework": "netstandard1.3",
"description": "My project description",
"author": "BigCo",
"version": "1.2.3",
"sources": [
{
"placeholder": "%([A-Za-z]{1,32})%",
"name": "MyTemplate",
"includes": [
"templates/**/*.html"
],
"excludes": [
"templates/foo",
"templates/bar"
],
"parameter": "file",
"namespace": "BigCo.Templates.Sample.Html",
"sections": [
{
"format": "<!--start-->(.*)<!--end-->",
"title": "Content"
}
]
}
]
The parameter
accepts values such as none
(default), file
, directory
, and extension
. It pretty much determines if some internal grouping should be done before writing out files. A grouping of file
would group in such a way that files in the same directory are collected and the name of the file needs to be used as a parameter.
License
MIT License (MIT). For more information see LICENSE file.