This repository has been archived on 2024-06-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
thesis-src/ReportGeneration/ReportGeneration.Generators/Html/HtmlTools.cs
T
2024-01-14 19:40:49 +01:00

60 lines
1.3 KiB
C#

using ReportGeneration.Interface;
namespace ReportGeneration.Generators;
internal static class HtmlTools
{
public static string Wrap(string tag, string? content, string? @class = default) =>
$"<{tag} class={@class}>{content}</{tag}>";
public static string FormatImage(string path, string? @class = default, IBounds? bounds = default)
{
var style = bounds is null
? string.Empty
: GetCssStyle(bounds);
path += path.EndsWith(".png") ? string.Empty : ".png";
return $"<img src=\"{path}\" style=\"{style}\" class={@class} />";
}
private static string GetCssStyle(IBounds bounds)
{
var style = string.Empty;
// Width
if (bounds.Width.HasValue)
{
style += $"width:{bounds.Width}{bounds.Unit};";
}
if (bounds.MinWidth.HasValue)
{
style += $"min-width:{bounds.MinWidth}{bounds.Unit};";
}
if (bounds.MaxWidth.HasValue)
{
style += $"max-width:{bounds.MaxWidth}{bounds.Unit};";
}
// Height
if (bounds.Height.HasValue)
{
style += $"height:{bounds.Height}{bounds.Unit};";
}
if (bounds.MinHeight.HasValue)
{
style += $"min-height:{bounds.MinHeight}{bounds.Unit};";
}
if (bounds.MaxHeight.HasValue)
{
style += $"max-height:{bounds.MaxHeight}{bounds.Unit};";
}
return style;
}
}