C++ HTML 模板框架、模板化库、HTML 生成器库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/355650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:52:29  来源:igfitidea点击:

C++ HTML template framework, templatizing library, HTML generator library

c++template-engine

提问by Marcin Gil

I am looking for template/generator libraries for C++ that are similar to eg. Ruby's Erb, Haml, PHP's Smarty, etc.

我正在寻找类似于例如的 C++ 模板/生成器库。Ruby 的 Erb、Haml、PHP 的 Smarty 等。

It would be great if I it would sport some basic features like loops, if/else, int conversion to strings, etc.

如果我能使用一些基本功能,比如循环、if/else、int 到字符串的转换等,那就太好了。

Parameter passing to template rendering engine is also important if I could pass all of them in a hash map instead of calling some function for each of parameters.

如果我可以在哈希映射中传递所有参数而不是为每个参数调用某个函数,则传递给模板渲染引擎的参数也很重要。

Do you have any recommendations?

你有什么建议?

I can see also the possibility of embedding languages like Lua, however I haven't found a templatizing library for that either.

我也可以看到嵌入像 Lua 这样的语言的可能性,但是我也没有找到一个模板化库。

采纳答案by Marcin Gil

A quick review of the mentioned project.

对上述项目的快速回顾。

http://rgrz.tumblr.com/post/13808947359/review-of-html-template-engines-in-c-language

http://rgrz.tumblr.com/post/13808947359/review-of-html-template-engines-in-c-language

ClearSilver

清银

Teng

Templatizer

模板器

  • Site: http://www.lazarusid.com/libtemplate.shtml
  • Project: download only
  • Group: none
  • License: free to use
  • Language: C (low level)/C++ (interface) mixed
  • Last Update: unknown
  • Last Release: unknown
  • Document: none
  • Community: none
  • 网站:http: //www.lazarusid.com/libtemplate.shtml
  • 项目:仅下载
  • 组:无
  • 许可证:免费使用
  • 语言:C(低级)/C++(接口)混合
  • 最后更新:未知
  • 最后发布:未知
  • 文件:无
  • 社区:无

HTML Template C++

HTML 模板 C++

ctpp

cp

  • Site: http://ctpp.havoc.ru/en/
  • Project: download only
  • Group: none
  • License: BSD License
  • Language: C++ with C API
  • Last Update: Oct 5, 2011
  • Last Release: Version 2.7.2 on Oct 5, 2011
  • Document: Rich
  • Community: none
  • 网站:http: //ctpp.havoc.ru/en/
  • 项目:仅下载
  • 组:无
  • 许可证:BSD 许可证
  • 语言:C++ 和 C API
  • 最后更新:2011 年 10 月 5 日
  • 最后版本:2011 年 10 月 5 日发布的 2.7.2 版
  • 文档:丰富
  • 社区:无

Wt

重量

Flate

弗拉特

  • Site: http://flate.dead-inside.org/
  • Project: none
  • Group: none
  • License: LGPL v2.1
  • Language: C
  • Last Update: Sep 4, 2010
  • Last Release: 2.0 on Sep 4, 2010
  • Document: Poor
  • Community: none
  • 网站:http: //flatate.dead-inside.org/
  • 项目:无
  • 组:无
  • 许可证:LGPL v2.1
  • 语言:C
  • 最后更新:2010 年 9 月 4 日
  • 最后版本:2010 年 9 月 4 日发布的 2.0
  • 文件:差
  • 社区:无

Jinja2C++

Jinja2C++

回答by Kristian

Grantleeis a string template engine based on the Django template system. It is ported to C++/Qt.

Grantlee是一个基于 Django 模板系统的字符串模板引擎。它被移植到 C++/Qt。

回答by Tomas Andrle

NLTemplateis a small C++ template library with syntax similar to Django.

NLTemplate是一个小型的 C++ 模板库,其语法类似于 Django。

  • Variable replacement
  • Repeatable or optional blocks
  • File includes
  • MIT licensed
  • No external dependencies
  • Single source file, easy to add to any project
  • 变量替换
  • 可重复或可选块
  • 文件包括
  • 麻省理工学院许可
  • 没有外部依赖
  • 单一源文件,易于添加到任何项目

Disclaimer: I'm the author.

免责声明:我是作者。

回答by yesraaj

Wt(pronounced 'witty') is a C++ library and application server for developing and deploying web applications. It is not a 'framework', which enforces a way of programming, but a library.

Wt(发音为“witty”)是一个用于开发和部署 Web 应用程序的 C++ 库和应用程序服务器。它不是一个强制执行编程方式的“框架”,而是一个库。

回答by yesraaj

CTPPis very fast and powerful library written in C++. It has bindings for Perl, PHP and Python.

CTPP是用 C++ 编写的非常快速和强大的库。它具有针对 Perl、PHP 和 Python 的绑定。

回答by wimh

ClearSilveris available for c. Hereis a list of existing websites which use clearsilver. But I don't use it myself.

ClearSilver可用于 c。以下是使用 clearsilver 的现有网站列表。但我自己不使用它。

回答by kirill_igum

facebook's 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"

回答by Sergei Sadovnikov

Jinja2C++

Jinja2C++

Description:

描述:

  • C++14/17 library
  • Supports mainstream compilers (Visual C++, gcc, clang)
  • Easy-to-use interface.
  • Conformance to Jinja2 specification http://jinja.pocoo.org/docs/2.10/
  • Support for both narrow- and wide-character strings both for templates and - parameters.
  • Built-in reflection for C++ types and popular json libraries (nlohmann, RapidJson).
  • User-defined callables.
  • Powerful full-featured Jinja2 expressions with filtering (via ‘|' operator) and ‘if'-expressions.
  • Big set of Jinja2 tags include macros and template extensions.
  • Rich error reporting.
  • C++14/17 库
  • 支持主流编译器(Visual C++、gcc、clang)
  • 易于使用的界面。
  • 符合 Jinja2 规范http://jinja.pocoo.org/docs/2.10/
  • 支持模板和 - 参数的窄字符串和宽字符串。
  • C++ 类型和流行的 json 库(nlohmann、RapidJson)的内置反射。
  • 用户定义的可调用对象。
  • 强大的全功能 Jinja2 表达式,带有过滤(通过“|”运算符)和“i​​f”表达式。
  • 大量 Jinja2 标签包括宏和模板扩展。
  • 丰富的错误报告。

回答by Mark

I have tried using template engine and Dynamic C++ Pages provided by the ffead-cpp framework, an example implementation is shown on the wiki

我曾尝试使用 ffead-cpp 框架提供的模板引擎和动态 C++ 页面,wiki 上显示了一个示例实现

回答by OJW