示例#1
0
// Tests that multiple mustache tags are replaced
BOOST_FIXTURE_TEST_CASE(TestMultipleMustacheFromString, TemplateFixture)
{
	template_string = "<title>{{title}}</title>\n";
	template_string += "Hi I am {{name}}{{lastname}}.\n";
	template_string += "I like {{pet}}.{{!comment}}\n";

	set_tag_value("title", "Multiple Mustaches");
	set_tag_value("name", "Daniel");
	set_tag_value("pet", "turtles");

	generate_template();

	std::string expected = "<title>Multiple Mustaches</title>\n";
	expected += "Hi I am Daniel.\n";
	expected += "I like turtles.\n";
	BOOST_CHECK_EQUAL(expected, result);
}
示例#2
0
int SendTemplate(MHD_Connection* connection, bool redirect, const char* redirectUrl) {
    SkString debuggerTemplate = generate_template(SkString(FLAGS_source[0]));

    MHD_Response* response = MHD_create_response_from_buffer(
        debuggerTemplate.size(),
        (void*) const_cast<char*>(debuggerTemplate.c_str()),
        MHD_RESPMEM_MUST_COPY);
    MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");

    int status = MHD_HTTP_OK;

    if (redirect) {
        MHD_add_response_header (response, "Location", redirectUrl);
        status = MHD_HTTP_SEE_OTHER;
    }

    int ret = MHD_queue_response(connection, status, response);
    MHD_destroy_response(response);
    return ret;
}
// Tests that a simple mustache tag is replaced
BOOST_FIXTURE_TEST_CASE(TestSectionMustacheFromString, TemplateFixture)
{
	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}}";

	set_tag_value("name", "Daniel");
	set_tag_value("pet", "turtles");
	set_tag_value("showme", "true");
	set_tag_value("showme2", "true");

	generate_template();

	std::string expected = "Hi I am Daniel.\n";
	expected += "I like turtles.\n";
	expected += "If you don't see this, something went wrong.";
	BOOST_CHECK_EQUAL(expected, result);
}