Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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);
```