Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrtazz/plustache
{{mustaches}} for C++
https://github.com/mrtazz/plustache
Last synced: 18 days ago
JSON representation
{{mustaches}} for C++
- Host: GitHub
- URL: https://github.com/mrtazz/plustache
- Owner: mrtazz
- License: mit
- Archived: true
- Created: 2010-04-19T17:20:00.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2019-02-22T13:05:42.000Z (over 5 years ago)
- Last Synced: 2024-07-31T22:46:33.823Z (3 months ago)
- Language: C++
- Homepage: mustache.github.com
- Size: 1.8 MB
- Stars: 202
- Watchers: 17
- Forks: 46
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# plustache - mustache templates for C++
[![Build Status](https://travis-ci.org/mrtazz/plustache.svg?branch=master)](https://travis-ci.org/mrtazz/plustache)
[![Coverage Status](https://coveralls.io/repos/mrtazz/plustache/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrtazz/plustache?branch=master)
[![Packagecloud](https://img.shields.io/badge/packagecloud-available-brightgreen.svg)](https://packagecloud.io/mrtazz/plustache)
[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)Basic port of [mustache templating](http://mustache.github.com) to C++.
## Motivation
I just wanted to port mustache and build simple templating for C++.
And I am still trying hard to keep it simple.## Usage
### Simple Usage
Create a template:```html
{{title}}
Hi I am {{name}}.
I like {{thing}}.
```Fill the context:
```C++
#include
#include
#includeusing std::string;
using PlustacheTypes::ObjectType;
using Plustache::template_t;ObjectType ctx;
ctx["title"] = "About";
ctx["name"] = "Daniel";
ctx["thing"] = "turtles";
```Instantiate template class and render the template:
```C++
template_t t;
string template("{{title}}
\nHi I am {{name}}.\nI like {{thing}}.");string result = t.render(template, ctx);
```Result:
```html
About
Hi I am Daniel.
I like turtles.
```### Advanced Usage
Create the template:```html
{{title}}
- {{name}}
- {{job}}
- {{status}}
{{# friends}}
{{/ friends}}
```
Create the context:
```C++
// create types
context ctx;
CollectionType c;
ObjectType jim;
ObjectType john;
ObjectType jack;
// Fill values
ctx.add("title", "My friends");
jim["name"] = "Jim";
jim["job"] = "Wizard";
jim["status"] = "Eating";
john["name"] = "John";
john["job"] = "Rainbow Painter";
john["status"] = "Sleeping";
jack["name"] = "Jack";
jack["job"] = "Unicorn Trainer";
jack["status"] = "Riding";
// enter data
c.push_back(jim);
c.push_back(john);
ctx.add("friends", c);
// also possible
ctx.add("friends", jack);
```
Render the template:
```C++
template_t t;
string result = t.render(template, ctx);
```
## Installation
There are packages available for some Linux distributions on
[Packagecloud](https://packagecloud.io/mrtazz/plustache).
Otherwise clone this repository and run the manual install task:
git clone git://github.com/mrtazz/plustache.git
autoreconf -i
./configure
make
make install
On OSX you can get it via [my homebrew
tap](https://github.com/mrtazz/homebrew-oss):
brew tap mrtazz/oss
brew install plustache
## Running the unit tests
### Build the google test library:
cd vendor/gtest-1.7.0
./configure
make
On OS X, you may get an error:
vendor/gtest-1.7.0/include/gtest/internal/gtest-port.h:499:13: fatal error:
'tr1/tuple' file not found
# include // NOLINT
If so, re-run configure with the following argument
./configure CPPFLAGS=-DGTEST_USE_OWN_TR1_TUPLE=1
make
### Build the test program
Run this from the top-level plustache source directory:
make test-program
If you get the tr1/tuple error, do:
./configure CPPFLAGS=-DGTEST_USE_OWN_TR1_TUPLE=1
make test-program
### Run the test program
./test-program
### Building with Microsoft Visual Studio
The supplied MSBuild files will look for an installation of boost in the parent
directory of this repo. The boost regex library must be built. For example:
```
cd boost_1_55_0
bootstrap
b2 -j8 toolset=msvc-12.0 address-model=64 --with-regex --prefix=../boost install
```
The boost directories and other build parameters can be
configured by creating a
[Directories.targets](msvc/Directories.targets.example) file.
The gtest project files are generated by cmake. Use a command like this to
recreate the gtest project files:
```
cd msvc/x64/msvc120/gtest
cmake -G "Visual Studio 12 Win64" ../../../../vendor/gtest-1.6.0 -Dgtest_force_shared_crt=ON
```
## Supported Functionality (as described in [the man page](http://mustache.github.com/mustache.5.html))
* Variables
* Sections
* False Values/Empty Lists
* Non-Empty-Lists
* Inverted Sections
* Comments
* Partials
* Set Delimiter
* HTML escape syntax (triple mustaches)
## TODO
* plustache executable
## Dependencies
* boost for regex and some other things
* google test for unit testing (included)