public void ApplyTemplate(string filename, string templatecode, object datasource) {
     var templatetxt = GetTemplate(templatecode);
     var jsonfilename = filename + ".file.tg.json";
 	var json = myapp.ioc.get<IJsonTransformer>().ToJson(datasource);
     var newtxt = new TemplateGenerator(templatetxt, datasource).Generate();
     myapp.files.Write(filename,newtxt);
     myapp.files.Write(jsonfilename,json);
 }
 public string GetTemplateJSON(string code) {
     var file = Enumerable.FirstOrDefault<string>(myapp.files.ResolveAll("~/", code + ".template.json", true, true));
     if (null != file) return File.ReadAllText(file);
     var template = GetTemplate(code);
     var tg = new TemplateGenerator(template);
     var substs = tg.GetSubstitutions();
     var condtions = tg.GetConditions();
     var s = "{\r\n";
     foreach (var subst in substs) {
         s += string.Format("'{0}':{type:'string', value='',},\r\n", subst);
     }
     foreach (var cond in condtions)
     {
         s += string.Format("'{0}':{type:'bool', value=false,},\r\n", cond);
     }
     s += "}";
     return s;
 }