Repository navigation
Expand file tree
/
Copy pathTableTemplate.cs
More file actions
66 lines (62 loc) · 1.98 KB
/
Copy pathTableTemplate.cs
File metadata and controls
66 lines (62 loc) · 1.98 KB
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
using System;
using System.Collections.Generic;
using ServiceStack.Text;
namespace ServiceStack.Metadata
{
internal class TableTemplate
{
public string Title { get; set; }
public IList<string> Items { get; set; }
public IDictionary<string, string> ItemsMap { get; set; }
public IDictionary<int, string> ItemsIntMap { get; set; }
public Func<string, string> ForEachItem { get; set; }
public string ItemTemplate { get; set; }
public override string ToString()
{
var sb = StringBuilderCache.Allocate();
if (!string.IsNullOrEmpty(Title))
{
sb.Append($"<h3>{Title}</h3>");
}
sb.Append("<table>");
sb.Append("<tbody>");
if (ItemTemplate != null)
{
if (Items != null)
{
foreach (var item in Items)
{
sb.AppendFormat(ItemTemplate, item, item);
}
}
if (ItemsMap != null)
{
foreach (var listItem in ItemsMap)
{
sb.AppendFormat(ItemTemplate, listItem.Key, listItem.Value);
}
}
if (ItemsIntMap != null)
{
foreach (var listItem in ItemsIntMap)
{
sb.AppendFormat(ItemTemplate, listItem.Key, listItem.Value);
}
}
}
if (this.ForEachItem != null)
{
if (Items != null)
{
foreach (var item in Items)
{
sb.Append(ForEachItem(item));
}
}
}
sb.Append("</tbody>");
sb.Append("</table>");
return StringBuilderCache.ReturnAndFree(sb);
}
}
}