-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathDynamicResources.cs
75 lines (69 loc) · 2.49 KB
/
DynamicResources.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Text;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
namespace Blazor_MAUI_Demos.Shared
{
/// <summary>
/// A component to render the dynamic resources like themes, polyfill.
/// </summary>
public class DynamicResources : ComponentBase
{
private string stylePath { get; set; }
[Inject]
protected NavigationManager UriHelper { get; set; }
[Inject]
protected SampleService SampleService { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddMarkupContent(0, RenderStyles());
builder.AddMarkupContent(1, RenderResources());
}
private string RenderStyles()
{
var themeName = SampleUtils.GetThemeName(UriHelper.Uri);
StringBuilder sb = new StringBuilder();
sb.Append(Environment.NewLine);
sb.Append($" <link");
sb.Append($" href=\"{ stylePath + themeName + ".css"}\"");
sb.Append($" rel=\"stylesheet\"");
sb.Append(" />");
sb.Append(Environment.NewLine);
return sb.ToString();
}
private string RenderResources()
{
StringBuilder sb = new StringBuilder();
var resources = SampleUtils.GetDynamicResources(UriHelper, SampleService);
foreach (var resource in resources)
{
sb.Append(Environment.NewLine);
if (resource.EndsWith(".css"))
{
sb.Append($" <link");
sb.Append($" href=\"" + resource + "\"");
sb.Append($" rel=\"stylesheet\"");
sb.Append(" />");
}
}
sb.Append(Environment.NewLine);
return sb.ToString();
}
protected override void OnInitialized()
{
base.OnInitialized();
#if (DEBUG || STAGING)
stylePath = "_content/Syncfusion.Blazor.Themes/";
#else
stylePath = "https://cdn.syncfusion.com/blazor/19.4.38/styles/";
#endif
}
}
}