public IEnumerable<TableOfContents> GenerateTableOfContents(DirectoryInfo directoryInfo)
        {
            var directoryName = directoryInfo.Name;
            var documentationVersion = directoryName;
            var directory = _options.GetPathToDocumentationPagesDirectory(documentationVersion);

            Debug.Assert(Directory.Exists(_options.GetPathToDocumentationPagesDirectory(documentationVersion)));

            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);
            if (File.Exists(docsFilePath) == false)
                yield break;

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (!item.IsFolder)
                    continue;

                var tableOfContents = new TableOfContents
                                          {
                                              Version = documentationVersion,
                                              Category = CategoryHelper.ExtractCategoryFromPath(item.Name),
                                              Items = GenerateTableOfContentItems(Path.Combine(directory, item.Name), item.Name).ToList()
                                          };

                yield return tableOfContents;
            }
        }
Beispiel #2
0
 public ArticleModel(DocumentationPage page, TableOfContents tableOfContents)
 {
     Key = page.Key;
     TableOfContents = tableOfContents;
     Title = page.Title;
     HtmlContent = page.HtmlContent;
 }
 public NotDocumentedModel(string articleKey, Language currentLanguage, IEnumerable<DocumentationPage> pages, TableOfContents tableOfContents)
 {
     ArticleKey = articleKey;
     CurrentLanguage = currentLanguage;
     TableOfContents = tableOfContents;
     AvailableLanguages = pages.Select(x => x.Language).ToList();
 }
        public static MvcHtmlString GenerateTableOfContents(this HtmlHelper htmlHelper, UrlHelper urlHelper, TableOfContents tableOfContents, string key)
        {
            Debug.Assert(tableOfContents != null);

            var mode = GetMode(tableOfContents.Version);

            var builder = new StringBuilder();
            builder.AppendLine("<div class='panel-group' id='sidebar'>");

            for (int index = 0; index < tableOfContents.Items.Count; index++)
            {
                var item = tableOfContents.Items[index];
                var containsKey = ContainsKey(item, key, 2);
                if (item.IsFolder)
                {
                    var id = "collapse" + index;

                    builder.AppendLine("<div class='panel panel-default'>");
                    builder.AppendLine("<div class='panel-heading'>");
                    builder.AppendLine("<h4 class='panel-title'>");

                    switch (mode)
                    {
                        case DocumentationMode.Normal:
                            builder.AppendLine(string.Format("<a data-toggle='collapse' data-parent='#sidebar' href='#{0}'>", id));
                            break;
                        case DocumentationMode.Legacy:
                            builder.AppendLine(string.Format("<a href='{0}'>", urlHelper.Action(MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { version = tableOfContents.Version, language = Language.Csharp, key = item.Key })));
                            break;
                    }

                    builder.AppendLine(string.Format("<span class='fa fa-folder-o'></span><span><strong>{0}</strong></span>", item.Title));
                    builder.AppendLine("</a>");
                    builder.AppendLine("</h4>");
                    builder.AppendLine("</div>");

                    builder.AppendLine(string.Format("<div id='{0}' class='panel-collapse collapse {1}'>", id, containsKey ? "in" : string.Empty));
                    builder.AppendLine("<ul class='list-group'>");
                    GenerateTableOfContents(htmlHelper, urlHelper, builder, item.Items, key, 0, tableOfContents.Version, mode);
                    builder.AppendLine("</ul>");
                    builder.AppendLine("</div>");
                    builder.AppendLine("</div>");

                    continue;
                }

                var link = htmlHelper.ActionLink(item.Title, MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { key = item.Key }, null).ToHtmlString();

                builder.AppendLine(string.Format("<div class='panel panel-default panel-article {0}'>", containsKey ? "selected" : string.Empty));
                builder.AppendLine("<div class='panel-heading'>");
                builder.AppendLine("<h4 class='panel-title'>");
                builder.AppendLine(string.Format("<span class='fa fa-file-text-o'></span>{0}", link));
                builder.AppendLine("</h4>");
                builder.AppendLine("</div>");
                builder.AppendLine("</div>");
            }

            builder.AppendLine("</div>");
            return new MvcHtmlString(builder.ToString());
        }
Beispiel #5
0
		private static bool ContainsKey(TableOfContents.TableOfContentsItem item, string key, int minNumberOfPartsThatMustMatch)
		{
			if (string.IsNullOrEmpty(key))
				return false;

			var numberOfParts = 0;

			var itemKey = item.Key;
			for (var i = 0; i < Math.Min(itemKey.Length, key.Length); i++)
			{
				if (itemKey[i] != key[i])
					return false;

				if (key[i] == '/')
					numberOfParts++;

				if (numberOfParts >= minNumberOfPartsThatMustMatch)
					return true;

				if (i == itemKey.Length - 1)
					return true;
			}

			return false;
		}
Beispiel #6
0
		private static void GenerateForFolder(HtmlHelper htmlHelper, UrlHelper urlHelper, StringBuilder builder, TableOfContents.TableOfContentsItem item, string key, int level, bool containsKey, string version, DocumentationMode mode)
		{
			if (mode == DocumentationMode.Legacy)
				builder.AppendLine(string.Format("<a href='{0}'>", urlHelper.Action(MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { version = version, language = Language.Csharp, key = item.Key })));

			builder.AppendLine(string.Format("<span class='fa fa-folder {1}'></span><span>{0}</span>", item.Title, containsKey ? "text-danger" : string.Empty));

			if (mode == DocumentationMode.Legacy)
				builder.AppendLine("</a>");

			builder.AppendLine("<ul class='list-group'>");

			GenerateTableOfContents(htmlHelper, urlHelper, builder, item.Items, key, ++level, version, mode);

			builder.AppendLine("</ul>");
		}
Beispiel #7
0
		private static void GenerateForArticle(HtmlHelper htmlHelper, StringBuilder builder, TableOfContents.TableOfContentsItem item)
		{
			var link = htmlHelper.ActionLink(item.Title, MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { key = item.Key }, null).ToHtmlString();
			builder.AppendLine(string.Format("<span class='fa fa-file-text-o'></span>{0}", link));
		}
Beispiel #8
0
 public PageModel(TableOfContents tableOfContents)
 {
     TableOfContents = tableOfContents;
 }