diff --git a/src/lib/text-template.hpp b/src/lib/text-template.hpp index ac9d87769..6529229af 100644 --- a/src/lib/text-template.hpp +++ b/src/lib/text-template.hpp @@ -36,10 +36,15 @@ #include "lib/error.hpp" +#include "lib/nocopy.hpp" +#include "lib/iter-explorer.hpp" +#include "lib/format-util.hpp" //#include "lib/util.hpp" //#include //#include +#include +#include //#include //#include @@ -49,6 +54,79 @@ namespace lib { // using Rat = boost::rational; // using boost::rational_cast; // using std::abs; + using std::string; + + + namespace {// preconfigured TextTemplate data bindings + + } + + + /** + * Text template substitution engine + */ + class TextTemplate + : util::MoveOnly + { + enum Clause { + IF, FOR + }; + enum Code { + TEXT, KEY, COND, JUMP, ITER, LOOP + }; + + struct ParseCtx + { + Clause clause; + }; + + struct Action + { + Code code; + string val; + }; + + template + struct Instance + { + + }; + + using PipeTODO = std::vector; + using InstanceIter = decltype (explore (std::declval())); + + public: + TextTemplate(string spec) + { } + + template + InstanceIter + render (DAT const& data) const; + + template + static string + apply (string spec, DAT const& data); + }; + + + + /** */ + template + inline TextTemplate::InstanceIter + TextTemplate::render (DAT const& data) const + { + UNIMPLEMENTED ("actually instantiate the text template"); + } + + /** */ + template + inline string + TextTemplate::apply (string spec, DAT const& data) + { + return util::join (TextTemplate(spec).render (data) + ,""); + } + }// namespace lib diff --git a/tests/library/text-template-test.cpp b/tests/library/text-template-test.cpp index c7efbc953..1f45066fa 100644 --- a/tests/library/text-template-test.cpp +++ b/tests/library/text-template-test.cpp @@ -34,6 +34,7 @@ //#include //#include +#include //using std::array; @@ -41,6 +42,8 @@ namespace lib { namespace test { + using MapS = std::map; + /***************************************************************************//** * @test verify a minimalistic text substitution engine with flexible @@ -69,12 +72,16 @@ namespace test { } - /** @test TODO - * @todo WIP 4/24 🔁 define ⟶ implement + /** @test TODO simple point-and-shot usage... + * @todo WIP 4/24 ✔ define ⟶ 🔁 implement */ void simpeUsage() { + MapS snaps{{"whatever", "cruel world"} + ,{"greeting", "farewell"}}; + CHECK (TextTemplate::apply ("${greeting} ${whatever} ↯", snaps) + == "farewell cruel world ↯"_expect); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 8597fbaf0..8ce262d16 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -112482,8 +112482,8 @@ std::cout << tmpl.render({"what", "World"}) << s - - + + @@ -112507,18 +112507,63 @@ std::cout << tmpl.render({"what", "World"}) << s - - + + + + + + + + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -112533,6 +112578,21 @@ std::cout << tmpl.render({"what", "World"}) << s + + + + + + + + + + + + + + + @@ -112546,20 +112606,251 @@ std::cout << tmpl.render({"what", "World"}) << s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + +