Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (36 sloc) 1.3 KB
using System.Linq;
using System.Collections.Generic;
using ServiceStack.Templates;
namespace MvcTemplates
{
public class CustomTemplateFilters : TemplateFilter
{
public Dictionary<int, KeyValuePair<string, string>> DocsIndex { get; } = new Dictionary<int, KeyValuePair<string, string>>();
public object prevDocLink(int order)
{
if (DocsIndex.TryGetValue(order - 1, out KeyValuePair<string,string> entry))
return entry;
return null;
}
public object nextDocLink(int order)
{
if (DocsIndex.TryGetValue(order + 1, out KeyValuePair<string,string> entry))
return entry;
return null;
}
List<KeyValuePair<string,string>> sortedDocLinks;
public object docLinks() => sortedDocLinks ?? (sortedDocLinks = sortLinks(DocsIndex));
public List<KeyValuePair<string,string>> sortLinks(Dictionary<int, KeyValuePair<string,string>> links)
{
var sortedKeys = links.Keys.ToList();
sortedKeys.Sort();
var to = new List<KeyValuePair<string,string>>();
foreach (var key in sortedKeys)
{
var entry = links[key];
to.Add(entry);
}
return to;
}
}
}