lyphtec / FluentEmail.Markdown

Markdown custom template renderer for FluentEmail

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a Markdown custom template renderer for FluentEmail
It utilises the ITemplateRenderer interface exposed by FluentEmail to hook in custom template renderers and supports full model binding as available in the default Razor renderer.

Markdown parsing is done by MarkdownDeep

Installation

Available on NuGet:

PM> Install-Package FluentEmail.Markdown

Example Usage

var email = Email
    .From("bob@hotmail.com")
    .To("somedude@gmail.com")
    .Subject("woo nuget")
    .UsingTemplateEngine(new MarkdownRenderer())   // Hook in this renderer -- IMPORTANT!!: This needs be set before the next line below
    .UsingTemplateFromFile(@"~/test.md", new { Name = "John Smith", Numbers = new string[] { "1", "2", "3" } });


// You can also set the default renderer so all Email instances will use this renderer by doing the following:

// Set global renderer to use (usually in App init):
Email.DefaultRenderer = new MarkdownRenderer();

// Use FluentEmail without the need to call UsingTemplateEngine() each time
var email = Email
    .From("bob@hotmail.com")
    .To("somedude@gmail.com")
    .Subject("woo nuget")
    .UsingTemplateFromFile(@"~/test.md", new { Name = "John Smith", Numbers = new string[] { "1", "2", "3" } });

test.md:

# Heading 1

This is a [Markdown](http://mouapp.com) page

1. one
2. two
3. three

You can also bind to Model

Name: @Model.Name

Numbers:

@foreach (i in Model.Numbers) {
@: - Number: @i 
}

The current date is: @DateTime.Now

This will be the rendered output (the Message.Body):

<h1>Heading 1</h1>

<p>This is a <a href="http://mouapp.com">Markdown</a> page</p>

<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>

<p>You can also bind to Model</p>

<p>Name: John Smith</p>

<p>Numbers:</p>

<ul>
<li>Number: 1 </li>
<li>Number: 2 </li>
<li>Number: 3 </li>
</ul>

<p>The current date is: 04/08/2014 10:52:33 PM</p>

Note the @foreach syntax above. It follows standard Razor conventions. This renderer actually does a Razor parse on the raw template text first to resolve all model bindings, then depending on the isHtml flag, will do the Markdown parsing.

About

Markdown custom template renderer for FluentEmail


Languages

Language:C# 96.5%Language:Shell 3.5%