• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D18-Apr-202049 65

.travis.ymlH A D18-Apr-2020659 2720

LICENSEH A D18-Apr-20201.3 KiB2621

MakefileH A D18-Apr-2020924 3223

README.mdH A D18-Apr-20203.4 KiB12684

appveyor.ymlH A D18-Apr-2020578 1918

build.batH A D18-Apr-20201 KiB5139

catch.hppH A D18-Apr-2020416.2 KiB11,6909,202

mustache.hppH A D18-Apr-202040.2 KiB1,1861,003

tests.cppH A D18-Apr-202048.2 KiB1,5051,305

README.md

1# About
2
3* [Mustache](http://mustache.github.io) implementation for modern C++ (requires C++11)
4* Header only
5* Zero dependencies
6* Templated string type for compatibility with any STL-like string (std::string, std::wstring, etc)
7* Boost license
8
9[![travis](https://travis-ci.org/kainjow/Mustache.svg?branch=master)](https://travis-ci.org/kainjow/Mustache) [![appveyor](https://ci.appveyor.com/api/projects/status/6uh5d5weajrffkyw?svg=true)](https://ci.appveyor.com/project/kainjow/mustache) [![codecov](https://codecov.io/gh/kainjow/Mustache/branch/master/graph/badge.svg)](https://codecov.io/gh/kainjow/Mustache)
10
11## Example usage
12
13All examples assume `using namespace kainjow::mustache`. Additional examples and usage can be found in the `tests.cpp` file.
14
15### Example 1 - Hello World
16
17````cpp
18mustache tmpl{"Hello {{what}}!"};
19std::cout << tmpl.render({"what", "World"}) << std::endl;
20// Hello World!
21````
22
23### Example 2 - Lists
24
25````cpp
26mustache tmpl{"{{#employees}}{{name}}, {{/employees}}"};
27data employees{data::type::list};
28employees << data{"name", "Steve"} << data{"name", "Bill"};
29tmpl.render({"employees", employees}, std::cout);
30// Steve, Bill,
31````
32
33### Example 3 - Custom Render Handler
34
35````cpp
36mustache tmpl("Hello {{what}}!");
37std::stringstream ss;
38tmpl.render({"what", "World"}, [&ss](const std::string& str) {
39    ss << str;
40});
41// ss.str() == "Hello World!"
42````
43
44## Supported Features
45
46This library supports all current Mustache features:
47
48- Variables
49- HTML escaping
50- Sections
51- Inverted Sections
52- True/False
53- Lists
54- Lambdas
55- Partials
56- Comments
57- Set Delimiter
58
59Additional features:
60
61- Custom escape function for use outside of HTML
62
63## Run Tests
64
65For *nix:
66
67    make
68
69For macOS:
70
71    make mac
72
73For Visual Studio 2013 (CMake 2.8+ required):
74
75    build.bat
76
77For Visual Studio 2015 (CMake 3.1+ required):
78
79    build.bat 14
80
81## Release Notes
82
83#### 4.1 - April 18, 2020
84
85* Fixed incorrect results when using lambda renderers
86
87#### 4.0 - October 28, 2019
88
89* Lines with sections that result in an empty line are removed, per the Mustache spec.
90
91#### 3.2.1 - July 22, 2018
92
93* Add an overload to render() that accepts a context and a stream (thanks Kitsune Ral)
94* Added checks for empty objects (thanks Snafuuz)
95* Refactored parser in preparation for future changes
96
97#### 3.2 - February 24, 2018
98
99* Added ability to provide a custom escape function (thanks to Kitsune Ral)
100* Allow `data.set()` to override an existing value
101
102#### 3.1 - July 22, 2017
103
104* 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 the `render` argument to render the section text, or any other text.
105
106#### 3.0 - July 8, 2017
107
108* Performance improvements - about 45% faster than version 2
109* Even simpler API. Not backwards compatible but upgrading should be straightforward:
110  * Namespace, classes, and methods are now in snake case to match the STL. For example, `Kainjow::Mustache` is now `kainjow::mustache`
111  * Classes and aliases are now under a `mustache` namespace, instead of being under the mustache class
112  * Removed `Data::List()` - use `data{data::type::list}` instead
113  * Removed `Data::type()` - use the various `is_xxx` methods to identity the type
114
115#### 2.0 - June 11, 2016
116
117* New simpler API (not backwards compatible)
118* std::wstring support
119* Bug fixes (thanks to Shen-Ta Hsieh)
120* Automated tests on OS X
121* 100% test coverage
122
123#### 1.0 - April 19, 2015
124
125* All current Mustache features are implemented.
126