我正在寻找与C ++类似的C ++模板/生成器库。 Ruby的Erb,Haml,PHP的Smarty等等。
如果我会使用循环,if / else,int转换为字符串等基本功能,那将会很棒。
如果我可以在哈希映射中传递所有这些参数而不是为每个参数调用某个函数,那么传递给模板渲染引擎的参数也很重要。
你有什么建议吗?
我也可以看到嵌入像Lua这样的语言的可能性,但是我还没有找到一个模板库。
答案 0 :(得分:50)
快速回顾上述项目。
http://rgrz.tumblr.com/post/13808947359/review-of-html-template-engines-in-c-language
答案 1 :(得分:7)
Grantlee是一个基于Django模板系统的字符串模板引擎。它被移植到C ++ / Qt。
答案 2 :(得分:6)
答案 3 :(得分:3)
Wt(发音为'witty')是一个用于开发和部署Web应用程序的C ++库和应用程序服务器。它不是一个“框架”,它强制执行一种编程方式,而是一个库。
答案 4 :(得分:3)
CTPP是用C ++编写的非常快速和强大的库。它具有Perl,PHP和Python的绑定。
答案 5 :(得分:2)
ClearSilver可用于c。 Here是使用clearsilver的现有网站列表。但我自己不用它。
答案 6 :(得分:2)
facebook的format:
std::cout << format("The answers are {} and {}", 23, 42);
// => "The answers are 23 and 42"
std::map<std::string, std::string> m { {"what", "answer"}, {"value", "42"} };
std::cout << vformat("The only {what} is {value}", m);
// => "The only answer is 42"
答案 7 :(得分:1)
我尝试过使用ffead-cpp框架提供的模板引擎和动态C ++页面,wiki
上显示了一个示例实现答案 8 :(得分:1)
答案 9 :(得分:1)
我最初在搜索时错过了NLTemplate,编写了自己的C ++模板引擎,显然与NLTemplate类似: - )
https://github.com/hughperkins/Jinja2CppLight
答案 10 :(得分:0)
我开发了here之后为c ++建模jade的东西。它需要一个简单但功能强大的输入语言,并创建一个将HTML写入流的单个c ++模板函数。
< html
< h1 The title is ${{ params["title"] }}& >
< ul >
& for(int i = 0; i < boost::get<int>(params["items"]); ++i) {
< li Item ${{ i }}$ >
& }
>
答案 11 :(得分:0)
Templtext是一个小型C ++文本模板处理库。它支持类似bash的变量(%VAR或%{VAR})。但主要功能是支持用户定义的功能。图书馆是我创建的。
需要BOOST正则表达式库,但在下一个版本中它将被替换为std :: regex
示例1:
using namespace templtext;
Templ * t = new Templ( "Dear %SALUTATION %NAME. I would like to invite you for %TEXT. Sincerely yours, %MYNAME." );
std::map<std::string, std::string> tokens01 =
{
{ "SALUTATION", "Mr." },
{ "NAME", "John Doe" },
{ "TEXT", "an interview" },
{ "MYNAME", "Ty Coon" }
};
std::map<std::string, std::string> tokens02 =
{
{ "SALUTATION", "Sweetheart" },
{ "NAME", "Mary" },
{ "TEXT", "a cup of coffee" },
{ "MYNAME", "Bob" }
};
std::cout << t->format( tokens01 ) << std::endl;
std::cout << t->format( tokens02 ) << std::endl;
输出:
Dear Mr. John Doe. I would like to invite you for an interview. Sincerely yours, Ty Coon.
Dear Sweetheart Mary. I would like to invite you for a cup of coffee. Sincerely yours, Bob.
示例2:
using namespace templtext;
std::unique_ptr<Templ> tf1( new Templ( "You have got an $decode( 1 )." ) );
std::unique_ptr<Templ> tf2( new Templ( "You have got an $decode( 2 )." ) );
std::unique_ptr<Templ> tf3( new Templ( "English version - $decode_loc( 1, EN )." ) );
std::unique_ptr<Templ> tf4( new Templ( "German version - $decode_loc( 1, DE )." ) );
std::unique_ptr<Templ> tf5( new Templ( "Flexible version - $decode_loc( 1, %LANG )." ) );
tf1->set_func_proc( func );
tf2->set_func_proc( func );
tf3->set_func_proc( func );
tf4->set_func_proc( func );
tf5->set_func_proc( func );
Templ::MapKeyValue map1 =
{
{ "LANG", "EN" }
};
Templ::MapKeyValue map2 =
{
{ "LANG", "DE" }
};
std::cout << tf1->format() << std::endl;
std::cout << tf2->format() << std::endl;
std::cout << tf3->format() << std::endl;
std::cout << tf4->format() << std::endl;
std::cout << tf5->format( map1 ) << std::endl;
std::cout << tf5->format( map2 ) << std::endl;
输出:
You have got an apple.
You have got an orange.
English version - apple.
German version - Apfel.
Flexible version - apple.
Flexible version - Apfel.
答案 12 :(得分:0)
Jinja2C ++
说明: