Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/DotNetApiDiff/ApiExtraction/ApiComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using DotNetApiDiff.Interfaces;
using DotNetApiDiff.Models;
using DotNetApiDiff.Models.Configuration;
using Microsoft.Extensions.Logging;

namespace DotNetApiDiff.ApiExtraction;
Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/ApiExtraction/NameMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using DotNetApiDiff.Interfaces;
using DotNetApiDiff.Models.Configuration;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;

namespace DotNetApiDiff.ApiExtraction;

Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/AssemblyLoading/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.Reflection;
using System.Runtime.Loader;
using System.Security;
using DotNetApiDiff.Interfaces;
using Microsoft.Extensions.Logging;
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetApiDiff/Commands/CompareCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CompareCommandSettings : CommandSettings
[DefaultValue("console")]
public string OutputFormat { get; set; } = "console";

[CommandOption("--output-file <path>")]
[CommandOption("-p|--output-file <path>")]
[Description("Output file path (required for json, html, markdown formats)")]
public string? OutputFile { get; set; }

Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/ExitCodes/ExitCodeManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.IO;
using System.Reflection;
using System.Security;
using DotNetApiDiff.Interfaces;
Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/ExitCodes/GlobalExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Security;
using DotNetApiDiff.Interfaces;
using Microsoft.Extensions.Logging;
Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/Interfaces/IApiComparer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.Reflection;
using DotNetApiDiff.Models;

namespace DotNetApiDiff.Interfaces;
Expand Down
2 changes: 0 additions & 2 deletions src/DotNetApiDiff/Interfaces/IAssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.Reflection;

namespace DotNetApiDiff.Interfaces;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/DotNetApiDiff/Interfaces/ITypeAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.Reflection;
using DotNetApiDiff.Models;

namespace DotNetApiDiff.Interfaces;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace DotNetApiDiff.Models.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace DotNetApiDiff.Models.Configuration;
Expand Down
2 changes: 0 additions & 2 deletions src/DotNetApiDiff/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using DotNetApiDiff.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using Spectre.Console.Cli;
using System.Diagnostics;

namespace DotNetApiDiff;

Expand Down
75 changes: 34 additions & 41 deletions src/DotNetApiDiff/Reporting/HtmlFormatterScriban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using DotNetApiDiff.Models.Configuration;
using Scriban;
using Scriban.Runtime;
using System.Text;

namespace DotNetApiDiff.Reporting;

Expand All @@ -14,24 +13,13 @@ namespace DotNetApiDiff.Reporting;
public class HtmlFormatterScriban : IReportFormatter
{
private readonly Template _mainTemplate;
private readonly Dictionary<string, Template> _partialTemplates;

public HtmlFormatterScriban()
{
// Initialize templates from embedded resources
// Initialize main template from embedded resources
try
{
_mainTemplate = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("main-layout.scriban"));

_partialTemplates = new Dictionary<string, Template>();

// Load all partial templates
_partialTemplates["change-group"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("change-group.scriban"));
_partialTemplates["breaking-changes"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("breaking-changes.scriban"));
_partialTemplates["configuration"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("configuration.scriban"));
_partialTemplates["config-string-list"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("config-string-list.scriban"));
_partialTemplates["config-mappings"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("config-mappings.scriban"));
_partialTemplates["config-namespace-mappings"] = Template.Parse(EmbeddedTemplateLoader.LoadTemplate("config-namespace-mappings.scriban"));
}
catch (Exception ex)
{
Expand All @@ -52,6 +40,7 @@ public string Format(ComparisonResult result)

// Add custom functions
scriptObject.Import("format_boolean", new Func<bool, string>(FormatBooleanValue));
scriptObject.Import("render_change_group", new Func<object, string>(RenderChangeGroup));

// Prepare data for the main template
var resultData = PrepareResultData(result);
Expand Down Expand Up @@ -248,20 +237,42 @@ private object[] PrepareBreakingChangesData(IEnumerable<ApiDifference> breakingC
}).ToArray();
}

private string RenderPartial(string templateName, object data)
private string FormatBooleanValue(bool value)
{
if (_partialTemplates.TryGetValue(templateName, out var template))
{
return template.Render(data, member => member.Name);
}

// Fallback for missing templates
return $"<!-- Template '{templateName}' not found -->";
return value ? "<span class=\"boolean-true\">✓ True</span>" : "<span class=\"boolean-false\">✗ False</span>";
}

private string FormatBooleanValue(bool value)
private string RenderChangeGroup(object sectionData)
{
return value ? "<span class=\"boolean-true\">✓ True</span>" : "<span class=\"boolean-false\">✗ False</span>";
try
{
// Load and parse the change-group template
var templateContent = EmbeddedTemplateLoader.LoadTemplate("change-group.scriban");
var template = Template.Parse(templateContent);

// Create a new context for the template with the section data as root
var context = new TemplateContext();
var scriptObject = new ScriptObject();

// Add the section data properties to the script object
if (sectionData != null)
{
var sectionType = sectionData.GetType();
foreach (var property in sectionType.GetProperties())
{
var value = property.GetValue(sectionData);
scriptObject.SetValue(property.Name.ToLowerInvariant(), value, true);
}
}

context.PushGlobal(scriptObject);

return template.Render(context);
}
catch (Exception ex)
{
return $"<!-- Error rendering change group: {ex.Message} -->";
}
}

private string GetCssStyles()
Expand Down Expand Up @@ -290,24 +301,6 @@ private string GetJavaScriptCode()
}
}

private string GetFallbackTemplate()
{
return @"<!DOCTYPE html>
<html>
<head>
<title>API Comparison Report</title>
<style>{{ css_styles }}</style>
</head>
<body>
<h1>API Comparison Report</h1>
<p>Generated on {{ result.comparison_timestamp }}</p>
<p>Total Differences: {{ result.total_differences }}</p>
<!-- Fallback template - source generator not available -->
<script>{{ javascript_code }}</script>
</body>
</html>";
}

private string GetFallbackStyles()
{
return "body { font-family: Arial, sans-serif; margin: 20px; }";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
{{if section.description}}
<p class="section-description">{{ section.description }}</p>
{{end}}
{{ include "change-group" section }}
{{ render_change_group section }}
</section>
{{end}}
</div>
Expand Down
Loading
Loading