项目作者: kainjow

项目描述 :
Mustache text templates for modern C++
高级语言: C++
项目地址: git://github.com/kainjow/Mustache.git
创建时间: 2015-04-11T18:23:45Z
项目社区:https://github.com/kainjow/Mustache

开源协议:Boost Software License 1.0

下载


About

  • Mustache 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

travis appveyor ghe codecov

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

  1. mustache tmpl{"Hello {{what}}!"};
  2. std::cout << tmpl.render({"what", "World"}) << std::endl;
  3. // Hello World!

Example 2 - Lists

  1. mustache tmpl{"{{#employees}}{{name}}, {{/employees}}"};
  2. data employees{data::type::list};
  3. employees << data{"name", "Steve"} << data{"name", "Bill"};
  4. tmpl.render({"employees", employees}, std::cout);
  5. // Steve, Bill,

Example 3 - Custom Render Handler

  1. mustache tmpl("Hello {{what}}!");
  2. std::stringstream ss;
  3. tmpl.render({"what", "World"}, [&ss](const std::string& str) {
  4. ss << str;
  5. });
  6. // 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