#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<const std::string, TemplateContext> _map) {
        return mstch::map(_map);
    }
    
    TemplateContext make_array(std::vector<TemplateContext> _array) {
       return mstch::array(_array);
    }


    Template::Template(std::string filename) : m_filename(filename)
    {}

    Template::~Template()
    {}

    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);
    }
}
}
