Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dburriss/temptress
I am a handle bars like templating engine for .NET
https://github.com/dburriss/temptress
Last synced: 21 days ago
JSON representation
I am a handle bars like templating engine for .NET
- Host: GitHub
- URL: https://github.com/dburriss/temptress
- Owner: dburriss
- License: mit
- Created: 2016-02-11T02:47:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-14T17:05:50.000Z (almost 9 years ago)
- Last Synced: 2024-11-10T23:06:38.795Z (about 1 month ago)
- Language: C#
- Size: 18.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Temptress
I am a handle bars like templating engine for .NET.Temptress uses the `{{var}}` type syntax for replacing text with values.
A big push for this project is that messages are strongly typed and verifiable*(TODO)* against the template.> Requires the reflection helper library [Philosphical Monkey](https://github.com/dburriss/PhilosophicalMonkey).
## Basic Usage
Install via Nuget
> `Install-Package Temptress -Pre`With the following POCO classes defined:
```csharp
public class WelcomeMessage
{
public string FullName { get; set; }public DateTime JoinDate { get; set; }
public Address Address { get; set; }
}public class Address
{
public int StreetNumber { get; set; }
public string StreetName { get; set; }
}
```
Then creating a template:
```csharp
var template = new Template("Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}!");
var renderer = new TemplateRenderer(template);
```
Then you can render the template with whatever data you like, reusing the same template with different data.> Note the creation template is the expensive part (as much as possible) so that the rendering is as fast as possible.
Then rendering the content:
```csharp
var message = new WelcomeMessage(){ FullName = "Devon", Address = new Address{ StreetNumber = 5, StreetName = "Main"} };
var messageText = renderer.Render(message);
```