Browse Source

partial docs refactor

pull/2722/head
Yunus Emre Kalkan 7 years ago
parent
commit
fd1596a3cb
  1. 13
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentPartialTemplateDto.cs
  2. 9
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentPartialTemplatesDto.cs
  3. 19
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/GetDocumentPartialTemplatesInput.cs
  4. 2
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  5. 27
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  6. 1
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs
  7. 14
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs
  8. 1
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs
  9. 5
      modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs
  10. 9
      modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentPartialTemplateContent.cs
  11. 2
      modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentPartialTemplateWithValuesDto.cs
  12. 7
      modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionRenderer.cs
  13. 4
      modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanDocumentSectionRenderer.cs
  14. 38
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

13
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentPartialTemplateDto.cs

@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace Volo.Docs.Documents
{
public class DocumentPartialTemplateDto
{
public string Name { get; set; }
public string Path { get; set; }
public List<string> Parameters { get; set; }
}
}

9
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/DocumentPartialTemplatesDto.cs

@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace Volo.Docs.Documents
{
public class DocumentPartialTemplatesDto
{
public List<DocumentPartialTemplateDto> Templates { get; set; }
}
}

19
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/GetDocumentPartialTemplatesInput.cs

@ -1,19 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
using Volo.Docs.Language;
using Volo.Docs.Projects;
namespace Volo.Docs.Documents
{
public class GetDocumentPartialTemplatesInput
{
public Guid ProjectId { get; set; }
[StringLength(ProjectConsts.MaxVersionNameLength)]
public string Version { get; set; }
[Required]
[StringLength(LanguageConsts.MaxLanguageCodeLength)]
public string LanguageCode { get; set; }
}
}

2
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs

@ -13,8 +13,6 @@ namespace Volo.Docs.Documents
Task<DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input);
Task<DocumentPartialTemplatesDto> GetPartialTemplatesAsync(GetDocumentPartialTemplatesInput input);
Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input);
}
}

27
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -128,33 +128,6 @@ namespace Volo.Docs.Documents
}
}
public async Task<DocumentPartialTemplatesDto> GetPartialTemplatesAsync(GetDocumentPartialTemplatesInput input)
{
var project = await _projectRepository.GetAsync(input.ProjectId);
try
{
if (string.IsNullOrWhiteSpace(project.PartialTemplatesDocumentName))
{
return await Task.FromResult<DocumentPartialTemplatesDto>(null);
}
var document = await GetDocumentWithDetailsDtoAsync(
project,
project.PartialTemplatesDocumentName,
input.LanguageCode,
input.Version
);
return JsonConvert.DeserializeObject<DocumentPartialTemplatesDto>(document.Content);
}
catch (DocumentNotFoundException)
{
Logger.LogWarning($"Partial template list file ({project.PartialTemplatesDocumentName}) not found.");
return new DocumentPartialTemplatesDto();
}
}
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDtoAsync(
Project project,
string documentName,

1
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs

@ -37,7 +37,6 @@ namespace Volo.Docs.GitHub.Documents
var commitHistoryUrl = project.GetGitHubUrlForCommitHistory() + documentName;
var isNavigationDocument = documentName == project.NavigationDocumentName;
var isParameterDocument = documentName == project.ParametersDocumentName;
var isPartialTemplatesDocumentName = documentName == project.PartialTemplatesDocumentName;
var editLink = rootUrl.ReplaceFirst("/tree/", "/blob/") + languageCode + "/" + documentName;
var localDirectory = "";
var fileName = documentName;

14
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Project.cs

@ -39,11 +39,6 @@ namespace Volo.Docs.Projects
/// </summary>
public virtual string ParametersDocumentName { get; protected set; }
/// <summary>
/// The document to be used for the partial document templates file (index).
/// </summary>
public virtual string PartialTemplatesDocumentName { get; protected set; }
public virtual string MinimumVersion { get; set; }
/// <summary>
@ -68,8 +63,7 @@ namespace Volo.Docs.Projects
[NotNull] string format,
[NotNull] string defaultDocumentName = "Index",
[NotNull] string navigationDocumentName = "docs-nav.json",
[NotNull] string parametersDocumentName = "docs-params.json",
[NotNull] string partialTemplatesDocumentName = "docs-templates.json")
[NotNull] string parametersDocumentName = "docs-params.json")
{
Id = id;
@ -80,7 +74,6 @@ namespace Volo.Docs.Projects
DefaultDocumentName = Check.NotNullOrWhiteSpace(defaultDocumentName, nameof(defaultDocumentName));
NavigationDocumentName = Check.NotNullOrWhiteSpace(navigationDocumentName, nameof(navigationDocumentName));
ParametersDocumentName = Check.NotNullOrWhiteSpace(parametersDocumentName, nameof(parametersDocumentName));
PartialTemplatesDocumentName = Check.NotNullOrWhiteSpace(partialTemplatesDocumentName, nameof(partialTemplatesDocumentName));
ExtraProperties = new Dictionary<string, object>();
}
@ -105,11 +98,6 @@ namespace Volo.Docs.Projects
ParametersDocumentName = Check.NotNullOrWhiteSpace(parametersDocumentName, nameof(parametersDocumentName));
}
public void SetPartialTemplatesDocumentName(string partialTemplatesDocumentName)
{
PartialTemplatesDocumentName = Check.NotNullOrWhiteSpace(partialTemplatesDocumentName, nameof(partialTemplatesDocumentName));
}
public void SetDefaultDocumentName(string defaultDocumentName)
{
DefaultDocumentName = Check.NotNullOrWhiteSpace(defaultDocumentName, nameof(defaultDocumentName));

1
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/EntityFrameworkCore/DocsDbContextModelBuilderExtensions.cs

@ -34,7 +34,6 @@ namespace Volo.Docs.EntityFrameworkCore
b.Property(x => x.DefaultDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxDefaultDocumentNameLength);
b.Property(x => x.NavigationDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxNavigationDocumentNameLength);
b.Property(x => x.ParametersDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxParametersDocumentNameLength);
b.Property(x => x.PartialTemplatesDocumentName).IsRequired().HasMaxLength(ProjectConsts.MaxPartialTemplatesDocumentNameLength);
b.Property(x => x.LatestVersionBranchName).HasMaxLength(ProjectConsts.MaxLatestVersionBranchNameLength);
});
}

5
modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs

@ -39,11 +39,6 @@ namespace Volo.Docs.Documents
return DocumentAppService.GetNavigationAsync(input);
}
public virtual Task<DocumentPartialTemplatesDto> GetPartialTemplatesAsync(GetDocumentPartialTemplatesInput input)
{
return DocumentAppService.GetPartialTemplatesAsync(input);
}
[HttpGet]
[Route("resource")]
public Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)

9
modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentPartialTemplateContent.cs

@ -0,0 +1,9 @@
namespace Volo.Docs.HtmlConverting
{
public class DocumentPartialTemplateContent
{
public string Path { get; set; }
public string Content { get; set; }
}
}

2
modules/docs/src/Volo.Docs.Web/HtmlConverting/DocumentPartialTemplateWithValuesDto.cs

@ -4,7 +4,7 @@ namespace Volo.Docs.HtmlConverting
{
public class DocumentPartialTemplateWithValuesDto
{
public string Name { get; set; }
public string Path { get; set; }
public Dictionary<string, string> Parameters { get; set; }
}

7
modules/docs/src/Volo.Docs.Web/HtmlConverting/IDocumentSectionRenderer.cs

@ -12,11 +12,4 @@ namespace Volo.Docs.HtmlConverting
Task<List<DocumentPartialTemplateWithValuesDto>> GetPartialTemplatesInDocumentAsync(string documentContent);
}
public class DocumentPartialTemplateContent
{
public string Name { get; set; }
public string Content { get; set; }
}
}

4
modules/docs/src/Volo.Docs.Web/HtmlConverting/ScribanDocumentSectionRenderer.cs

@ -180,9 +180,9 @@ namespace Volo.Docs.HtmlConverting
var json = betweenJsonOpenerAndCloser.Substring(betweenJsonOpenerAndCloser.IndexOf(docs_templates, StringComparison.Ordinal) + docs_templates.Length);
var templateName = JsonConvert.DeserializeObject<DocumentPartialTemplateWithValuesDto>(json)?.Name;
var templatePath = JsonConvert.DeserializeObject<DocumentPartialTemplateWithValuesDto>(json)?.Path;
var template = templates.FirstOrDefault(t => t.Name == templateName);
var template = templates.FirstOrDefault(t => t.Path == templatePath);
var beforeTemplate = document.Substring(0,
document.IndexOf(jsonOpener, StringComparison.Ordinal));

38
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -420,20 +420,6 @@ namespace Volo.Docs.Pages.Documents.Project
private async Task<List<DocumentPartialTemplateContent>> GetDocumentPartialTemplatesAsync()
{
var projectPartialTemplates = await _documentAppService.GetPartialTemplatesAsync(
new GetDocumentPartialTemplatesInput()
{
ProjectId = Project.Id,
LanguageCode = LanguageCode,
Version = Version
});
if (!projectPartialTemplates?.Templates?.Any() ?? true)
{
return null;
}
var partialTemplatesInDocument = await _documentSectionRenderer.GetPartialTemplatesInDocumentAsync(Document.Content);
if (!partialTemplatesInDocument?.Any(t => t.Parameters != null) ?? true)
@ -449,23 +435,29 @@ namespace Volo.Docs.Pages.Documents.Project
{
UserPreferences.Add(parameter.Key, parameter.Value);
}
else
{
UserPreferences[parameter.Key] = parameter.Value;
}
}
}
var contents = new List<DocumentPartialTemplateContent>();
foreach (var partialTemplate in projectPartialTemplates.Templates)
foreach (var partialTemplate in partialTemplatesInDocument)
{
var content = (await _documentAppService.GetAsync(new GetDocumentInput
{
LanguageCode = LanguageCode,
Name = partialTemplate.Path,
ProjectId = Project.Id,
Version = Version
})).Content;
contents.Add(new DocumentPartialTemplateContent
{
Name = partialTemplate.Name,
Content = (await _documentAppService.GetAsync(new GetDocumentInput
{
LanguageCode = LanguageCode,
Name = partialTemplate.Path,
ProjectId = Project.Id,
Version = Version
})).Content
Path = partialTemplate.Path,
Content = content
});
}

Loading…
Cancel
Save