2015-04-24 07:35:29 +08:00
|
|
|
# mstch - {{mustache}} templates in C++11
|
|
|
|
|
2015-04-24 18:29:58 +08:00
|
|
|
![mstch logo](http://i.imgur.com/XAdHwUs.png)
|
2015-04-24 18:16:03 +08:00
|
|
|
|
2015-04-24 07:35:29 +08:00
|
|
|
mstch is a complete implementation of [{{mustache}}](http://mustache.github.io/) templates using modern C++.
|
2015-04-24 07:48:42 +08:00
|
|
|
|
2015-04-24 07:35:29 +08:00
|
|
|
[![Build Status](https://travis-ci.org/no1msd/mstch.svg?branch=master)](https://travis-ci.org/no1msd/mstch)
|
|
|
|
|
2015-04-24 18:25:24 +08:00
|
|
|
## Supported features
|
|
|
|
|
|
|
|
mstch supports the complete feature set described in the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html):
|
|
|
|
|
|
|
|
- JSON-like data structure using [Boost.Variant](http://www.boost.org/doc/libs/1_57_0/doc/html/variant.html)
|
|
|
|
- variables, sections, inverted sections
|
|
|
|
- partials
|
|
|
|
- changing the delimiter
|
|
|
|
- C++11 lambdas
|
|
|
|
- C++ objects as view models
|
|
|
|
|
2015-04-24 07:35:29 +08:00
|
|
|
## Basic usage
|
|
|
|
|
|
|
|
```c++
|
|
|
|
#include <iostream>
|
|
|
|
#include <mstch/mstch.hpp>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
std::string view{"{{#names}}Hi {{name}}!\n{{/names}}"};
|
|
|
|
mstch::map context{
|
|
|
|
{"names", mstch::array{
|
2015-04-24 07:37:09 +08:00
|
|
|
mstch::map{{"name", std::string{"Chris"}}},
|
|
|
|
mstch::map{{"name", std::string{"Mark"}}},
|
|
|
|
mstch::map{{"name", std::string{"Scott"}}},
|
|
|
|
}}
|
2015-04-24 07:35:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
std::cout << mstch::render(view, context) << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
The output of this example will be:
|
|
|
|
|
|
|
|
```
|
2015-04-24 07:48:42 +08:00
|
|
|
Hi Chris!
|
|
|
|
Hi Mark!
|
|
|
|
Hi Scott!
|
2015-04-24 07:35:29 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
- A C++ compiler with decent C++11 support. Currently only tested with GCC 4.9.
|
|
|
|
- Boost 1.54
|
|
|
|
- CMake for building
|
|
|
|
|
2015-04-24 07:48:42 +08:00
|
|
|
## Installing
|
2015-04-24 07:35:29 +08:00
|
|
|
|
|
|
|
From the root of the source tree:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ mkdir build
|
|
|
|
$ cd build
|
|
|
|
$ cmake ..
|
|
|
|
$ make
|
2015-04-24 07:48:42 +08:00
|
|
|
$ make install
|
2015-04-24 07:35:29 +08:00
|
|
|
```
|
|
|
|
|
2015-04-24 07:48:42 +08:00
|
|
|
### Running the unit tests
|
2015-04-24 07:35:29 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ mkdir build
|
|
|
|
$ cd build
|
|
|
|
$ cmake -DWITH_UNIT_TESTS=ON ..
|
|
|
|
$ make
|
|
|
|
$ make test
|
|
|
|
```
|
|
|
|
|
2015-04-24 07:48:42 +08:00
|
|
|
## Advanced usage
|
2015-04-24 07:35:29 +08:00
|
|
|
|
|
|
|
TODO
|