Skip to content

lukasz-lysik/Handlebars.Net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handlebars.Net Build Status

Blistering-fast Handlebars.js templates in your .NET application.

Handlebars.js is an extension to the Mustache templating language created by Chris Wanstrath. Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.

Check out the handlebars.js documentation for how to write Handlebars templates.

Handlebars.Net doesn't use a scripting engine to run a Javascript library - it compiles Handlebars templates directly to IL bytecode. It also mimics the JS library's API as closely as possible.

Handlebars.Net is in beta right now - check out the todo to see what's missing.

##Install

nuget install Handlebars.Net -PreRelease

##Usage

string source =
@"<div class=""entry"">
  <h1>{{title}}</h1>
  <div class=""body"">
    {{body}}
  </div>
</div>";

var template = Handlebars.Compile(source);

var data = new {
    title = "My new post",
    body = "This is my first post!"
};

var result = template(data);

/* Would render:
<div class="entry">
  <h1>My New Post</h1>
  <div class="body">
    This is my first post!
  </div>
</div>
*/

###Registering Helpers

Handlebars.RegisterHelper("link_to", (writer, context, parameters) => {
  writer.WriteSafeString("<a href='" + context.url + "'>" + context.text + "</a>");
});

string source = @"Click here: {{link_to}}";

var template = Handlebars.Compile(source);

var data = new {
    url = "https://github.com/rexm/handlebars.net",
    text = "Handlebars.Net"
};

var result = template(data);

/* Would render:
Click here: <a href='https://github.com/rexm/handlebars.net'>Handlebars.Net</a>
*/

##Todo Release Candidate prerequisites:

  • Support for block helpers
  • if / else / unless helper
  • with helper
  • each / else helper
  • # / ^ sections
  • Escape everything by default
  • Object enumeration
  • @key, @index, @first, @last context variables
  • Comments
  • > partials
  • Give helpers access to current context
  • Support for JS-like truthy and falsy values
  • Non-escaping expressions ("triple-stash" {{{ }}})

Future roadmap:

  • Add unit tests!
  • Set delimiters
  • Mustache(5) Lambdas
  • MVC view engine
  • Nancy view engine

About

A real .NET Handlebars engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published