Клинап
This commit is contained in:
@@ -1,70 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mROA.CodegenTools
|
||||
namespace mROA.Codegen.Tools
|
||||
{
|
||||
public class InsertTemplateSection : ITagged, IBaking
|
||||
{
|
||||
private object _insertedValue;
|
||||
private string _tag;
|
||||
public string Tag => _tag;
|
||||
public TemplateDocument Context { get; set; }
|
||||
public readonly List<string> Parameters;
|
||||
private object _insertedValue;
|
||||
|
||||
public InsertTemplateSection(string tag, TemplateDocument context, params string[] parameters)
|
||||
{
|
||||
_tag = tag;
|
||||
Tag = tag;
|
||||
Parameters = parameters.ToList();
|
||||
Context = context;
|
||||
}
|
||||
|
||||
private bool IsInserted(object value)
|
||||
{
|
||||
if (Parameters.IndexOf("r") == -1) return false;
|
||||
|
||||
ProduceInserted(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ProduceInserted(object value)
|
||||
{
|
||||
var currentIndex = Context.Parts.IndexOf(this);
|
||||
var clone = (InsertTemplateSection)MemberwiseClone();
|
||||
clone._tag += "+";
|
||||
|
||||
clone._insertedValue = value;
|
||||
|
||||
Context.Parts.Insert(currentIndex, clone);
|
||||
|
||||
InsertSeparator(currentIndex + 1);
|
||||
}
|
||||
|
||||
private void InsertSeparator(int currentIndex)
|
||||
{
|
||||
var sepIndex = Parameters.IndexOf("sep");
|
||||
if (sepIndex == -1)
|
||||
return;
|
||||
|
||||
Context.Parts.Insert(currentIndex, new LiteralTemplateSection(Context[Parameters[sepIndex + 1]].ToString(), Context));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Setup(object value)
|
||||
{
|
||||
if (!(value is string) && !(value is ITemplateSection) )
|
||||
return;
|
||||
if (IsInserted(value))
|
||||
return;
|
||||
|
||||
_insertedValue = value;
|
||||
}
|
||||
|
||||
|
||||
public int TargetLength => 0;
|
||||
|
||||
public string Bake()
|
||||
{
|
||||
switch (_insertedValue)
|
||||
@@ -78,9 +28,59 @@ namespace mROA.CodegenTools
|
||||
}
|
||||
}
|
||||
|
||||
public string Tag { get; private set; }
|
||||
|
||||
public TemplateDocument Context { get; set; }
|
||||
|
||||
|
||||
public int TargetLength => 0;
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new InsertTemplateSection(_tag, Context, Parameters.ToArray());
|
||||
return new InsertTemplateSection(Tag, Context, Parameters.ToArray());
|
||||
}
|
||||
|
||||
private bool IsInserted(object value)
|
||||
{
|
||||
if (Parameters.IndexOf("r") == -1) return false;
|
||||
|
||||
ProduceInserted(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ProduceInserted(object value)
|
||||
{
|
||||
var currentIndex = Context.Parts.IndexOf(this);
|
||||
var clone = (InsertTemplateSection)MemberwiseClone();
|
||||
clone.Tag += "+";
|
||||
|
||||
clone._insertedValue = value;
|
||||
|
||||
Context.Parts.Insert(currentIndex, clone);
|
||||
|
||||
InsertSeparator(currentIndex + 1);
|
||||
}
|
||||
|
||||
private void InsertSeparator(int currentIndex)
|
||||
{
|
||||
var sepIndex = Parameters.IndexOf("sep");
|
||||
if (sepIndex == -1)
|
||||
return;
|
||||
|
||||
Context.Parts.Insert(currentIndex,
|
||||
new LiteralTemplateSection(Context[Parameters[sepIndex + 1]].ToString(), Context));
|
||||
}
|
||||
|
||||
|
||||
public void Setup(object value)
|
||||
{
|
||||
if (!(value is string) && !(value is ITemplateSection))
|
||||
return;
|
||||
if (IsInserted(value))
|
||||
return;
|
||||
|
||||
_insertedValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user