Skip to content

Commit

Permalink
Option parameters, links to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene-Sackers committed Jul 7, 2021
1 parent ab70e27 commit baa1713
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/StormworksLuaDocsGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ private static void ParseParameter(ExcelWorksheet functionDescriptionsSheet, int
parameterName = "arg" + (function.Parameters.Count + 1);
}

var isOptional = functionDescriptionsSheet.Cells[row, 4].Text.ToLowerInvariant() == "true";
var isOptional = functionDescriptionsSheet.Cells[row, 4].Text.ToLowerInvariant() == "1";
var parameterType = functionDescriptionsSheet.Cells[row, 6].Text;
var parameterDescription = functionDescriptionsSheet.Cells[row, 7].Text;

var descriptionCell = functionDescriptionsSheet.Cells[row, 7];
var translatedHyperlink = TranslateHyperlink(descriptionCell);
var parameterDescription = descriptionCell.Text + (string.IsNullOrWhiteSpace(translatedHyperlink) ? null : $" {translatedHyperlink}");

function.Parameters.Add(new()
{
Expand All @@ -167,6 +170,17 @@ private static void ParseParameter(ExcelWorksheet functionDescriptionsSheet, int
});
}

private static string TranslateHyperlink(ExcelRange cell)
{
var descriptionHyperlink = cell.Hyperlink as ExcelHyperLink;
if (descriptionHyperlink == null)
return null;

return !string.IsNullOrWhiteSpace(descriptionHyperlink.ReferenceAddress) ?
$"(Refer to cells \"{descriptionHyperlink.ReferenceAddress}\" on {DocsGoogleSheetUrl})"
: descriptionHyperlink.AbsoluteUri;
}

private static void ParseReturnParameter(ExcelWorksheet functionDescriptionsSheet, int row, Function function)
{
var returnParameterName = functionDescriptionsSheet.Cells[row, 8].Text;
Expand Down Expand Up @@ -203,7 +217,8 @@ private static StringBuilder GenerateDocs(IEnumerable<Function> functions)

var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("-- Auto generated docs by StormworksLuaDocsGen (https://github.com/Rene-Sackers/StormworksLuaDocsGen)");
stringBuilder.AppendLine($"-- Notice issues/missing info? Please contribute here: {DocsGoogleSheetUrl}, then create an issue on the GitHub");
stringBuilder.AppendLine($"-- Based on data in: {DocsGoogleSheetUrl}");
stringBuilder.AppendLine($"-- Notice issues/missing info? Please contribute here: {DocsGoogleSheetUrl}, then create an issue on the GitHub repo");
stringBuilder.AppendLine();
stringBuilder.AppendLine("--- @diagnostic disable: lowercase-global");
stringBuilder.AppendLine();
Expand All @@ -218,7 +233,8 @@ private static StringBuilder GenerateDocs(IEnumerable<Function> functions)
stringBuilder.AppendLine($"--- {docFunction.Description.RemoveNewlines()}");
foreach (var parameter in docFunction.Parameters)
{
stringBuilder.AppendLine($"--- @param {parameter.Name} {parameter.Type} {parameter.Description.RemoveNewlines()}");
var type = parameter.IsOptional ? $"{parameter.Type}|nil" : parameter.Type;
stringBuilder.AppendLine($"--- @param {parameter.Name} {type} {parameter.Description.RemoveNewlines()}");
}

if (docFunction.ReturnParameters.Any())
Expand Down

0 comments on commit baa1713

Please sign in to comment.