private void RegisterHandlebarsTemplates() { if (!VeilStaticConfiguration.IsParserRegistered("handlebars")) { VeilStaticConfiguration.RegisterParser(new HandlebarsTemplateParserRegistration()); } context.RegisterTemplate("role", "{{ this }}"); context.RegisterTemplate("master", "Hello {{ Name }} {{body}} See Ya!"); }
private void RegisterSuperSimpleTemplates() { if (!VeilStaticConfiguration.IsParserRegistered("supersimple")) { VeilStaticConfiguration.RegisterParser(new SuperSimpleParserRegistration()); } context.RegisterTemplate("Role", "@Current;"); context.RegisterTemplate("Roles", "<ul>@Each.Current;<li>@Partial['Role'];</li>@EndEach;</ul>"); context.RegisterTemplate("Department", "@Model.DepartmentName @Model.Company.CompanyName"); context.RegisterTemplate("Master", "Hello @Model.Name; @Section['Middle'] See Ya!"); context.RegisterTemplate("MiddleMaster", "@Master['Master'] @Section['Middle']from @Model.Department.DepartmentName @Section['Content'];@EndSection"); }
private static ITemplateParser GetParser(string parserKey) { if (String.IsNullOrEmpty(parserKey)) { throw new ArgumentNullException("parserKey"); } if (!VeilStaticConfiguration.IsParserRegistered(parserKey)) { throw new ArgumentException("A parser with key '{0}' is not registered.".FormatInvariant(parserKey), "parserKey"); } var parser = VeilStaticConfiguration.GetParserInstance(parserKey); return(parser); }
/// <summary> /// Parses and compiles the specified template /// </summary> /// <typeparam name="T">The type of the model that will be passed to the template</typeparam> /// <param name="parserKey">Key of the <see cref="ITemplateParser"/> to use to parse the template.</param> /// <param name="templateContents">The contents of the template to compile</param> /// <returns>A compiled action ready to be executed as needed to render the template</returns> public Action <TextWriter, T> Compile <T>(string parserKey, TextReader templateContents) { if (String.IsNullOrEmpty(parserKey)) { throw new ArgumentNullException("parserKey"); } if (templateContents == null) { throw new ArgumentNullException("templateContents"); } if (!VeilStaticConfiguration.IsParserRegistered(parserKey)) { throw new ArgumentException("A parser with key '{0}' is not registered.".FormatInvariant(parserKey), "parserKey"); } var parser = VeilStaticConfiguration.GetParserInstance(parserKey); var syntaxTree = parser.Parse(templateContents, typeof(T)); return(new VeilTemplateCompiler <T>(CreateIncludeParser(parserKey, context)).Compile(syntaxTree)); }