https://github.com/kainjow/mustache
Mustache text templates for modern C++
https://github.com/kainjow/mustache
c-plus-plus mustache
Last synced: 6 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 (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T16:31:30.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T08:11:02.640Z (12 months 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
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 DelimiterAdditional features:
- Custom escape function for use outside of HTML