/// <summary>
        /// Loads file orders from files in directories.
        /// </summary>
        /// <param name="rootFolder">The root folder representing the Input folder.</param>
        public static void LoadOrders(SidenavFolder rootFolder)
        {
            string folderPath      = rootFolder.InputFolderPath;
            string orderConfigPath = Path.Combine(folderPath, "order.config");

            if (File.Exists(orderConfigPath))
            {
                string   configContents = Utils.GetFullFileConent(orderConfigPath);
                string[] lines          = configContents.Split(Configuration.NewlineChars, StringSplitOptions.None);
                foreach (string line in lines)
                {
                    int spacePos = line.IndexOf(' ');
                    if (spacePos != -1)
                    {
                        int order;
                        if (int.TryParse(line.Substring(0, spacePos), out order))
                        {
                            string fileName      = line.Substring(spacePos + 1);
                            string inputFilePath = Path.Combine(rootFolder.InputFolderPath, fileName);
                            if (File.Exists(inputFilePath))
                            {
                                foreach (SidenavFile file in rootFolder.Files)
                                {
                                    if (file.InputFilePath == inputFilePath)
                                    {
                                        if (file.Order == 0)
                                        {
                                            file.Order = order;
                                        }
                                    }
                                }
                            }

                            if (Directory.Exists(inputFilePath))
                            {
                                foreach (SidenavFolder folder in rootFolder.Folders)
                                {
                                    if (folder.InputFolderPath == inputFilePath)
                                    {
                                        if (folder.Order == 0)
                                        {
                                            folder.Order = order;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (SidenavFolder folder in rootFolder.Folders)
            {
                LoadOrders(folder);
            }
        }
 /// <summary>
 /// Returns absolute folder path of the folder inside Input directory.
 /// </summary>
 /// <param name="folder">Folder to get the path of.</param>
 /// <returns>Absolute folder path.</returns>
 public static string GetAbsoluteFolderPath(this SidenavFolder folder)
 {
     if (folder.FolderName == "root")
     {
         return(string.Empty);
     }
     else
     {
         return(Path.Combine(folder.Parent.GetAbsoluteFolderPath(), folder.RelativeHtmlLink));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Replaces html <IsThisFolder> and <IsNotThisFolder> with html content (within <ForAllSubFolders> tag).
        /// </summary>
        /// <param name="forAllSubFoldersContent">Html content to replace <ForAllSubFolders> tag.</param>
        /// <param name="currentFolderInLoop">Current folder we are copying an instance of <ForAllPages> for.</param>
        /// <param name="currentPageFile">Current file being built.</param>
        /// <returns>Returns Html content with <IsThisFolder> and <IsNotThisFolder> converted into pure Html.</returns>
        private static string HandleThisFolderSpecialTags(string forAllSubFoldersContent, SidenavFolder currentFolderInLoop, SidenavFile currentPageFile)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(forAllSubFoldersContent);
            IEnumerable <HtmlNode> show, hide;
            bool          isThisFolder = false;
            SidenavFolder loopFolder   = currentPageFile.Parent;

            if (loopFolder == currentFolderInLoop)
            {
                isThisFolder = true;
            }

            while (loopFolder.Parent != null && !isThisFolder)
            {
                if (loopFolder.Parent == currentFolderInLoop)
                {
                    isThisFolder = true;
                }

                loopFolder = loopFolder.Parent;
            }

            if (isThisFolder)
            {
                show = Utils.CloneListNotValues(doc.DocumentNode.Descendants("IsThisFolder".ToLower(Configuration.Culture)));
                hide = Utils.CloneListNotValues(doc.DocumentNode.Descendants("IsNotThisFolder".ToLower(Configuration.Culture)));
            }
            else
            {
                hide = Utils.CloneListNotValues(doc.DocumentNode.Descendants("IsThisFolder".ToLower(Configuration.Culture)));
                show = Utils.CloneListNotValues(doc.DocumentNode.Descendants("IsNotThisFolder".ToLower(Configuration.Culture)));
            }

            foreach (HtmlNode showNode in show)
            {
                foreach (HtmlNode childNode in showNode.ChildNodes)
                {
                    showNode.ParentNode.InsertBefore(childNode, showNode);
                }

                showNode.ParentNode.RemoveChild(showNode);
            }

            foreach (HtmlNode hideNode in hide)
            {
                hideNode.ParentNode.RemoveChild(hideNode);
            }

            return(doc.DocumentNode.OuterHtml);
        }
        /// <summary>
        /// Generates documentation.
        /// </summary>
        public void Generate()
        {
            if (!TemplateManager.CheckRequiredTemplatesExist(templateFolderPath))
            {
                return;
            }

            Utils.ClearDirectory(outputFolderPath);
            rootFolder = TreeParser.LoadRootInputFolder(inputFolderPath);
            PageManager.LoadOrders(rootFolder);
            templates = TemplateManager.LoadTemplates(templateFolderPath);
            BuildFolder(rootFolder);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the absolute link to a page in sidenav.
        /// </summary>
        /// <param name="file">File to get link from.</param>
        /// <returns>Absolute link starting with '/'.</returns>
        public static string GetAbsoluteLink(this SidenavFile file)
        {
            StringBuilder builder      = new StringBuilder(file.RelativeHtmlLink);
            SidenavFolder parentFolder = file.Parent;

            builder.Insert(0, $"{parentFolder.RelativeHtmlLink}/");
            while (parentFolder.Parent != null)
            {
                parentFolder = parentFolder.Parent;
                builder.Insert(0, $"{parentFolder.RelativeHtmlLink}/");
            }

            return(builder.ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// Generates html content which should replace the <ForAllFolders> tag.
        /// </summary>
        /// <param name="rootFolder">Sidenav folder which represents as the Input folder.</param>
        /// <param name="currentFile">The file currently being built for.</param>
        /// <param name="allSubFolderContent">Html content of <ForAllSubFolders> tag to be repeated.</param>
        /// <param name="allPagesContent">Html content of <ForAllSubPages> tag to be repeated.</param>
        /// <param name="layer">Integer representing the depth of the current folder from the Input folder.</param>
        /// <returns>Returns html content to replace the <ForAllFolders> tag.</returns>
        private static string GetHtmlToReplaceForAllFoldersTag(SidenavFolder rootFolder, SidenavFile currentFile, string allSubFolderContent, string allPagesContent, int layer)
        {
            StringBuilder forAllContent = new StringBuilder();

            List <SidenavElement> elmts = new List <SidenavElement>();

            foreach (SidenavFolder folder in rootFolder.Folders)
            {
                elmts.Add(folder);
            }

            foreach (SidenavFile file in rootFolder.Files)
            {
                elmts.Add(file);
            }

            IOrderedEnumerable <SidenavElement> orderedElmts = elmts.OrderBy(o => o.Order);

            foreach (SidenavElement elmt in orderedElmts)
            {
                if (elmt is SidenavFolder)
                {
                    SidenavFolder folder                    = (SidenavFolder)elmt;
                    string        folderContent             = GetHtmlToReplaceForAllFoldersTag(folder, currentFile, allSubFolderContent, allPagesContent, layer + 1);
                    string        allSubFolderFilledContent = allSubFolderContent.Replace("@SubFolder.Name;", folder.FolderName);
                    allSubFolderFilledContent = allSubFolderFilledContent.Replace("@SubFolder.Layer;", layer.ToString());
                    allSubFolderFilledContent = HandleThisFolderSpecialTags(allSubFolderFilledContent, folder, currentFile);
                    allSubFolderFilledContent = allSubFolderFilledContent.Replace("@SubFolder.Recursive;", folderContent);
                    forAllContent.Append(allSubFolderFilledContent);
                }
                else
                {
                    SidenavFile file        = (SidenavFile)elmt;
                    string      pageContent = allPagesContent;
                    pageContent = HandleThisPageSpecialTags(pageContent, file, currentFile);
                    foreach (PProperty property in file.Properties)
                    {
                        pageContent = pageContent.Replace($"@SubPage.{property.Name};", property.Value);
                    }

                    pageContent = pageContent.Replace("@SubPage.Layer;", layer.ToString());
                    pageContent = pageContent.Replace("@SubPage.Link;", file.GetAbsoluteLink());
                    pageContent = pageContent.Replace("@SubPage.Id;", file.Id);
                    forAllContent.Append(pageContent);
                }
            }

            return(forAllContent.ToString());
        }
        /// <summary>
        /// Builds and writes html pages for entire folder (including files and subdirectories).
        /// </summary>
        /// <param name="folder">Folder to output the content of.</param>
        private void BuildFolder(SidenavFolder folder)
        {
            string thisOutputFolderPath = Path.Combine(outputFolderPath, folder.GetAbsoluteFolderPath());

            Directory.CreateDirectory(thisOutputFolderPath);

            foreach (SidenavFolder subFolder in folder.Folders)
            {
                BuildFolder(subFolder);
            }

            foreach (SidenavFile file in folder.Files)
            {
                BuildFile(file);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Replaces special tags in html.
        /// </summary>
        /// <param name="htmlContent">Html to replace tags in.</param>
        /// <param name="rootFolder">Root SidenavFolder.</param>
        /// <param name="currentFile">The <see cref="SidenavFile"/> whose page is currently being built.</param>
        /// <returns>Html with special tags corrected.</returns>
        public static string InjectSpecialTags(string htmlContent, SidenavFolder rootFolder, SidenavFile currentFile)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(htmlContent);
            List <HtmlNode> allFoldersNodes = doc.GetAllNodesOfType("ForAllFolders");

            foreach (HtmlNode node in allFoldersNodes)
            {
                HtmlNode allSubFoldersNode = node.FindFirstChild("ForeachSubFolder");
                HtmlNode allPagesNode      = node.FindFirstChild("ForeachPage");

                StringBuilder allSubFolderContent = new StringBuilder();
                if (allSubFoldersNode != null)
                {
                    foreach (HtmlNode subNode in allSubFoldersNode.ChildNodes)
                    {
                        allSubFolderContent.Append(subNode.OuterHtml);
                    }
                }

                StringBuilder allPagesContent = new StringBuilder();
                if (allPagesNode != null)
                {
                    foreach (HtmlNode pagesNode in allPagesNode.ChildNodes)
                    {
                        allPagesContent.Append(pagesNode.OuterHtml);
                    }
                }

                string       rootAllFoldersContent = GetHtmlToReplaceForAllFoldersTag(rootFolder, currentFile, allSubFolderContent.ToString(), allPagesContent.ToString(), 1);
                HtmlDocument newDoc = new HtmlDocument();
                newDoc.LoadHtml(rootAllFoldersContent);
                foreach (HtmlNode allFoldersNode in newDoc.DocumentNode.ChildNodes)
                {
                    node.ParentNode.InsertBefore(allFoldersNode, node);
                }

                node.ParentNode.RemoveChild(node);
            }

            doc.RemoveComments();
            return(doc.DocumentNode.OuterHtml);
        }
        private static SidenavFolder LoadSidenavFolder(string sidenavFolderName, string directory, SidenavFolder parent)
        {
            string actualFolderName = Path.GetFileName(directory);

            if (sidenavFolderName == "root")
            {
                actualFolderName = string.Empty;
            }

            SidenavFolder parentFolder  = new SidenavFolder(sidenavFolderName, directory, HttpUtility.UrlEncode(actualFolderName), parent);
            DirectoryInfo directoryInfo = new DirectoryInfo(directory);

            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                if (fileInfo.Extension == ".html" || fileInfo.Extension == ".md")
                {
                    string   fileLink = HttpUtility.UrlEncode(fileInfo.Name);
                    FileType fileType = FileType.Html;
                    if (fileInfo.Extension == ".md")
                    {
                        fileLink = fileLink.Substring(0, fileLink.Length - 2) + "html";
                        fileType = FileType.Markdown;
                    }

                    SidenavFile file = new SidenavFile(fileInfo.Name, fileType, fileInfo.FullName, fileLink, parentFolder);
                    parentFolder.Files.Add(file);
                }
            }

            foreach (DirectoryInfo subDirInfo in directoryInfo.GetDirectories())
            {
                SidenavFolder folder = LoadSidenavFolder(subDirInfo.Name, subDirInfo.FullName, parentFolder);
                if (folder.Files.Count != 0 || folder.Folders.Count != 0)
                {
                    parentFolder.Folders.Add(folder);
                }
            }

            return(parentFolder);
        }