antaris / fumanchu Goto Github PK
View Code? Open in Web Editor NEWHandlebars/Mustache templating in .NET
Handlebars/Mustache templating in .NET
Hi,
Source code for console application, output is comapred to Handlebars.net:
When processing user generated content, it would be useful to limit the processing of properties through attributes.
Json.NET supports something similar through the MemberSerialization flag (http://www.newtonsoft.com/json/help/html/serializationattributes.htm) and it would be great if FuManchu could to.
Cheers!
Added unit tests for expression tags has highlighted that although the parser supports the {{{...}}}
tag syntax, the SyntaxTreeRenderer<T>.Write
method isn't actual considering the RenderContext.EscapeEncoding
setting, therefore content is always being encoded.
using FuManchu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApp1
{
public class Program
{
public static void Main(string[] args)
{
string template = "{{#is Value != 1}}True!{{/is}}";
string content = Handlebars.CompileAndRun("test", template, new { Value = 2 });
Console.WriteLine(content);
Console.ReadKey();
}
}
}
Hi, I want to define a helper which can perform a loop, and as part of this, I'd like to pass in the @FIRST, @last and @Index variables. I notice this is possible in the EnumberableRenderer, but I'm not sure how I go about implementing this in an helper declared inline using the RegisterHelper interface.
Do you have an example of how to implement this?
Publish documentation site.
HandlebarsJS supports the notion of subexpressions, whereby the results of expression helpers can be passed to other helpers, e.g.:
{{outer-helper (inner-helper 'abc') 'def'}}
See http://handlebarsjs.com/expressions.html
This might be a powerful addition to the framework.
I've created a template like this:
{{#range 1 10}}
{{#if @index}},{{/if}}
{
// Some json content
}
{{/range}}
I'm using a custom helper for the "range" tag, which all works fine, however there seems to be a problem with the if statement inside it. Running handlebars, rather than getting a list of object tags separated by a comma, I get a bunch of commas all grouped together, then the list of objects next to them (not comma seperated).
,,,,,,,,,{}{}{}{}{}{}{}{}{}{}
I'm trying to debug in at the moment, but it looks to be down to the fact that at some point, the span renderer for the comma renders against the writer that is in the scope, which is the current outer blocks scope, rather than the writer generated for the range helper, thus all the commas get written to the main writer, then on completion of the helper, all the other objects are written to the writer directly afterwards.
I'm currently getting really confused with the visitor rabbit whole to be able to narrow it down to a specific location, but any help would be greatly appreciated.
Dan Harper implemented some useful Handlebars extensions in his repo at https://github.com/danharper/Handlebars-Helpers.
The {{#is...}}
helper builds on the purpose of {{#if...}}
with different semantics, adding support for different types of comparison operators, and custom operators.
The standard operators include:
==
(equality)!=
(negated equality)not
(alias for !=
)===
(strict equality)!==
(strict negated equality)>
(less than)>=
(less than or equal to)<
(less than)<=
(less than or equal to)in
(exists within a set)These could add serious flexibility to FuManchu, but need to be careful with strict vs. non-strict, in terms of type conversions.
Apparently the following is also supported by mustache:
{{&name}}
Which is the equivalent of:
{{{name}}}
Mustache supports the following:
{{^person}}...{{/person}}
Which is the equivalent of:
{{#unless person}} {{/unless}}
I've also seen instances of:
{{#person}}
{{name}}
{{^}}
No person :-(
{{/person}}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.