Import from internal git

This commit is contained in:
2025-10-11 13:08:09 +02:00
commit 97aaa715dc
175 changed files with 7014 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
namespace Core.Templates;
public interface ITemplateFactory
{
public ITemplate GetTemplate(string templatePath, IDictionary<string, object> data);
}

View File

@@ -0,0 +1,9 @@
using System.Collections;
namespace Core.Templates;
public interface ITemplate
{
public IEnumerable GetData();
public string GetText();
}

View File

@@ -0,0 +1,23 @@
using System.Collections;
namespace Core.Templates;
public class MustacheTemplate : ITemplate
{
private readonly string _text;
private readonly TemplateData<string, object> _data;
public MustacheTemplate(string text)
{
_text = text;
_data = new TemplateData<string, object>();
}
public void AddProperties(IDictionary<string, object> data)
{
_data.AddAll(data);
}
public IEnumerable GetData() => _data.GetData();
public string GetText() => _text;
}

View File

@@ -0,0 +1,19 @@
using Core.Helpers;
namespace Core.Templates;
public class MustacheTemplateFactory : ITemplateFactory
{
public MustacheTemplateFactory()
{
}
public ITemplate GetTemplate(string templatePath, IDictionary<string, object> data)
{
var text = PathHelper.TextFrom(templatePath);
var template = new MustacheTemplate(text);
template.AddProperties(data);
return template;
}
}

View File

@@ -0,0 +1,29 @@
using Services.Common.ObjUtils;
namespace Core.Templates;
public class TemplateData<TK, TV> where TK : notnull
{
private IDictionary<TK, TV> _data;
public TemplateData()
{
_data = new Dictionary<TK, TV>();
}
public void Add(TK key, TV value)
{
_data.Add(key, value);
}
public void AddAll(IDictionary<TK, TV> properties)
{
foreach (var item in properties)
{
_data.Add(item);
}
}
public IDictionary<TK, TV> GetData() => _data.Clone();
}