Stubble is an implementation of the Mustache template system in C# (but is usable from any .NET language).
For a language-agnostic overview of mustache's template syntax, see the mustache(5)
manpage.
Stubble is tested against the mustache specification and is v.1.1.2, including lambdas
compliant, this means that your templates in other languages will work with Stubble provided they match the spec!
It is licensed under the MIT License which can be found here.
Stubble is designed to be a spec compliant mustache renderer with only the bare essentials, you could say the rest has been trimmed down!
Stubble provides no methods of finding your templates, no complicated logic for getting values from your objects or special types, no non-spec tags for rendering or logic and only the necessaries to make it a simple and fast parser and renderer.
At the moment Stubble is in alpha but please feel free to grab it from the pre-release feed on nuget.org by clicking on the badge above! Another option for the more adventurous is to download the source and build it yourself.
For how to use Stubble I'd recommend reading the how to use guide here.
We use BenchmarkDotNet to optimize our performance to to allow us to compare our real performance against our closest comparable measure which is Nustache.
Our benchmarks can be found in the repo and we test using the Tweet benchmarks found in the Mustache.java repository that we have implemented in C#. We've tried to be as fair as possible giving each their optimal scenario so we can focus on raw numbers.
The test itself measures how long it takes to render a timeline of tweets with partials, inverted sections default values and missing data.
Note: This graph shows the original Regex parser and renderer, this will be removed from the chart with the version 1.0.0 release to avoid confusion for new users.
The numbers here represent the baseline values graphed from the timeline test with warm-ups and outliers removed, please feel free to checkout the repository and run the benchmarks to verify the results or if there's a better way to benchmark the library, we're always open to improvements.
Stubble exposes certain internal structures for parsing and rendering extensions to be added in a loosely coupled way.
These extensions can be added on to the IRendererSettingsBuilder
as extension methods or the IStubbleBuilder
which implements the interface for of IRendererSettingsBuilder
and passes through to an internal builder. This is to simplify the building interface.
For more detail on the types of Extensibility and how to extend stubble please see the extensibility docs here..
Stubble comes in the box with very few template loaders but provides an interface and extension points which allow you to provide your own async and sync methods to get templates from a given name or use one that has already been created in a separate package.
The implementation of this feature is heavily inspired by bobthecow's implementation of loaders in mustache.php.
For more detail on template loading please see the template loading docs here..
Why not use Nustache instead?
If Stubble doesn't do what you need then you should use Nustache! It's a great tool and provides the same base functionality as Stubble provides for the default Mustache spec (I know because I'm a contributor and current maintainer of that project!).
However it does provide lots of extra features, such as a variety of input types, helpers and compilation which increases its complexity and some which are extensions to the Mustache spec (such as helpers). If you need any of those pieces of functionality I'd highly recommend you use Nustache... at least until there are Extensions for Stubble which provide the functionality your after!
Straight Razor by Vectors Market from the Noun Project