Example #1
0
 private IActionResult build(PageStack pageStack, HtmlDocumentRenderer dr)
 {
     try
     {
         return(getConvertedDocument(pageStack, dr));
     }
     catch (DirectoryNotFoundException)
     {
         //If the source file cannot be read offer to create the new file instead.
         if (targetFileInfo.PathCanCreateFile)
         {
             return(showNewPage(pageStack, dr));
         }
         else
         {
             throw;
         }
     }
     catch (FileNotFoundException ex)
     {
         //If the source file cannot be read offer to create the new file instead.
         if (targetFileInfo.PathCanCreateFile)
         {
             var sb = new StringBuilder($"Could not find file '{ex.FileName}' Message: '{ex.Message}' building page '{pageStack.ContentFile}'. Showing new page.");
             WriteSearchLocations(sb, ex as PageStackFileNotFoundException);
             logger.LogInformation(sb.ToString());
             return(showNewPage(pageStack, dr));
         }
         else
         {
             throw;
         }
     }
 }
Example #2
0
        private IActionResult buildAsPage(PageStack pageStack, String layout)
        {
            HtmlDocumentRenderer dr = new HtmlDocumentRenderer(templateEnvironment);

            dr.addTransform(new HashTreeMenus(fileFinder));
            dr.addTransform(new ExpandRootedPaths(this.HttpContext.Request.PathBase));
            pageStack.pushLayout(layout);
            return(build(pageStack, dr));
        }
Example #3
0
        public void buildPage(String relativeFile)
        {
            relativeFile = relativeFile.TrimStartingPathChars();

            var outFile = Path.Combine(this.outDir, relativeFile);

            if (OutputExtension != null)
            {
                outFile = Path.ChangeExtension(outFile, OutputExtension);
            }

            ITargetFileInfo     fileInfo    = fileInfoProvider.GetFileInfo(relativeFile, null);
            TemplateEnvironment environment = new TemplateEnvironment(fileInfo.FileNoExtension, fileFinder, overrideValuesProvider.OverrideVars, version, true);
            PageStack           pageStack   = new PageStack(environment, fileFinder);

            pageStack.ContentFile = fileInfo.HtmlFile;
            if (pageStack.Visible)
            {
                var pageSettings = fileFinder.GetProjectPageDefinition(fileInfo);
                var layout       = pageSettings.Layout;
                if (OutputExtension != null)
                {
                    layout = Path.ChangeExtension(layout, OutputExtension);
                }
                pageStack.pushLayout(layout);

                var pathBase = environment.PathBase;

                HtmlDocumentRenderer dr = new HtmlDocumentRenderer(environment);
                dr.addTransform(new HashTreeMenus(fileFinder));
                dr.addTransform(new ExpandRootedPaths(pathBase));
                if (!String.IsNullOrEmpty(pathBase))
                {
                    //Safe to fix relative urls last since it wont replace any that already start with the path base.
                    dr.addTransform(new FixRelativeUrls(pathBase));
                }
                var document = dr.getDocument(pageStack.Pages);
                var outDir   = Path.GetDirectoryName(outFile);
                if (!Directory.Exists(outDir))
                {
                    Directory.CreateDirectory(outDir);
                }
                using (var writer = new StreamWriter(File.Open(outFile, FileMode.Create, FileAccess.Write, FileShare.None)))
                {
                    writer.Write(document.DocumentNode.OuterHtml);
                }
                fileFinder.CopyLinkedFiles(this.outDir, pageStack);
            }
        }
Example #4
0
        private IActionResult showNewPage(PageStack pageStack, HtmlDocumentRenderer dr)
        {
            switch (branchDetector.Phase)
            {
            case Phases.Draft:
                pageStack.pushLayout("notfound.html");
                pageStack.ContentFile = null;
                break;

            case Phases.Edit:
                pageStack = new PageStack(templateEnvironment, fileFinder);
                pageStack.pushLayout("new.html");
                break;
            }
            return(getConvertedDocument(pageStack, dr));
        }
Example #5
0
        private IActionResult buildAsEditor(PageStack pageStack, String layout)
        {
            if (!fileFinder.DoesLayoutExist(layout))
            {
                layout = "default.html"; //Change layout to default.html if the layout does not exist, this way we at least return a page
            }
            HtmlDocumentRenderer dr = new HtmlDocumentRenderer(templateEnvironment);

            switch (branchDetector.Phase)
            {
            case Phases.Draft:
                pageStack.pushLayout("draft.html");
                foreach (var editStackItem in fileFinder.Project.DraftComponents)
                {
                    pageStack.pushLayout(editStackItem);
                }

                pageStack.pushLayout(layout);
                pageStack.pushLayout("editarea-noedit.html");
                break;

            case Phases.Edit:
                pageStack.pushLayout("edit.html");
                foreach (var editStackItem in fileFinder.Project.EditComponents)
                {
                    pageStack.pushLayout(editStackItem);
                }

                pageStack.pushLayout(layout);
                pageStack.pushLayout("editarea-ckeditor.html");
                dr.addTransform(new CreateSettingsForm());
                dr.addTransform(new CreateTreeMenuEditor());
                break;
            }

            dr.addTransform(new HashTreeMenus(fileFinder));
            dr.addTransform(new ExpandRootedPaths(this.HttpContext.Request.PathBase));

            return(build(pageStack, dr));
        }
Example #6
0
        private IActionResult getConvertedDocument(PageStack pageStack, HtmlDocumentRenderer dr)
        {
            var document = dr.getDocument(pageStack.Pages);

            return(Content(document.DocumentNode.OuterHtml, new MediaTypeHeaderValue("text/html")));
        }
        public static IRenderer Create(ElementTypes elementTypes, object element)
        {
            switch (elementTypes)
            {
            case ElementTypes.Heading:

                if (element is Heading heading)
                {
                    var renderer = new HtmlHeadingRenderer(heading);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.Document:

                if (element is Document document)
                {
                    var renderer = new HtmlDocumentRenderer(document);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.Hyperlink:

                if (element is Hyperlink hyperlink)
                {
                    var renderer = new HtmlHyperlinkRenderer(hyperlink);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.Paragraph:

                if (element is Paragraph paragraph)
                {
                    var renderer = new HtmlParagraphRenderer(paragraph);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.Image:

                if (element is Image image)
                {
                    var renderer = new HtmlImageRenderer(image);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.TextElement:

                if (element is TextElement textElement)
                {
                    var renderer = new HtmlTextElementRenderer(textElement);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            case ElementTypes.Font:

                if (element is Font font)
                {
                    var renderer = new HtmlFontRenderer(font);
                    return(renderer);
                }
                else
                {
                    throw new InvalidCastException("Invalid element type");
                }

            default:
                throw new NotSupportedException("Not suportet Element Type");
            }
        }