コード例 #1
0
ファイル: Razor.cs プロジェクト: schulz3000/Wyam
        /// <summary>
        /// Gets the view for an input document (which is different than the view for a layout, partial, or
        /// other indirect view because it's not necessarily on disk or in the file system).
        /// </summary>
        private IView GetViewFromStream(string relativePath, Stream stream, string viewStartLocation, string layoutLocation,
                                        IRazorViewEngine viewEngine, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder,
                                        IRazorPageFactoryProvider pageFactoryProvider, IFileProvider rootFileProvider, IRazorCompilationService razorCompilationService)
        {
            IEnumerable <string> viewStartLocations = viewStartLocation != null
                ? new [] { viewStartLocation }
                : ViewHierarchyUtility.GetViewStartLocations(relativePath);
            List <IRazorPage> viewStartPages = viewStartLocations
                                               .Select(pageFactoryProvider.CreateFactory)
                                               .Where(x => x.Success)
                                               .Select(x => x.RazorPageFactory())
                                               .Reverse()
                                               .ToList();
            IRazorPage page = GetPageFromStream(relativePath, viewStartLocation, layoutLocation, stream, rootFileProvider, razorCompilationService);

            if (layoutLocation != null)
            {
                page.Layout = layoutLocation;
            }
            return(new RazorView(viewEngine, pageActivator, viewStartPages, page, htmlEncoder));
        }
コード例 #2
0
ファイル: RazorCompiler.cs プロジェクト: olevett/Wyam-1
        /// <summary>
        /// Gets the view for an input document (which is different than the view for a layout, partial, or
        /// other indirect view because it's not necessarily on disk or in the file system).
        /// </summary>
        private IView GetViewFromStream(IServiceProvider serviceProvider, RenderRequest request, IRazorPage page)
        {
            IEnumerable <string> viewStartLocations = request.ViewStartLocation != null
                ? new[] { request.ViewStartLocation }
                : ViewHierarchyUtility.GetViewStartLocations(request.RelativePath);

            List <IRazorPage> viewStartPages = viewStartLocations
                                               .Select(serviceProvider.GetRequiredService <IRazorPageFactoryProvider>().CreateFactory)
                                               .Where(x => x.Success)
                                               .Select(x => x.RazorPageFactory())
                                               .Reverse()
                                               .ToList();

            if (request.LayoutLocation != null)
            {
                page.Layout = request.LayoutLocation;
            }

            IRazorViewEngine    viewEngine    = serviceProvider.GetRequiredService <IRazorViewEngine>();
            IRazorPageActivator pageActivator = serviceProvider.GetRequiredService <IRazorPageActivator>();
            HtmlEncoder         htmlEncoder   = serviceProvider.GetRequiredService <HtmlEncoder>();

            return(new RazorView(viewEngine, pageActivator, viewStartPages, page, htmlEncoder));
        }
コード例 #3
0
        /// <summary>
        /// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each
        /// <c>_ViewImports</c> that is applicable to the page located at <paramref name="pagePath"/>. The list is
        /// ordered so that the <see cref="CodeTree"/> for the <c>_ViewImports</c> closest to the
        /// <paramref name="pagePath"/> in the file system appears first.
        /// </summary>
        /// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
        /// <returns>A <see cref="IReadOnlyList{CodeTree}"/> of parsed <c>_ViewImports</c>
        /// <see cref="CodeTree"/>s.</returns>
        public virtual IReadOnlyList <CodeTree> GetInheritedCodeTrees([NotNull] string pagePath)
        {
            var inheritedCodeTrees = new List <CodeTree>();
            var templateEngine     = new RazorTemplateEngine(_razorHost);

            foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath))
            {
                // viewImportsPath contains the app-relative path of the _ViewImports.
                // Since the parsing of a _ViewImports would cause parent _ViewImports to be parsed
                // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations
                // for the current _ViewImports to succeed.
                var codeTree = _codeTreeCache.GetOrAdd(viewImportsPath,
                                                       fileInfo => ParseViewFile(templateEngine,
                                                                                 fileInfo,
                                                                                 viewImportsPath));

                if (codeTree != null)
                {
                    inheritedCodeTrees.Add(codeTree);
                }
            }

            return(inheritedCodeTrees);
        }