Wraps HandlebarsJS to make it usable from .net.
Has a dependency on the MsieJavaScriptEngine package.
ILMerges the MsieJavaScriptEngine assembly to avoid an extra dependency
Has a dependency on the ClearScript.V8 package.
Has a dependency on the MsieJavaScriptEngine and Chevron.IE packages.
ILMerges the MsieJavaScriptEngine and Chevron.IE assembly to avoid an any extra dependencies.
Has a dependency on the ClearScript.V8 and Chevron.V8 packages.
var source = @"<p>Hello, my name is {{name}}. I am from {{hometown}}. I have ' +
'{{kids.length}} kids:</p>' +
'<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>";
var context = new
{
name = "Alan",
hometown = "Somewhere, TX",
kids = new[]
{
new
{
name = "Sally",
age = "4"
}
}
};
using (var handleBars = new Handlebars())
{
handleBars.RegisterTemplate("myTemplate", source);
Approvals.Verify(handleBars.Transform("myTemplate", context));
}
<p>Hello, my name is Alan. I am from Somewhere, TX. I have 1 kids:</p>
<ul>
<li>Sally is 4</li>
</ul>
var source = "<ul>{{#posts}}<li>{{link_to}}</li>{{/posts}}</ul>";
var context = new
{
posts = new[]
{
new
{
url = "/hello-world",
body = "Hello World!"
}
}
};
using (var handleBars = new Handlebars())
{
handleBars.RegisterHelper("link_to",
@"function() {
return new Handlebars.SafeString(""<a href='"" + this.url + ""'>"" + this.body + ""</a>"");
}");
handleBars.RegisterTemplate("myTemplate", source);
Approvals.Verify(handleBars.Transform("myTemplate", context));
}
<ul>
<li>
<a href='/hello-world'>Hello World!</a>
</li>
</ul>
var source = "<ul>{{#people}}<li>{{> link}}</li>{{/people}}</ul>";
var context = new
{
people = new[]
{
new
{
name = "Alan",
id = 1
},
new
{
name = "Yehuda",
id = 2
}
}
};
using (var handleBars = new Handlebars())
{
handleBars.RegisterPartial("link",@"<a href=""/people/{{id}}"">{{name}}</a>");
handleBars.RegisterTemplate("myTemplate", source);
Approvals.Verify(handleBars.Transform("myTemplate", context));
}
<ul>
<li><a href="/people/1">Alan</a></li>
<li><a href="/people/2">Yehuda</a></li>
</ul>
The binary ships with a resource merged version of HandlebarsJS. Also see the License.
The current version included in the library is v1.3.0. If you feel a newer version should be included at any point in time please raise an issue.
If you want to run a custom version of HandlebaseJS simply place the custom handlebars.js
in the current running directory and that file will be used instead of the merged version.
Mustache designed by Matt Brooks from The Noun Project