https://github.com/kainjow/Mustache
Mustache text templates for modern C++
https://github.com/kainjow/Mustache
c-plus-plus mustache
Last synced: 11 months ago
JSON representation
Mustache text templates for modern C++
- Host: GitHub
- URL: https://github.com/kainjow/Mustache
- Owner: kainjow
- License: bsl-1.0
- Created: 2015-04-11T18:23:45.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T16:31:30.000Z (about 2 years ago)
- Last Synced: 2024-10-14T08:11:02.640Z (over 1 year ago)
- Topics: c-plus-plus, mustache
- Language: C++
- Homepage:
- Size: 619 KB
- Stars: 355
- Watchers: 22
- Forks: 49
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-modern-cpp - Mustache - Mustache text templates in C++11. (Libraries / String formatting & templating)
README
# About
* [Mustache](http://mustache.github.io) 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
[](https://travis-ci.org/kainjow/Mustache) [](https://ci.appveyor.com/project/kainjow/mustache) [](https://github.com/kainjow/Mustache/actions) [](https://codecov.io/gh/kainjow/Mustache)
## Example usage
All examples assume `using namespace kainjow::mustache`. Additional examples and usage can be found in the `tests.cpp` file.
### Example 1 - Hello World
````cpp
mustache tmpl{"Hello {{what}}!"};
std::cout << tmpl.render({"what", "World"}) << std::endl;
// Hello World!
````
### Example 2 - Lists
````cpp
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,
````
### Example 3 - Custom Render Handler
````cpp
mustache tmpl("Hello {{what}}!");
std::stringstream ss;
tmpl.render({"what", "World"}, [&ss](const std::string& str) {
ss << str;
});
// ss.str() == "Hello World!"
````
## Supported Features
This library supports all current Mustache features:
- Variables
- HTML escaping
- Sections
- Inverted Sections
- True/False
- Lists
- Lambdas
- Partials
- Comments
- Set Delimiter
Additional features:
- Custom escape function for use outside of HTML