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 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);
 }
Exemple #3
0
 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(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();
        }
Exemple #5
0
        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();
        }