- Mustache implementation for modern C++ (requires C++11)
- Header only
- Zero dependencies
- Templated string type for compatibility with any STL-like string (std::string, std::wstring, etc)
- Boost license
All examples assume using namespace kainjow::mustache. Additional examples and usage can be found in the tests.cpp file.
mustache tmpl{"Hello {{what}}!"};
std::cout << tmpl.render({"what", "World"}) << std::endl;
// Hello World!mustache tmpl{"{{#employees}}{{name}}, {{/employees}}"};
data employees{data::type::list};
employees << data{"name", "Steve"} << data{"name", "Bill"};
tmpl.render({"employees", employees}, std::cout);
// Steve, Bill, mustache tmpl("Hello {{what}}!");
std::stringstream ss;
tmpl.render({"what", "World"}, [&ss](const std::string& str) {
ss << str;
});
// ss.str() == "Hello World!"This library supports all current Mustache features.
- Variables
- HTML escaping
- Sections
- Inverted Sections
- True/False
- Lists
- Lambdas
- Partials
- Comments
- Set Delimiter
For *nix:
make
For macOS:
make mac
For Visual Studio 2013 (CMake 2.8+ required):
build.bat
For Visual Studio 2015 (CMake 3.1+ required):
build.bat 14
- Added a new lambda type (innovatively called
lambda2) that takes an additional render function. It will not render its result but allows the user to call therenderargument to render the section text, or any other text.
- Performance improvements - about 45% faster than version 2
- Even simpler API. Not backwards compatible but upgrading should be straightforward:
- Namespace, classes, and methods are now in snake case to match the STL. For example,
Kainjow::Mustacheis nowkainjow::mustache - Classes and aliases are now under a
mustachenamespace, instead of being under the mustache class - Removed
Data::List()- usedata{data::type::list}instead - Removed
Data::type()- use the variousis_xxxmethods to identity the type
- Namespace, classes, and methods are now in snake case to match the STL. For example,
- New simpler API (not backwards compatible)
- std::wstring support
- Bug fixes (thanks to Shen-Ta Hsieh)
- Automated tests on OS X
- 100% test coverage
- All current Mustache features are implemented.
Copyright 2015-2017 Kevin Wojniak
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.