Why Veil?
Recently I've been working away on a new project Veil.
Veil is my entry in to the .NET "view engine" / templates space.
There isn't exactly an urgent need for a new solution to this problem and most are perfectly happy with Razor. So why did I go ahead and spend my time writing one?
Like all great software, it was written to scratch an itch.
Veil isn't my first template solution, in fact my first post on this blog over 8 years ago was to share the solution I used back then.
How is Veil different?
- Veil compiles your template down to IL, returning you an
Action<TextWriter, TModel>
. This compilation gives Veil a significant rendering performance advantage over most other template solutions available. - Veil is easy to use and integrate into your solution.
- Veil does not define a syntax, instead it supports multiple syntax parsers.
Let's dig further in to these.
Compilation
Like Razor, Veil does compilation of your templates. This scenario is optimized for templates that can be compiled once and then run many times.
Unlike Razor though, Veil uses Sigil to emit IL to a DynamicMethod. It does not create assemblies. This makes Veil much easier to work with.
Simplicity
Veil maintains a small surface area and can be dropped in to any project with ease. It is as simple as this
// Register your parsers once at startup
VeilEngine.RegisterParser("supersimple", new SuperSimpleParser());
// Compile each template once with the chosen parser
var template = "Hello @Model.Name";
var compiledTemplate = new VeilEngine().Compile<ViewModel>("supersimple", new StringReader(template));
// Execute your template as needed
using (var writer = new StringWriter()) {
compiledTemplate(writer, new ViewModel { Name = "Bob" });
}
Syntax
Unusually Veil does not dictate a particular syntax for your templates. The Veil compiler accepts an abstract syntax tree which defines the template. This means Veil can support any number of syntax parsers all of which will benefit from the compilation and integration work done to the core.
Currently there are two syntaxes being targeted - Veil.SuperSimple and Veil.Handlebars. These are a bit rough at the moment, but will be improved over time.
A goal is for it to be as simple as possible for people to port their favourite syntax over to Veil and create a drop-in replacements for whichever syntax their templates are currently written in.
The future
I've just pushed out the first "alpha" packages for Veil. The immediate priority is to finish off the features I want in my 0.1.0 release and lock down the API.