Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: override support #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions toolsrc/Chloroplast.Core/Content/ContentArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static IEnumerable<ContentArea> LoadContentAreas (IConfigurationRoot conf
TargetPath = outDirectory.CombinePath (areaConfig["output_folder"].NormalizePath(toLower: normalizePaths)),
RootRelativePath = areaConfig["output_folder"].Replace ("index.html", "").NormalizePath (toLower: normalizePaths),
NormalizePaths = normalizePaths,
AreaType = areaConfig["type"]
AreaType = areaConfig["type"],
OverridePath = rootDirectory.CombinePath (areaConfig["override_folder"])
};

// TODO: validate values
Expand Down Expand Up @@ -93,7 +94,8 @@ public string AreaType
if (!string.IsNullOrWhiteSpace (value))
areaType = value;
}
}
}
public string OverridePath { get; set; }

public GroupContentArea ()
{
Expand Down
5 changes: 4 additions & 1 deletion toolsrc/Chloroplast.Core/Extensions/PathExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;

namespace Chloroplast.Core.Extensions
{
Expand Down Expand Up @@ -36,7 +37,9 @@ public static string GetPathFileName(this string value)

public static string CombinePath(this string value, params string[] paths)
{
string combinedPaths = Path.Combine (paths).NormalizePath ();
if (value == null) value = string.Empty;

string combinedPaths = Path.Combine (paths.Where(p => !string.IsNullOrWhiteSpace(p)).ToArray()).NormalizePath ();
if (combinedPaths.StartsWith (Path.DirectorySeparatorChar))
combinedPaths = combinedPaths.Substring (1);

Expand Down
7 changes: 7 additions & 0 deletions toolsrc/Chloroplast.Core/Loaders/EcmaXmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public class XType
[XmlAttribute]
public string FullName { get; set; }

public string Namespace {
get
{
return FullName.Replace ("." + Name, string.Empty);
}
}

[XmlElement ("TypeSignature")]
public List<XSignature> Signatures { get; set; } = new List<XSignature> ();

Expand Down
27 changes: 27 additions & 0 deletions toolsrc/Chloroplast.Core/Rendering/EcmaXmlRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Chloroplast.Core.Content;
using Chloroplast.Core.Loaders;
using Microsoft.Extensions.Configuration;
using EcmaXml = Chloroplast.Core.Loaders.EcmaXml;
Expand All @@ -19,7 +21,32 @@ public static async Task<RenderedContent> Render (ContentNode item, string body,

if (body.StartsWith ("<Type "))
{
GroupContentArea groupArea = item.Area as GroupContentArea;

var t = EcmaXmlLoader.LoadXType (body);

// TODO: use groupArea.OverridePath to look for the type's override files if any
// and also all members
// for uid, use t.FullName
if (groupArea != null && Directory.Exists(groupArea.OverridePath))
{
var overrideFile = Path.Combine (groupArea.OverridePath,t.Namespace, t.FullName + ".md");
if (File.Exists(overrideFile))
{
t.Docs.Remarks = File.ReadAllText (overrideFile);
}

foreach(var m in t.Members)
{
// TODO: look for override file for this member
overrideFile = Path.Combine (groupArea.OverridePath, t.Namespace, t.FullName + "." + m.Name + ".md");
if (File.Exists (overrideFile))
{
m.Docs.Remarks = File.ReadAllText (overrideFile);
}
}
}

var nscontent = ToEcmaContent (item, config, t);

var result = await ContentRenderer.ToRazorAsync (nscontent);
Expand Down