-
Notifications
You must be signed in to change notification settings - Fork 3
/
ICssClassHolder.cs
43 lines (37 loc) · 1.43 KB
/
ICssClassHolder.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
using System.Collections.Generic;
using System.Linq;
namespace Lombiq.BaseTheme.Services;
/// <summary>
/// Service for managing CSS classes to be rendered in the template.
/// </summary>
public interface ICssClassHolder
{
/// <summary>
/// Gets the classes associated with the <c><body></c> element.
/// </summary>
ISet<string> Body { get; }
/// <summary>
/// Gets the set that contains the classes that will be attached to the zone called <paramref name="zoneName"/>.
/// </summary>
ISet<string> this[string zoneName] { get; }
/// <summary>
/// Adds a <paramref name="className"/> to the zone called <paramref name="zoneName"/>.
/// </summary>
void AddClassToZone(string zoneName, string className);
/// <summary>
/// Returns the set of classes belonging to the zone called <paramref name="zoneName"/>. If the set doesn't exists,
/// a new one is created. You can use this to remove classes if needed.
/// </summary>
ISet<string> GetZoneClasses(string zoneName);
}
public static class CssClassHolderExtensions
{
/// <summary>
/// Returns the string you can insert into the zone's template.
/// </summary>
public static string ConcatenateZoneClasses(this ICssClassHolder holder, string zoneName, params string[] additionalClasses) =>
holder[zoneName]
.Concat(additionalClasses)
.WhereNot(string.IsNullOrEmpty)
.Join();
}