Exemplo n.º 1
0
 public void GenerateToc(IDocumentationItem rootItem)
 {
     var menuToc = Path.Combine(OutputPath, "toc.html");
     var sb = new StringBuilder();
     CreateHtmlToc(rootItem, sb);
     File.WriteAllText(menuToc, sb.ToString());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Processes an item.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string ProcessItem(Folder folder, string versionUrl, IDocumentationItem item, string fullPath)
        {
            if (item.Slug != null)
            {
                item.Slug = item.Slug.TrimStart('\\', '/');
            }

            item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            folder.Items.Add(item);

            var document = item as Document;

            if (document != null)
            {
                return(this.CompileDocument(versionUrl, document, fullPath));
            }

            var subFolder = item as Folder;

            if (subFolder != null)
            {
                return(CompileFolder(subFolder, versionUrl));
            }

            return(string.Empty);
        }
Exemplo n.º 3
0
        private static string GenerateBreadcrumbs(IDocumentationItem doc)
        {
            var ancestors = new List <IDocumentationItem>();

            var parent = doc.Parent;

            while (parent != null)
            {
                ancestors.Add(parent);

                parent = parent.Parent;
            }

            ancestors.Reverse();
            ancestors.Add(doc);

            var builder = new StringBuilder();

            foreach (var breadcrumb in ancestors.Skip(1))
            {
                builder.AppendFormat("<li>{0}</li>\n", breadcrumb.Title);
            }

            return(builder.ToString());
        }
Exemplo n.º 4
0
        private string GenerateMenuItemTitle(IDocumentationItem item, Document current)
        {
            var document = item as Document;

            if (document != null)
            {
                return(string.Format("<a href='{0}' class='{2}'>{1}</a>", GenerateUrlForDocument(document, current), item.Title, item == current ? "current" : string.Empty));
            }

            var folder = item as Folder;

            if (folder != null)
            {
                switch (CompilationMode)
                {
                case CompilationMode.Legacy:
                    return(string.Format("<a href='{0}' class='folder'>{1}</a>", GenerateUrlForFolder(folder), item.Title));

                case CompilationMode.Normal:
                    return(string.Format("<span>{0}</span>", item.Title));

                default:
                    throw new NotSupportedException();
                }
            }

            return(string.Empty);
        }
Exemplo n.º 5
0
        private string GenerateMenuItem(IDocumentationItem item, Document current)
        {
            var isOpen = IsMenuItemOpen(item, current);

            var builder = new StringBuilder();

            builder.AppendFormat("<li class='{1}'>{0}", GenerateMenuItemTitle(item, current), isOpen ? "open" : string.Empty);

            var groups = item.Children
                         .GroupBy(x => new { x.Trail, x.Slug, IsFolder = x is Folder, IsDocument = x is Document })
                         .OrderByDescending(x => x.Key.IsFolder);

            foreach (var g in groups)
            {
                var child = g.FirstOrDefault(x => x.Language == current.Language) ?? g.First();

                if (CompilationMode == CompilationMode.Legacy && child.Slug == "index")
                {
                    continue;
                }

                builder.Append("<ul>");
                builder.Append(GenerateMenuItem(child, current));
                builder.Append("</ul>");
            }

            builder.Append("</li>");

            return(builder.ToString());
        }
Exemplo n.º 6
0
        public void GenerateToc(IDocumentationItem rootItem)
        {
            var menuToc = Path.Combine(OutputPath, "toc.html");
            var sb      = new StringBuilder();

            CreateHtmlToc(rootItem, sb);
            File.WriteAllText(menuToc, sb.ToString());
        }
Exemplo n.º 7
0
        private static void CreateHtmlToc(IDocumentationItem item, StringBuilder sb)
        {
            var folder = item as Folder;
            if (folder != null)
            {
                sb.AppendFormat(@"<li><a href=""{0}/index.html""><strong>{1}</strong></a><ul>", Path.Combine(item.Trail, item.Slug ?? string.Empty).Replace('\\', '/'), item.Title);
                sb.AppendLine();
                foreach (var documentationItem in folder.Items)
                {
                    CreateHtmlToc(documentationItem, sb);
                }
                sb.AppendLine("</ul></li>");
                return;
            }

            sb.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", Path.Combine(item.Trail, item.Slug).Replace('\\', '/').Replace(".markdown", ".html"), item.Title);
            sb.AppendLine();
        }
Exemplo n.º 8
0
        private static void CreateHtmlToc(IDocumentationItem item, StringBuilder sb)
        {
            var folder = item as Folder;

            if (folder != null)
            {
                sb.AppendFormat(@"<li><a href=""{0}/index.html""><strong>{1}</strong></a><ul>", Path.Combine(item.Trail, item.Slug ?? string.Empty).Replace('\\', '/'), item.Title);
                sb.AppendLine();
                foreach (var documentationItem in folder.Items)
                {
                    CreateHtmlToc(documentationItem, sb);
                }
                sb.AppendLine("</ul></li>");
                return;
            }

            sb.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", Path.Combine(item.Trail, item.Slug).Replace('\\', '/').Replace(".markdown", ".html"), item.Title);
            sb.AppendLine();
        }
Exemplo n.º 9
0
        private static bool IsMenuItemOpen(IDocumentationItem item, Document current)
        {
            var isOpen = item == current;

            if (isOpen)
            {
                return(true);
            }

            foreach (var child in item.Children)
            {
                isOpen = IsMenuItemOpen(child, current);

                if (isOpen)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Processes an item.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string ProcessItem(Folder folder, string versionUrl, IDocumentationItem item, string fullPath)
        {
            if (item.Slug != null)
                item.Slug = item.Slug.TrimStart('\\', '/');
 
            item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            folder.Items.Add(item);

            var document = item as Document;
            if (document != null)
                return this.CompileDocument(versionUrl, document, fullPath);
 
            var subFolder = item as Folder;
            if (subFolder != null)
                return CompileFolder(subFolder, versionUrl);
 
            return string.Empty;
        }
Exemplo n.º 11
0
 public void GenerateTableOfContents(IDocumentationItem rootItem)
 {
 }
Exemplo n.º 12
0
 public void GenerateTableOfContents(IDocumentationItem rootItem)
 {
 }