Giter Site home page Giter Site logo

plustache's Introduction

plustache - mustache templates for C++

Basic port of mustache templating 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:

<h1>{{title}}</h1>
Hi I am {{name}}.
I like {{thing}}.

Fill the context:

ObjectType ctx;
ctx["title"] = "About";
ctx["name"] = "Daniel";
ctx["thing"] = "turtles";

Instantiate template class and render the template:

template_t t;
string result = t.render(template, ctx);

Result:

<h1>About</h1>
Hi I am Daniel.
I like turtles.

Advanced Usage

Create the template:

<h1> {{title}} </h1>
<ul>
  {{# friends}}
    <li> {{name}}</li>
    <li> {{job}}</li>
    <li> {{status}}</li>
  {{/ friends}}
</ul>

Create the context:

// 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:

template_t t;
string result = t.render(template, ctx);

Installation

Clone this repository:

git clone git://github.com/mrtazz/plustache.git

Run the install tasks:

autoreconf -i
./configure
make
make install

Or you can get it via homebrew:

brew install plustache

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 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)

  • 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

plustache's People

Contributors

joshuanapoli avatar mrtazz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.