Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atifaziz/Transplator
Simple C# source generator for text templates
https://github.com/atifaziz/Transplator
Last synced: about 1 month ago
JSON representation
Simple C# source generator for text templates
- Host: GitHub
- URL: https://github.com/atifaziz/Transplator
- Owner: atifaziz
- License: apache-2.0
- Created: 2021-01-05T21:03:36.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-11T17:12:49.000Z (about 2 years ago)
- Last Synced: 2024-10-29T11:42:16.508Z (about 1 month ago)
- Language: C#
- Size: 60.5 KB
- Stars: 31
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING.txt
Awesome Lists containing this project
- RSCG_Examples - Transplator
- csharp-source-generators - Transplator - ![stars](https://img.shields.io/github/stars/atifaziz/Transplator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/atifaziz/Transplator?style=flat-square&cacheSeconds=86400) A simple C# source generator for text templates. (Source Generators / Text templating)
README
# Transplator
This project is currently an experiment into the idea of generating C# source
code from a text template. The code generation is integrated into the C#
compiler using the [source generator] feature made available starting with
the version supporting C# 9.The input to Transplator is a simple text template file, where literal text is
interspersed with C# source code. The output is C# code that, when executed as
part of the compiled product, will produce text with literal parts copied over
as they are and the C# code in the template contributing dynamic text.Using the [source generator] feature has the benefit that the template is
turned into strong- and statically-typed C# source code. Any type errors will
be caught at compile-time. At run-time, the template output will be produced
at native speed, without any interpretation.The text templates can be used, for example, to generate e-mail messages with
certain parts replaced dynamically at run-time.## Format
Anything between `{%` and `%}` is considered C# code and everthing else is
treated as literal text. For example:The current date and time is {% DateTime.Now %}.
Transplator has some smarts to distinguish between control flow blocks or
statement and expressions that contribute dynamic text, so syntactically,
you only need to remember to use `{%` and `%}` as delimiters:{%
for (var i = 0; i < 10; i++) {
%}
i = {% i + 1 %}
{%
}
%}Like the [Liquid] templating language, you can use `-` to trim whitespace
from the left or right side:{%- "left whitespace is trimmed" %}
{% "right whitespace is trimmed" -%}
{%- "left and right whitespace is trimmed" -%}Like the [Scriban] templating language, you can use `~` to for [non-greedy
whitespace trimming][scrws]:> - Using a `{{~` will remove any whitespace before but will stop on the
> first newline without including it
> - Using a `~}}` will remove any whitespace after including the first
> newline but will stop after[source generator]: https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/
[Liquid]: https://shopify.github.io/liquid/
[Scriban]: https://github.com/scriban/scriban
[scrws]: https://github.com/scriban/scriban/blob/master/doc/language.md#14-whitespace-control