GithubHelp home page GithubHelp logo

jamescurran / fluentemail.markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lyphtec/fluentemail.markdown

0.0 1.0 0.0 887 KB

Markdown custom template renderer for FluentEmail

C# 96.51% Batchfile 3.49%

fluentemail.markdown's Introduction

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("[email protected]")
    .To("[email protected]")
    .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("[email protected]")
    .To("[email protected]")
    .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.

fluentemail.markdown's People

Contributors

lyphtec avatar srijken avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.