CollectionsTest()
    {
        template_string = "Hi I am {{me}}.\n";
        template_string += "{{# people}}";
        template_string += "Hi {{me}}, I am {{name}}, I do {{work}}.";
        template_string += "{{/ people}}";
        template_single_string = "Hi I am {{me}}.\n";
        template_single_string += "{{# people}}";
        template_single_string += "Hi {{name}}!";
        template_single_string += "{{/ people}}";

        // single entry
        PlustacheTypes::ObjectType tom;
        PlustacheTypes::ObjectType jerry;
        tom["name"] = "Tom";
        Plustache::Context ctx_single;
        ctx_single.add("me", "Daniel");
        ctx_single.add("people",tom);

        // multiple entries
        jerry["name"] = "Jerry";
        PlustacheTypes::CollectionType b_multiple;
        b_multiple.push_back(tom);
        b_multiple.push_back(jerry);
        Plustache::Context ctx_multiple;
        ctx_multiple.add("me", "Daniel");
        ctx_multiple.add("people", b_multiple);

        // multiple fields
        tom["work"] = "Accounting";
        jerry["work"] = "Magic";
        PlustacheTypes::CollectionType b_multiple_fields;
        b_multiple_fields.push_back(tom);
        Plustache::Context ctx;
        ctx.add("me", "Daniel");
        ctx.add("people", b_multiple_fields);
        ctx.add("people", jerry);



        Plustache::template_t t;
        result_single = t.render(template_single_string, ctx_single);
        result_multiple = t.render(template_single_string, ctx_multiple);
        result_multiple_fields = t.render(template_string, ctx);
    }
Beispiel #2
0
std::string shader<Stage>::render_source_(const std::string& source, const parameters_t& params) {
#ifdef USE_PLUSTACHE
    PlustacheTypes::ObjectType ctx;
    for (const auto& param : params) {
        ctx[param.first] = param.second;
    }
    Plustache::template_t t;
    return t.render(source, ctx);
#else
    return source;
#endif // USE_PLUSTACHE
}
    virtual void SetUp()
    {
        template_string = "Hi I am {{name}}.\n";
        template_string += "{{# showme}}";
        template_string += "I like {{pet}}.\n";
        template_string += "{{# showme2}}";
        template_string += "If you don't see this, something went wrong.";
        template_string += "{{/ showme2}}";
        template_string += "{{/ showme}}";
        file = "sections.mustache";

        std::ofstream myfile;
        myfile.open (file.c_str());
        myfile << template_string;
        myfile.close();

        ctx["name"] = "Daniel";
        ctx["pet"] = "turtles";
        ctx["showme"] = "true";
        ctx["showme2"] = "true";
        Plustache::template_t t;
        result_string = t.render(template_string, ctx);
        result_file = t.render(file, ctx);
    }