Skip to content

mapx/cpp-closure-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

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:
# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://closure-templates.googlecode.com/svn/trunk/ closure-templates-read-only
  1. Modify build.xml to pack the template files, global parameters file and SoyHandler.java with closure-templates' stuff into the final jar ball.
  2. Modify three macros in src/cpp/soy_handler.h:
MAPX_SOY_JAR_FILE
MAPX_RESOURCE_NAMESPACE
MAPX_SOYHANDLER_IN_JAR
  1. 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.

About

Google Closure Templates C++ adapter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published