mstch abstraction in template done

This commit is contained in:
Thomas Ave 2016-05-25 18:30:26 +02:00
parent 90e7427c4b
commit 2b66d58138
2 changed files with 34 additions and 3 deletions

View File

@ -5,10 +5,11 @@
#include <map>
#include <string>
#include <vector>
#include <mstch/mstch.hpp>
namespace lxs {
namespace templ {
using TemplateContext = void*;
using TemplateContext = mstch::node;
TemplateContext make_string(std::string);
TemplateContext make_map(std::map<std::string, TemplateContext>);

View File

@ -1,14 +1,44 @@
#include "Lexesis/template.h"
#include "mstch/mstch.hpp"
#include <fstream>
#include <string>
#include <sstream>
namespace lxs {
namespace templ {
TemplateContext make_string(std::string _string) {
return mstch::node(_string);
}
TemplateContext make_map(std::map<std::string, TemplateContext> _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<TemplateContext> _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);
}
}
}