private void ProcessDependenciesCore(string outputDirectory, IEnumerable <TemplateBundle> templateBundles) { foreach (var resourceInfo in templateBundles.SelectMany(s => s.Resources).Distinct()) { try { // TODO: support glob pattern if (resourceInfo.IsRegexPattern) { var regex = new Regex(resourceInfo.ResourceKey, RegexOptions.IgnoreCase); foreach (var name in _resourceProvider.Names) { if (regex.IsMatch(name)) { using (var stream = _resourceProvider.GetResourceStream(name)) { ProcessSingleDependency(stream, outputDirectory, name); } } } } else { using (var stream = _resourceProvider.GetResourceStream(resourceInfo.ResourceKey)) { ProcessSingleDependency(stream, outputDirectory, resourceInfo.FilePath); } } } catch (Exception e) { Logger.Log(LogLevel.Info, $"Unable to get relative resource for {resourceInfo.FilePath}: {e.Message}"); } } }
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 static string ExpandMasterPage(ResourceCollection resource, TemplateRendererResource info, Regex masterRegex, Regex bodyRegex) { var template = info.Content; var templateName = info.TemplateName; var masterPageResourceName = ExtractMasterPageResourceName(resource, info, masterRegex).FirstOrDefault(); template = masterRegex.Replace(template, string.Empty); if (masterPageResourceName != null) { using (var stream = resource.GetResourceStream(masterPageResourceName)) { if (stream != null) { using (var sr = new StreamReader(stream)) { var master = sr.ReadToEnd(); if (bodyRegex.IsMatch(master)) { return(bodyRegex.Replace(master, template)); } else { Logger.LogInfo($"Master page {masterPageResourceName} does not contain {{{{!body}}}} element, content in current template {templateName} is ignored."); return(master); } } } } } return(template); }
private void ProcessDependenciesCore(string outputDirectory, IEnumerable <TemplateBundle> templateBundles) { foreach (var resourceInfo in templateBundles.SelectMany(s => s.Resources).Distinct()) { try { using (var stream = _resourceProvider.GetResourceStream(resourceInfo.ResourceKey)) { ProcessSingleDependency(stream, outputDirectory, resourceInfo.ResourceKey); } } catch (Exception e) { Logger.Log(LogLevel.Info, $"Unable to get relative resource for {resourceInfo.ResourceKey}: {e.Message}"); } } }