Import from internal git
This commit is contained in:
20
Generator/Infrastructure/TemplateFiller/AbstractFiller.cs
Normal file
20
Generator/Infrastructure/TemplateFiller/AbstractFiller.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Core.Templates;
|
||||
|
||||
namespace Generator.Infrastructure.TemplateFiller;
|
||||
|
||||
public abstract class AbstractFiller
|
||||
{
|
||||
protected string Render;
|
||||
protected ITemplate Template;
|
||||
|
||||
/// <summary>
|
||||
/// Fills the text extracted from the template file
|
||||
/// </summary>
|
||||
public abstract void Fill();
|
||||
|
||||
/// <summary>
|
||||
/// Output the filled text in a file
|
||||
/// </summary>
|
||||
/// <param name="outputPath"></param>
|
||||
public abstract void Write(string outputPath);
|
||||
}
|
||||
35
Generator/Infrastructure/TemplateFiller/MustacheFiller.cs
Normal file
35
Generator/Infrastructure/TemplateFiller/MustacheFiller.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Core.Exceptions;
|
||||
using Core.Templates;
|
||||
using Mustache;
|
||||
|
||||
namespace Generator.Infrastructure.TemplateFiller;
|
||||
|
||||
public class MustacheFiller : AbstractFiller
|
||||
{
|
||||
public MustacheFiller(ITemplate template)
|
||||
{
|
||||
Template = template;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Fill()
|
||||
{
|
||||
var compiler = new FormatCompiler
|
||||
{
|
||||
RemoveNewLines = false
|
||||
};
|
||||
var generator = compiler.Compile(Template?.GetText());
|
||||
|
||||
Render = generator.Render(Template?.GetData());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Write(string outputPath)
|
||||
{
|
||||
if (Render == null) throw new FillerException(
|
||||
"Filler Exception : No text can be written. Have you forgot to call the Fill method ?");
|
||||
|
||||
using StreamWriter file = new StreamWriter(outputPath);
|
||||
file.Write(Render);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user