diff --git a/include/Lexesis/template.h b/include/Lexesis/template.h index 5f59c83..d8e76c9 100644 --- a/include/Lexesis/template.h +++ b/include/Lexesis/template.h @@ -5,10 +5,11 @@ #include #include #include +#include namespace lxs { namespace templ { - using TemplateContext = void*; + using TemplateContext = mstch::node; TemplateContext make_string(std::string); TemplateContext make_map(std::map); diff --git a/src/template.cpp b/src/template.cpp index 42bfe39..ec60b18 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -1,14 +1,44 @@ #include "Lexesis/template.h" +#include "mstch/mstch.hpp" + +#include +#include +#include namespace lxs { namespace templ { + + TemplateContext make_string(std::string _string) { + return mstch::node(_string); + } + + TemplateContext make_map(std::map _map) { + // return mstch::node(_map); -> g++ goes mental.. + mstch::map result; + for(auto& item: _map) { + result[item.first] = item.second; + } + return result; + } + + TemplateContext make_array(std::vector _array) { + return mstch::node(_array); + } + + Template::Template(std::string filename) : m_filename(filename) {} Template::~Template() {} - void Template::render(std::ostream&, TemplateContext&) - {} + void Template::render(std::ostream& out, TemplateContext& context) { + std::ifstream file; + file.open (m_filename); + std::stringstream tmplt; + tmplt << file.rdbuf(); + file.close(); + out << mstch::render(tmplt.str(),context); + } } }