2016-05-24 11:47:31 +02:00
|
|
|
#include "Lexesis/template.h"
|
2016-05-25 18:30:26 +02:00
|
|
|
#include "mstch/mstch.hpp"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2016-05-24 11:47:31 +02:00
|
|
|
|
|
|
|
namespace lxs {
|
|
|
|
namespace templ {
|
2016-05-25 18:30:26 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-24 11:47:31 +02:00
|
|
|
Template::Template(std::string filename) : m_filename(filename)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Template::~Template()
|
|
|
|
{}
|
|
|
|
|
2016-05-25 18:30:26 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-05-24 11:47:31 +02:00
|
|
|
}
|
|
|
|
}
|