- Notifications
You must be signed in to change notification settings - Fork2
C++ Template Engine Library
License
duzy/mold
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Mold is aC++ Text Engine. It's a header-only library for generatingtext from a template and a set of data (feed).
Templates can be defined in different domain languages, here now we alreadyhaveMustache andTildache, could implement moretext domain languages. And the data set (feeds the template) is containedbymold::object
. Text templates written in a domain language(such asTildache) are compiled into aMoldprogram(a sequence of operations) and further executed by the virtualmachine to create the text output.
The engine is running on a stacked-based virtual machine. Which executes asequence of text operations (seeops.hpp
) and renders desired text(defined by the template) to astd::ostream
. The virtual machine is notfor generic computing. Instead, it focuses on text processing. So theregisters arestd::string
based, rather thenint
orfloat
. But it dosupports some basic arithmatic and logical computation.
Themold engine is inspired byBoostache. Reasons why I startedmold as a new project and deprecatedBoostache are:
- Boostache is still buggy (e.g. not fully working with theMustache spec).
- Boostache source code seems to be immature so far and not updated.
The primary goal ofmold is at least a fully workingMustache engine.The long term (possible) goals are:
- Performance improvement: avoid many string copy operations.
- Support multiple domain languages afterMustache is done.
- Mordern C++ design and C++1z friendly.
- Persistant byte code representation.
#include<mold/mold.hpp>#include<mold/format/mustache.hpp>#include<mold/format/mustache.ipp>#include<iostream>static std::string MUSTACHE_EXAMPLE{u8R"***(//" Dear {{FirstName}}, It's been long time since we last met. {{Story}} Best Regards, {{MyName}})***" +4};//";intmain(int argc,char**argv){ mold::object feed { {"FirstName","Tony" }, {"MyName","Mold" }, {"Story","Blah blah blah... Here goes a very long story..." }, };auto t = mold::load<mold::format::mustache>(MUSTACHE_EXAMPLE);mold::generate(std::cout, t, feed);return0;}
Expected result onstd::cout
:
Dear Tony, It's been long time since we last met. Blah blah blah... Here goes a very long story... Best Regards, Mold
- Get rid of boost::spirit, wirte parser from scratch instead to make it zero dependency and standalone
- Improve performance for string processing, reduce copies, memory allocaition, etc.
Themold engine supports multiple template domain languages. Currently it has:
- Mustache - Logic-less templates.
- Tildache - A variant ofMustache withtild extensions. (*)