encapsulate template logic

This commit is contained in:
Ivan Ansimov
2025-07-15 16:37:06 +03:00
parent ec4c008d4c
commit 1cde4b0ed0
12 changed files with 453 additions and 171 deletions
+45
View File
@@ -0,0 +1,45 @@
using mROA.CodegenTools;
using mROA.CodegenTools.Reading;
namespace mROA.Codegen.Templates
{
public abstract class TemplateView
{
private readonly TemplateDocument _template;
protected TemplateView(string templateFile)
{
_template = TemplateReader.FromEmbeddedResource(templateFile);
}
protected TemplateView(TemplateDocument template)
{
_template = template;
}
public string Compile()
{
return _template.Compile();
}
protected void Define(string tag, string value)
{
_template.AddDefine(tag, value);
}
protected void Insert(string tag, string value)
{
_template.Insert(tag, value);
}
protected bool Inserted(string tag)
{
return _template[$"{tag}+"] != null;
}
protected TemplateDocument CloneInner(string tag)
{
return _template.CloneInnerTemplate(tag);
}
}
}