项目作者: mapx

项目描述 :
Google Closure Templates C++ adapter
高级语言: C++
项目地址: git://github.com/mapx/cpp-closure-templates.git
创建时间: 2013-05-31T09:47:05Z
项目社区:https://github.com/mapx/cpp-closure-templates

开源协议:MIT License

下载


cpp-closure-templates

Google Closure Templates’ C++ adapter.

It calls the official java interpreter from a jar ball through java jni interface.

Installation

  1. Download soy closure-templates source files:
    1. # Non-members may check out a read-only working copy anonymously over HTTP.
    2. svn checkout http://closure-templates.googlecode.com/svn/trunk/ closure-templates-read-only
  2. Modify build.xml to pack the template files, global parameters file and SoyHandler.java with closure-templates’ stuff into the final jar ball.
  3. Modify three macros in src/cpp/soy_handler.h:

    1. MAPX_SOY_JAR_FILE
    2. MAPX_RESOURCE_NAMESPACE
    3. MAPX_SOYHANDLER_IN_JAR
  4. Use SoyHandler::render() to render a template of tpl_name with data json_map and locale. Then use SoyHandler::ngx_str() to fetch the result string in a special object (it’s nginx’s inner string type). The string is available until the next render call. No need to release the result string’s memory.

FAQ

Q: Why return an nginx string object rather than a null ended string?

There is no end_of_string character like C in Java. By returning an nginx string we make zero copy of the result string.

Q: Why do you have these large functions kept in .h file, not in .cpp file? It’s not good to inline large function.

Just for convenience. A modern c++ compile can tell whether to inline a function and make a good choice.

Q: Will you write a native c++ templates interpreter?

It depends. I wish to write it, too.

Q: The code is ugly.

Indeed.