Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/moldPublic

C++ Template Engine Library

License

NotificationsYou must be signed in to change notification settings

duzy/mold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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).

Introduction

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.

Notes

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.

Examples

#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

TODO

  • 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.

Supported Formats

Themold engine supports multiple template domain languages. Currently it has:

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp