package org.born.gendoctor;

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;

import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by ThiagoBorn on 18/05/2016.
 */
public class Templates {

  public static Template getTemplate(String name) {
    try {
      Mustache.Compiler compiler = Mustache.compiler()
        .withLoader((tplName) -> new InputStreamReader(Templates.class.getResourceAsStream("/partials/" + tplName + ".mustache")));
      InputStream resourceAsStream = Templates.class.getResourceAsStream("/templates/" + name + ".mustache");
      InputStreamReader source = new InputStreamReader(resourceAsStream);
      return compiler.compile(source);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}
