/// <summary>
        /// Generates a <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCodeDocument" /> for the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorProjectItem" />.</param>
        /// <returns>The created <see cref="T:Microsoft.AspNetCore.Razor.Language.RazorCodeDocument" />.</returns>
        // Token: 0x06000468 RID: 1128 RVA: 0x00009EB8 File Offset: 0x000080B8
        public virtual Microsoft.AspNetCore.Razor.Language.RazorCodeDocument CreateCodeDocument(Microsoft.AspNetCore.Razor.Language.RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }
            if (!projectItem.Exists)
            {
                throw new InvalidOperationException($"FormatRazorTemplateEngine_ItemCouldNotBeFound {projectItem.FilePath}");
            }
            Microsoft.AspNetCore.Razor.Language.RazorSourceDocument source = Microsoft.AspNetCore.Razor.Language.RazorSourceDocument.ReadFrom(projectItem);
            IEnumerable <Microsoft.AspNetCore.Razor.Language.RazorSourceDocument> imports = this.GetImports(projectItem);

            return(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument.Create(source, imports));
        }
Ejemplo n.º 2
0
        public void CreateCodeDocument_NullImportFileName_IncludesDefaultImportIfNotNull()
        {
            // Arrange
            var projectItem    = new TestRazorProjectItem("/Views/Home/Index.cshtml");
            var project        = new TestRazorProjectFileSystem(new[] { projectItem });
            var razorEngine    = RazorEngine.Create();
            var defaultImport  = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml");
            var templateEngine = new RazorTemplateEngine(razorEngine, project)
            {
                Options =
                {
                    DefaultImports = defaultImport,
                }
            };

            // Act
            var codeDocument = templateEngine.CreateCodeDocument(projectItem);

            // Assert
            Assert.Collection(codeDocument.Imports,
                              import => Assert.Same(defaultImport, import));
        }
Ejemplo n.º 3
0
        public void ProcessDesignTime_WithImportsAndTagHelpers_SetsOnCodeDocument()
        {
            // Arrange
            var projectItem        = new TestRazorProjectItem("Index.cshtml");
            var importItem         = new TestRazorProjectItem("_import.cshtml");
            var expectedImports    = new[] { RazorSourceDocument.ReadFrom(importItem) };
            var expectedTagHelpers = new[]
            {
                TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly").Build(),
                TagHelperDescriptorBuilder.Create("Test2TagHelper", "TestAssembly").Build(),
            };

            var projectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, TestRazorProjectFileSystem.Empty);

            // Act
            var codeDocument = projectEngine.ProcessDesignTime(RazorSourceDocument.ReadFrom(projectItem), expectedImports, expectedTagHelpers);

            // Assert
            var tagHelpers = codeDocument.GetTagHelpers();

            Assert.Same(expectedTagHelpers, tagHelpers);
            Assert.Equal(expectedImports, codeDocument.Imports);
        }
Ejemplo n.º 4
0
        protected internal RazorCodeDocument CreateCodeDocumentCore(
            RazorSourceDocument sourceDocument,
            string fileKind = null,
            IReadOnlyList <RazorSourceDocument> importSourceDocuments          = null,
            IReadOnlyList <TagHelperDescriptor> tagHelpers                     = null,
            Action <RazorParserOptionsBuilder> configureParser                 = null,
            Action <RazorCodeGenerationOptionsBuilder> configureCodeGeneration = null)
        {
            if (sourceDocument == null)
            {
                throw new ArgumentNullException(nameof(sourceDocument));
            }

            importSourceDocuments = importSourceDocuments ?? Array.Empty <RazorSourceDocument>();

            var parserOptions = GetRequiredFeature <IRazorParserOptionsFactoryProjectFeature>().Create(fileKind, builder =>
            {
                ConfigureParserOptions(builder);
                configureParser?.Invoke(builder);
            });
            var codeGenerationOptions = GetRequiredFeature <IRazorCodeGenerationOptionsFactoryProjectFeature>().Create(fileKind, builder =>
            {
                ConfigureCodeGenerationOptions(builder);
                configureCodeGeneration?.Invoke(builder);
            });

            var codeDocument = RazorCodeDocument.Create(sourceDocument, importSourceDocuments, parserOptions, codeGenerationOptions);

            codeDocument.SetTagHelpers(tagHelpers);

            if (fileKind != null)
            {
                codeDocument.SetFileKind(fileKind);
            }

            return(codeDocument);
        }
        protected RazorCodeDocument CreateCodeDocumentCore(
            RazorProjectItem projectItem,
            Action <RazorParserOptionsBuilder> configureParser,
            Action <RazorCodeGenerationOptionsBuilder> configureCodeGeneration)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException(nameof(projectItem));
            }

            var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);

            var importItems = new List <RazorProjectItem>();
            var features    = ProjectFeatures.OfType <IImportProjectFeature>();

            foreach (var feature in features)
            {
                importItems.AddRange(feature.GetImports(projectItem));
            }

            var importSourceDocuments = GetImportSourceDocuments(importItems);

            return(CreateCodeDocumentCore(sourceDocument, projectItem.FileKind, importSourceDocuments, tagHelpers: null, configureParser, configureCodeGeneration, cssScope: projectItem.CssScope));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets <see cref="T:RazorSourceDocument" /> that are applicable to the specified <paramref name="projectItem" />.
        /// </summary>
        /// <param name="projectItem">The <see cref="T:RazorProjectItem" />.</param>
        /// <returns>The sequence of applicable <see cref="T:RazorSourceDocument" />.</returns>
        public virtual IEnumerable <RazorSourceDocument> GetImports(RazorProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }

            var list = new List <RazorSourceDocument>();

            foreach (var razorProjectItem in this.GetImportItems(projectItem))
            {
                if (razorProjectItem.Exists)
                {
                    list.Insert(0, RazorSourceDocument.ReadFrom(razorProjectItem));
                }
            }

            if (this.Options.DefaultImports != null)
            {
                list.Insert(0, this.Options.DefaultImports);
            }

            return(list);
        }
Ejemplo n.º 7
0
 public ClassifiedSpanVisitor(RazorSourceDocument source)
 {
     _source           = source;
     _spans            = new List <ClassifiedSpanInternal>();
     _currentBlockKind = BlockKindInternal.Markup;
 }
Ejemplo n.º 8
0
 public override void Visit(RazorSyntaxTree tree)
 {
     _source = tree.Source;
     Visit(tree.Root);
 }
 public static RazorCodeDocument Create(RazorSourceDocument source, IEnumerable <RazorSourceDocument> imports)
 {
     return(new DefaultRazorCodeDocument(source, imports));
 }
Ejemplo n.º 10
0
 public virtual RazorCodeDocument ProcessDesignTime(RazorSourceDocument source, string fileKind, IReadOnlyList <RazorSourceDocument> importSources, IReadOnlyList <TagHelperDescriptor> tagHelpers)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public TagHelperSpanVisitor(RazorSourceDocument source)
 {
     _source = source;
     _spans  = new List <TagHelperSpanInternal>();
 }
 private NamespaceVisitor(RazorSourceDocument source)
 {
     _source = source;
 }
Ejemplo n.º 13
0
 public Verifier(RazorSourceDocument source)
 {
     _currentLocation = new SourceLocation(source.FilePath, 0, 0, 0);
     _source          = source;
 }
Ejemplo n.º 14
0
 public abstract RazorCodeDocument Process(RazorSourceDocument sourceDocument);
Ejemplo n.º 15
0
 internal virtual RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorSourceDocument source, IReadOnlyList <RazorSourceDocument> importSources, IReadOnlyList <TagHelperDescriptor> tagHelpers)
 {
     return(RazorCodeDocument.Create(source, importSources));
 }
Ejemplo n.º 16
0
 public Verifier(RazorSourceDocument source)
 {
     _tracker = new SourceLocationTracker(new SourceLocation(source.FilePath, 0, 0, 0));
     _source  = source;
 }
 public DefaultRazorSourceLineCollection(RazorSourceDocument document)
 {
     _document   = document;
     _lineStarts = GetLineStarts();
 }