public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) { return(null); } var resourceName = name + PartialTemplateExtension; return(_templateCache.GetOrAdd(resourceName, s => { lock (_resourceProvider) { using (var stream = _resourceProvider.GetResourceStream(s)) { if (stream == null) { return null; } var template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) { template.Load(reader); } return template; } } })); }
public Nustache.Core.Template TestNustache() { var template = new Nustache.Core.Template(); template.Load(new StringReader(TextTemplateMustache)); return(template); }
public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) return null; var resourceName = name + PartialTemplateExtension; Nustache.Core.Template template; if (!_templateCache.TryGetValue(resourceName, out template)) { using (var stream = _resourceProvider.GetResourceStream(resourceName)) { if (stream == null) { return null; } template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) { template.Load(reader); } _templateCache[resourceName] = template; } } return template; }
public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) { return(null); } var resourceName = name + PartialTemplateExtension; Nustache.Core.Template template; if (!_templateCache.TryGetValue(resourceName, out template)) { using (var stream = _resourceProvider.GetResourceStream(resourceName)) { if (stream == null) { return(null); } template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) { template.Load(reader); } _templateCache[resourceName] = template; } } return(template); }
public MustacheTemplateRenderer(ResourceCollection resourceProvider, TemplateRendererResource info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (info.Content == null) { throw new ArgumentNullException(nameof(info.Content)); } if (info.TemplateName == null) { throw new ArgumentNullException(nameof(info.TemplateName)); } _templateName = info.TemplateName; _resourceTemplateLocator = new ResourceTemplateLocator(resourceProvider); _resource = resourceProvider; _template = new Nustache.Core.Template(); using (var reader = new StringReader(info.Content)) { _template.Load(reader); } Dependencies = ExtractDependencyResourceNames(info.Content).ToList(); }
public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) return null; var resourceName = name + PartialTemplateExtension; return _templateCache.GetOrAdd(resourceName, s => { lock (_resourceProvider) { using (var stream = _resourceProvider.GetResourceStream(s)) { if (stream == null) { return null; } var template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) { template.Load(reader); } return template; } } }); }
public MustacheTemplateRenderer(ResourceCollection resourceProvider, string template) { if (template == null) throw new ArgumentNullException(nameof(template)); _resourceTemplateLocator = new ResourceTemplateLocator(resourceProvider); _template = new Nustache.Core.Template(); using (var reader = new StringReader(template)) _template.Load(reader); Dependencies = ExtractDependentFilePaths(template); }
public MustacheTemplateRenderer(ResourceCollection resourceProvider, string template) { if (template == null) { throw new ArgumentNullException(nameof(template)); } _resourceTemplateLocator = new ResourceTemplateLocator(resourceProvider); _template = new Nustache.Core.Template(); using (var reader = new StringReader(template)) _template.Load(reader); Dependencies = ExtractDependentFilePaths(template); }
public BenchRenderers() { var parsers = new BenchParsers(); _scribanTemplate = parsers.TestScriban(); _dotLiquidTemplate = parsers.TestDotLiquid(); _stubbleTemplate = parsers.TestStubble(); _stubbleSettings = new Stubble.Core.Settings.RendererSettingsBuilder().BuildSettings(); _nustacheTemplate = parsers.TestNustache(); _handlebarsTemplate = parsers.TestHandlebars(); _cottleTemplate = parsers.TestCottle(); _fluidTemplate = parsers.TestFluid(); _razorTemplate = parsers.TestRazor(); const int ProductCount = 500; _products = new List <Product>(ProductCount); _scribanProducts = new List <ScriptObject>(); _dotLiquidProducts = new List <DotLiquid.Hash>(ProductCount); var cottleValues = new List <Cottle.Value>(); for (int i = 0; i < ProductCount; i++) { var product = new Product("Name" + i, i, Lorem); _products.Add(product); var hash = new Hash() { ["name"] = product.Name, ["price"] = product.Price, ["description"] = product.Description }; _dotLiquidProducts.Add(hash); var obj = new ScriptObject { ["name"] = product.Name, ["price"] = product.Price, ["description"] = product.Description }; _scribanProducts.Add(obj); cottleValues.Add(new Cottle.Values.ReflectionValue(product)); } _liquidTemplateContext = new LiquidTemplateContext(); // For Cottle, we match the behavior of Scriban that is accessing the Truncate function via an reflection invoke // In Scriban, we could also have a direct Truncate function, but it is much less practical in terms of declaration _cottleStringStore = new Dictionary <Cottle.Value, Cottle.Value>(); _cottleStringStore["truncate"] = new Cottle.Functions.NativeFunction((values, store, Output) => { if (values.Count != 2) { throw new InvalidOperationException("Unexpected number of arguments for truncate function"); } return(StringFunctions.Truncate(values[0].AsString, Convert.ToInt32(values[1].AsNumber))); }, 2); }
public BenchRenderers() { var parsers = new BenchParsers(); _scribanTemplate = parsers.TestScriban(); _dotLiquidTemplate = parsers.TestDotLiquid(); _stubbleTemplate = parsers.TestStubble(); _stubbleSettings = new Stubble.Core.Settings.RendererSettingsBuilder().BuildSettings(); _nustacheTemplate = parsers.TestNustache(); _handlebarsTemplate = parsers.TestHandlebars(); _cottleTemplate = parsers.TestCottle(); _fluidTemplate = parsers.TestFluid(); const int ProductCount = 500; _products = new List <Product>(ProductCount); _scribanProducts = new List <ScriptObject>(); _dotLiquidProducts = new List <DotLiquid.Hash>(ProductCount); var cottleProducts = new List <Cottle.Value>(); for (int i = 0; i < ProductCount; i++) { var product = new Product("Name" + i, i, Lorem); _products.Add(product); var hash = new Hash() { ["name"] = product.Name, ["price"] = product.Price, ["description"] = product.Description }; _dotLiquidProducts.Add(hash); var obj = new ScriptObject { ["name"] = product.Name, ["price"] = product.Price, ["description"] = product.Description }; _scribanProducts.Add(obj); var value = new Dictionary <Cottle.Value, Cottle.Value> { ["name"] = product.Name, ["price"] = product.Price, ["description"] = product.Description }; cottleProducts.Add(value); } _cottleProducts = cottleProducts; _templateContext = new TemplateContext(); _templateContext.BuiltinObject["truncate"] = ((ScriptObject)_templateContext.BuiltinObject["string"])["truncate"]; // For Cottle, we match the behavior of Scriban that is accessing the Truncate function via an reflection invoke // In Scriban, we could also have a direct Truncate function, but it is much less practical in terms of declaration _cottleStringStore = new Dictionary <Cottle.Value, Cottle.Value>(); _cottleStringStore["truncate"] = new Cottle.Functions.NativeFunction(values => StringFunctions.Truncate(values[0].AsString, Convert.ToInt32(values[1].AsNumber)), 2); }
public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) return null; var resourceName = name + PartialTemplateExtension; using (var stream = _resourceProvider.GetResourceStream(resourceName)) { if (stream == null) return null; var template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) template.Load(reader); return template; } }
public Nustache.Core.Template GetTemplate(string name) { if (_resourceProvider == null) { return(null); } var resourceName = name + PartialTemplateExtension; using (var stream = _resourceProvider.GetResourceStream(resourceName)) { if (stream == null) { return(null); } var template = new Nustache.Core.Template(name); using (StreamReader reader = new StreamReader(stream)) template.Load(reader); return(template); } }
private Nustache.Core.Template LoadMustacheTemplate(string templateId) { templateId = templateId.Trim(); if (templateId.EndsWith(".mustache")) { templateId = templateId.Remove(templateId.Length - ".mustache".Length); } string controlId = string.Format("{0}MustacheTemplate", templateId); var literal = control.FindControlRecursive(controlId) as Literal; if (literal != null) { string mustacheTemplateText = literal.Text; TextReader reader = new StringReader(mustacheTemplateText); var template = new Nustache.Core.Template(templateId); template.Load(reader); return template; } return null; }
public BenchRenderers() { var parsers = new BenchParsers(); _scribanTemplate = parsers.TestScriban(); _dotLiquidTemplate = parsers.TestDotLiquid(); _stubbleTemplate = parsers.TestStubble(); _stubbleSettings = new Stubble.Core.Settings.RendererSettingsBuilder().BuildSettings(); _nustacheTemplate = parsers.TestNustache(); _handlebarsTemplate = parsers.TestHandlebars(); const int ProductCount = 500; _products = new List <Product>(ProductCount); _dotLiquidProducts = new List <DotLiquid.Hash>(ProductCount); for (int i = 0; i < ProductCount; i++) { var product = new Product("Name" + i, i, Lorem); _products.Add(product); _dotLiquidProducts.Add(DotLiquid.Hash.FromAnonymousObject(product)); } }
public MustacheTemplateRenderer(IResourceFileReader reader, ResourceInfo info, string name = null) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (info.Content == null) { throw new ArgumentNullException(nameof(info.Content)); } if (info.Path == null) { throw new ArgumentNullException(nameof(info.Path)); } Path = info.Path; Name = name ?? System.IO.Path.GetFileNameWithoutExtension(Path); _reader = reader; _resourceTemplateLocator = new ResourceTemplateLocator(reader); _template = new Nustache.Core.Template(); var processedTemplate = ParseTemplateHelper.ExpandMasterPage(reader, info, MasterPageRegex, MasterPageBodyRegex); using (var sr = new StringReader(processedTemplate)) { try { _template.Load(sr); } catch (Nustache.Core.NustacheException e) { throw new DocfxException($"Error in mustache template {info.Path}: {e.Message}", e); } } Dependencies = ExtractDependencyResourceNames(processedTemplate).ToList(); }
public MustacheTemplateRenderer(ResourceCollection resourceProvider, TemplateRendererResource info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (info.Content == null) { throw new ArgumentNullException(nameof(info.Content)); } if (info.TemplateName == null) { throw new ArgumentNullException(nameof(info.TemplateName)); } _templateName = info.TemplateName; _resource = resourceProvider; _resourceTemplateLocator = new ResourceTemplateLocator(resourceProvider); _template = new Nustache.Core.Template(); var processedTemplate = ParseTemplateHelper.ExpandMasterPage(resourceProvider, info, MasterPageRegex, MasterPageBodyRegex); using (var reader = new StringReader(processedTemplate)) { try { _template.Load(reader); } catch (Nustache.Core.NustacheException e) { throw new DocfxException($"Error in mustache template {info.TemplateName}: {e.Message}", e); } } Dependencies = ExtractDependencyResourceNames(processedTemplate).ToList(); }