Inheritance: SourceFile
コード例 #1
0
        private string RenderContentForExtension(SourceFile source, string content, string extension, DocumentFile contextDocument, string documentContent, LayoutFile contextLayout)
        {
            RenderingEngine engine;

            if (this.Transaction.Engines.TryGetValue(extension, out engine))
            {
                var backupContent = contextDocument.Content;

                try
                {
                    contextDocument.Content = documentContent;

                    dynamic data = new DynamicRenderDocument(contextDocument, contextLayout, this.Transaction.Site);

                    var result = engine.Render(source, content, data);

                    return result;
                }
                finally
                {
                    contextDocument.Content = backupContent;
                }
            }
            else
            {
                Console.WriteLine("Cannot find a rendering engine for extension: {0}", extension);
                return null;
            }
        }
コード例 #2
0
        private static IEnumerable <LayoutFile> LoadLayouts(string rootPath)
        {
            if (!Directory.Exists(rootPath))
            {
                return(Enumerable.Empty <LayoutFile>());
            }

            return(Directory.GetFiles(rootPath, "*", SearchOption.AllDirectories)
                   .AsParallel()
                   .Select(
                       file =>
            {
                var layoutFile = new LayoutFile(file, rootPath);

                layoutFile.Load();

                return layoutFile;
            }));

            //if (Directory.Exists(rootPath))
            //{
            //    foreach (var file in Directory.GetFiles(rootPath, "*", SearchOption.AllDirectories))
            //    {
            //        var layoutFile = new LayoutFile(file, rootPath);

            //        layoutFile.Load();

            //        yield return layoutFile;
            //    }
            //}
        }
コード例 #3
0
ファイル: ContentRendering.cs プロジェクト: robmen/tinysite
        public string RenderDocumentContentUsingLayout(DocumentFile document, string documentContent, LayoutFile layout)
        {
            var content = this.RenderContentForExtension(layout, layout.SourceContent, layout.Extension, document, documentContent, layout);

            document.AddContributingFile(layout);

            this.AssignLayoutMetadataToDocument(document, layout);

            return content;
        }
コード例 #4
0
        private void RenderDocumentWithLayout(LayoutFile layout, Paginator paginator)
        {
            var content = this.RenderContentForExtension(false, layout.Extension, layout.Content, layout, paginator);

            this.Content = content;

            string parentLayout;

            if (layout.Metadata.TryGet <string>("layout", out parentLayout))
            {
                layout = RenderingTransaction.Current.Layouts[parentLayout];
                this.RenderDocumentWithLayout(layout, paginator);
            }
        }
コード例 #5
0
        public void CanReadDynamicRenderingData()
        {
            var sitePath = @"C:\site\";
            var documentsPath = sitePath + @"documents\";
            var layoutsPath = sitePath + @"layouts\";
            var outputPath = sitePath + @"build\";

            var document = new DocumentFile(documentsPath + "foo.html.md", documentsPath, outputPath + "foo.html", outputPath, String.Empty, String.Empty, null, null, null);
            var layout = new LayoutFile(layoutsPath + "default.cshtml", layoutsPath, String.Empty, null, null);
            var config = new SiteConfig() { OutputPath = outputPath, Url = "http://example.com", RootUrl = String.Empty, };
            var site = new Site(config, Enumerable.Empty<DataFile>(), new[] { document }, Enumerable.Empty<StaticFile>(), new LayoutFileCollection(new[] { layout }));

            dynamic data = new DynamicRenderDocument(document, layout, site);
            Assert.Equal(outputPath, data.Site.OutputPath);
            Assert.Single(data.Site.Documents);

            foreach (var d in data.Site.Documents)
            {
                Assert.Equal(outputPath + "foo.html", d.OutputPath);
            }
        }
コード例 #6
0
ファイル: ContentRendering.cs プロジェクト: robmen/tinysite
 private void AssignLayoutMetadataToDocument(DocumentFile document, LayoutFile layout)
 {
     foreach (var metadataKeyValue in layout.Metadata)
     {
         if (!metadataKeyValue.Key.Equals("Id", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("Extension", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("Layout", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("Modified", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("Name", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("SourcePath", StringComparison.OrdinalIgnoreCase) &&
             !metadataKeyValue.Key.Equals("SourceContent", StringComparison.OrdinalIgnoreCase) &&
             !document.Metadata.Contains(metadataKeyValue.Key))
         {
             document.Metadata.Add(metadataKeyValue.Key, metadataKeyValue.Value);
         }
     }
 }
コード例 #7
0
ファイル: ContentRendering.cs プロジェクト: robmen/tinysite
        private string RenderContentForExtension(SourceFile source, string content, string extension, DocumentFile contextDocument, string documentContent, LayoutFile contextLayout)
        {
            RenderingEngine engine;

            if (this.Transaction.Engines.TryGetValue(extension, out engine))
            {
                var backupContent = contextDocument.Content;

                try
                {
                    contextDocument.Content = documentContent;

                    var data = new DynamicRenderDocument(contextDocument, contextLayout, this.Transaction.Site);

                    var result = engine.Render(source, content, data);

                    return result;
                }
                catch (RuntimeBinderException e)
                {
                    Console.WriteLine("{0} : error TS0101: Internal failure while processing template. This almost always indicates a failure in a Razor template @Include() by this file. Additional detail: {1}", source.SourcePath, e.Message);
                    return String.Empty;
                }
                finally
                {
                    contextDocument.Content = backupContent;
                }
            }
            else
            {
                Console.WriteLine("Cannot find a rendering engine for extension: {0}", extension);
                return null;
            }
        }
コード例 #8
0
        private string RenderContentForExtension(bool renderingSelf, string extension, string template, LayoutFile layout, Paginator paginator)
        {
            var engine = RenderingTransaction.Current.Engines[extension];

            dynamic data = new CaseInsenstiveExpando();

            data.Site      = RenderingTransaction.Current.Site.GetAsDynamic();
            data.Layout    = layout.GetAsDynamic();
            data.Document  = this.GetAsDynamic(renderingSelf);
            data.Paginator = paginator == null ? null : paginator.GetAsDynamic();

            return(engine.Render(template, data));
        }