public void RegisterTemplate(string templateName, Func <string> content) { templateName = templateName.ToLowerInvariant(); if (!registeredTemplates.Contains(templateName)) { VariableNameValidator.ValidateSuffix(templateName); registeredTemplates.Add(templateName); var templateContent = content(); templateContent = SanitizeContent(templateContent); var code = string.Format( @"var {0}_source = '{1}'; var chevronTemplate_{0} = Handlebars.compile({0}_source);", templateName, templateContent); engine.Execute(code); } }
public void RegisterTemplate(string templateName, Func <string> content) { Guard.AgainstNullAndEmpty(templateName, "templateName"); if (char.IsNumber(templateName[0])) { throw new ArgumentException("'templateName' cannot start with a number.", "templateName"); } templateName = templateName.ToLowerInvariant(); if (!registeredTemplates.Contains(templateName)) { VariableNameValidator.ValidateSuffix(templateName); registeredTemplates.Add(templateName); var templateContent = content(); templateContent = SanitizeContent(templateContent); var code = string.Format( @"var {0}_source = '{1}'; var chevronTemplate_{0} = Handlebars.compile({0}_source);", templateName, templateContent); engine.Execute(code); } }