Skip to content

Commit e926af8

Browse files
committed
added method to render IconData to a string
1 parent 8d95c9f commit e926af8

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

src/IconData.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Components;
2+
using System.Text;
23

34
namespace NAMESPACE;
45

@@ -83,6 +84,91 @@ public static RenderFragment Render(this IconData data, string? width, string? h
8384

8485
builder.CloseElement();
8586
};
87+
88+
public static string RenderAsString(this IconData data, string? width, string? height, string? fill, string? cssClass, string? viewBox)
89+
{
90+
var sb = new StringBuilder();
91+
92+
sb.Append("<svg");
93+
94+
if (data.Xmlns != null) {
95+
sb.Append(" xmlns=\"");
96+
sb.Append(data.Xmlns);
97+
sb.Append('"');
98+
}
99+
100+
if (data.Width != null || width != null)
101+
{
102+
sb.Append(" width=\"");
103+
sb.Append(width ?? data.Width);
104+
sb.Append('"');
105+
}
106+
107+
if (data.Height != null || height != null)
108+
{
109+
sb.Append(" height=\"");
110+
sb.Append(height ?? data.Height);
111+
sb.Append('"');
112+
}
113+
114+
if (data.Fill != null || fill != null)
115+
{
116+
sb.Append(" fill=\"");
117+
sb.Append(fill ?? data.Fill);
118+
sb.Append('"');
119+
}
120+
121+
if (data.ViewBox != null || viewBox != null)
122+
{
123+
sb.Append(" viewBox=\"");
124+
sb.Append(viewBox ?? data.ViewBox);
125+
sb.Append('"');
126+
}
127+
128+
if (data.Stroke != null)
129+
{
130+
sb.Append(" stroke=\"");
131+
sb.Append(data.Stroke);
132+
sb.Append('"');
133+
}
134+
135+
if (data.StrokeWidth != null)
136+
{
137+
sb.Append(" stroke-width=\"");
138+
sb.Append(data.StrokeWidth);
139+
sb.Append('"');
140+
}
141+
142+
if (data.StrokeLineCap != null)
143+
{
144+
sb.Append(" stroke-linecap=\"");
145+
sb.Append(data.StrokeLineCap);
146+
sb.Append('"');
147+
}
148+
149+
if (data.StrokeLineJoin != null)
150+
{
151+
sb.Append(" stroke-linejoin=\"");
152+
sb.Append(data.StrokeLineJoin);
153+
sb.Append('"');
154+
}
155+
156+
sb.Append(" class=\"");
157+
if (string.IsNullOrWhiteSpace(cssClass))
158+
{
159+
sb.Append(data.Class);
160+
}
161+
else
162+
{
163+
sb.Append(data.Class + ' ' + cssClass);
164+
}
165+
sb.Append("\">");
166+
167+
sb.Append(data.SvgContent);
168+
sb.Append("</svg>");
169+
170+
return sb.ToString();
171+
}
86172
}
87173

88174
#nullable disable

src/Vizor.Icons.Tabler/Vizor.Icons.Tabler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PackageIcon>datahint_logo.png</PackageIcon>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2020

21-
<Version>2.11.0</Version>
21+
<Version>2.11.1</Version>
2222
<ProductVersion>$(Version)</ProductVersion>
2323
<AssemblyVersion>$(Version)</AssemblyVersion>
2424
<FileVersion>$(Version)</FileVersion>

src/Vizor.Icons.Tabler/gulpfile.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Following steps are required to install gulp: see https://gulpjs.com/docs/en/getting-started/quick-start/
2+
// npm install --global gulp-cli
3+
//
4+
// in the project dir:
5+
// npm init
6+
// npm install --save-dev gulp child_process
7+
// npm install @tabler/icons
8+
//
9+
// to build:
10+
// gulp
11+
12+
var gulp = require('gulp');
13+
var path = require('path');
14+
var exec = require("child_process").exec;
15+
16+
gulp.task("publishLocal", function (callback) {
17+
exec(
18+
"Powershell.exe -executionpolicy remotesigned . .\\publish_local.ps1 -Push:1",
19+
function (err, stdout, stderr) {
20+
console.log(stdout);
21+
callback(err);
22+
}
23+
);
24+
});

src/Vizor.Icons.Tabler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"author": "Ben Motmans <[email protected]>",
77
"license": "MIT",
88
"devDependencies": {
9+
"child_process": "^1.0.2",
910
"gulp": "^4.0.2",
1011
"gulp-clean": "^0.4.0",
1112
"gulp-clean-css": "^4.3.0",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# usage:
2+
# powershell .\publish_nuget.ps1
3+
# powershell .\publish_nuget.ps1 -Push:1
4+
5+
param (
6+
[string]$Folder = "D:\\Dev\\NugetLocal",
7+
[string]$BuildConfig = "Release"
8+
)
9+
10+
[xml]$xmlElem = Get-Content -Path Vizor.Icons.Tabler.csproj
11+
$version = ($xmlElem.Project.PropertyGroup.Version).Trim()
12+
13+
Write-Host -ForegroundColor Green "Building Vizor.Icons.Tabler version $version"
14+
&dotnet "pack" "-p:PackageVersion=$version" "Vizor.Icons.Tabler.csproj" "-c:$BuildConfig"
15+
16+
Write-Host -ForegroundColor Green "Pushing Vizor.Icons.Tabler version $version to $Folder"
17+
&nuget "add" "bin/$BuildConfig/Vizor.Icons.Tabler.$version.nupkg" "-Source" "$Folder"

0 commit comments

Comments
 (0)