diff --git a/src/ManiaTemplates/Lib/MtTransformer.cs b/src/ManiaTemplates/Lib/MtTransformer.cs
index d51cc78..155623b 100644
--- a/src/ManiaTemplates/Lib/MtTransformer.cs
+++ b/src/ManiaTemplates/Lib/MtTransformer.cs
@@ -58,7 +58,8 @@ public string BuildManialink(MtComponent rootComponent, string className, int ve
XmlStringToNode(rootComponent.TemplateContent),
_engine.BaseMtComponents.Overload(rootComponent.ImportedComponents),
rootContext,
- isRootNode:true
+ parentComponent: rootComponent,
+ isRootNode: true
);
var template = new Snippet
@@ -235,12 +236,12 @@ private string CreateSlotRenderMethod(MtComponent component, int scope, MtDataCo
if (context.ParentContext != null)
{
- output.AppendLine(CreateLocalVariablesFromContext(context.ParentContext));
+ output.AppendLine(CreateLocalVariablesFromContext(context.ParentContext, parentComponent?.Properties.Keys));
variablesInherited.AddRange(context.ParentContext.Keys);
}
output
- .AppendLine(CreateLocalVariablesFromContext(context, variablesInherited))
+ .AppendLine(CreateLocalVariablesFromContext(context, parentComponent?.Properties.Keys))
.AppendLine(_maniaTemplateLanguage.FeatureBlockEnd())
.AppendLine(slotContent)
.AppendLine(_maniaTemplateLanguage.FeatureBlockStart())
@@ -347,7 +348,8 @@ private string ProcessNode(XmlNode node, MtComponentMap availableMtComponents, M
if (hasChildren)
{
subSnippet.AppendLine(1,
- ProcessNode(childNode, availableMtComponents, currentContext));
+ ProcessNode(childNode, availableMtComponents, currentContext,
+ parentComponent: parentComponent));
subSnippet.AppendLine(CreateXmlClosingTag(tag));
}
@@ -530,7 +532,7 @@ private string ProcessComponentNode(
renderComponentCall.Append(
$", __slotRenderer_{parentSlotName}: __slotRenderer_{parentSlotName}");
}
-
+
foreach (var propertyName in parentComponent.Properties.Keys)
{
renderComponentCall.Append($",{propertyName}: {propertyName}");
@@ -540,19 +542,10 @@ private string ProcessComponentNode(
{
foreach (var parentSlotName in component.Slots)
{
- if (isRootNode)
- {
- renderComponentCall.Append(
- $", __slotRenderer_{parentSlotName}: () => DoNothing()");
- }
- else
- {
- renderComponentCall.Append(
- $", __slotRenderer_{parentSlotName}: __slotRenderer_{parentSlotName}");
- }
+ renderComponentCall.Append($", __slotRenderer_{parentSlotName}: () => DoNothing()");
}
}
-
+
renderComponentCall.Append(')');
i++;
@@ -565,7 +558,7 @@ private string ProcessComponentNode(
return renderComponentCall.ToString();
}
-
+
///
/// Creates the method which renders the contents of a component.
///
diff --git a/tests/ManiaTemplates.Tests/IntegrationTests/ManialinkEngineTest.cs b/tests/ManiaTemplates.Tests/IntegrationTests/ManialinkEngineTest.cs
index 6ffa376..486156a 100644
--- a/tests/ManiaTemplates.Tests/IntegrationTests/ManialinkEngineTest.cs
+++ b/tests/ManiaTemplates.Tests/IntegrationTests/ManialinkEngineTest.cs
@@ -88,17 +88,20 @@ await Assert.ThrowsAsync(() =>
[Fact]
public async void Should_Render_Component_Without_Content_For_Slot()
{
- var slotRecursionOuterTwoTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-outer-two.mt");
- var slotRecursionOuterTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-outer.mt");
- var slotRecursionInnerTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-inner.mt");
+ var slotRecursionOuterTwoTemplate =
+ await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-outer-two.mt");
+ var slotRecursionOuterTemplate =
+ await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-outer.mt");
+ var slotRecursionInnerTemplate =
+ await File.ReadAllTextAsync("IntegrationTests/templates/slot-recursion-inner.mt");
var expected = await File.ReadAllTextAsync("IntegrationTests/expected/single-slot-unfilled.xml");
var assemblies = new[] { typeof(ManiaTemplateEngine).Assembly, typeof(ComplexDataType).Assembly };
-
+
_maniaTemplateEngine.AddTemplateFromString("SlotRecursionOuterTwo", slotRecursionOuterTwoTemplate);
_maniaTemplateEngine.AddTemplateFromString("SlotRecursionOuter", slotRecursionOuterTemplate);
_maniaTemplateEngine.AddTemplateFromString("SlotRecursionInner", slotRecursionInnerTemplate);
-
- var template = _maniaTemplateEngine.RenderAsync("SlotRecursionInner", new{}, assemblies).Result;
+
+ var template = _maniaTemplateEngine.RenderAsync("SlotRecursionInner", new { }, assemblies).Result;
Assert.Equal(expected, template, ignoreLineEndingDifferences: true);
}
@@ -110,15 +113,32 @@ public async void Should_Pass_Properties_To_Components_And_Slots()
var testComponentTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/component.mt");
var expected = await File.ReadAllTextAsync("IntegrationTests/expected/property-test.xml");
var assemblies = new[] { typeof(ManiaTemplateEngine).Assembly, typeof(ComplexDataType).Assembly };
-
+
_maniaTemplateEngine.AddTemplateFromString("PropertyTest", propertyTestTemplate);
_maniaTemplateEngine.AddTemplateFromString("Wrapper", testWrapperTemplate);
_maniaTemplateEngine.AddTemplateFromString("TestComponent", testComponentTemplate);
-
+
var template = _maniaTemplateEngine.RenderAsync("PropertyTest", new
{
testVariable = "integration"
}, assemblies).Result;
Assert.Equal(expected, template, ignoreLineEndingDifferences: true);
}
+
+ [Fact]
+ public async void Should_Fill_All_Slots()
+ {
+ var baseTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slots/base.mt");
+ var containerTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slots/container.mt");
+ var windowTemplate = await File.ReadAllTextAsync("IntegrationTests/templates/slots/window.mt");
+ var expected = await File.ReadAllTextAsync("IntegrationTests/expected/slots/manialink.xml");
+ var assemblies = new[] { typeof(ManiaTemplateEngine).Assembly, typeof(ComplexDataType).Assembly };
+
+ _maniaTemplateEngine.AddTemplateFromString("Base", baseTemplate);
+ _maniaTemplateEngine.AddTemplateFromString("Container", containerTemplate);
+ _maniaTemplateEngine.AddTemplateFromString("Window", windowTemplate);
+
+ var template = _maniaTemplateEngine.RenderAsync("Base", new { }, assemblies).Result;
+ Assert.Equal(expected, template, ignoreLineEndingDifferences: true);
+ }
}
\ No newline at end of file
diff --git a/tests/ManiaTemplates.Tests/IntegrationTests/expected/slots/manialink.xml b/tests/ManiaTemplates.Tests/IntegrationTests/expected/slots/manialink.xml
new file mode 100644
index 0000000..9bb5746
--- /dev/null
+++ b/tests/ManiaTemplates.Tests/IntegrationTests/expected/slots/manialink.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/base.mt b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/base.mt
new file mode 100644
index 0000000..f190a0b
--- /dev/null
+++ b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/base.mt
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/container.mt b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/container.mt
new file mode 100644
index 0000000..005b411
--- /dev/null
+++ b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/container.mt
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/window.mt b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/window.mt
new file mode 100644
index 0000000..5a9a4c6
--- /dev/null
+++ b/tests/ManiaTemplates.Tests/IntegrationTests/templates/slots/window.mt
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/ManiaTemplates.Tests/Lib/expected.tt b/tests/ManiaTemplates.Tests/Lib/expected.tt
index 7c1248c..a3a2dda 100644
--- a/tests/ManiaTemplates.Tests/Lib/expected.tt
+++ b/tests/ManiaTemplates.Tests/Lib/expected.tt
@@ -39,11 +39,11 @@ var __outerIndex1 = 0;
foreach (int i in numbers) {
var __index = __outerIndex1;
if (enabled) {
-Render_Component_MtContext2(__data: __data, x: (20 * __index), __slotRenderer_default: () => Render_Slot_3_default(__data: new CRoot_ForEachLoop1(__data){__index = __index, i = i}, __slotRenderer_default: () => DoNothing()));
+Render_Component_MtContext2(__data: __data, x: (20 * __index), __slotRenderer_default: () => Render_Slot_3_default(__data: new CRoot_ForEachLoop1(__data){__index = __index, i = i},numbers: numbers,enabled: enabled));
}
__outerIndex1++;
}
-Render_Component_MtContext2(__data: __data, __slotRenderer_default: () => Render_Slot_4_default(__data: __data, __slotRenderer_default: () => DoNothing()));
+Render_Component_MtContext2(__data: __data, __slotRenderer_default: () => Render_Slot_4_default(__data: __data,numbers: numbers,enabled: enabled));
foreach(var maniaScriptRenderMethod in __maniaScriptRenderMethods){ maniaScriptRenderMethod(); }
#>
<#+
}
-void Render_Slot_3_default(CRoot_ForEachLoop1 __data,Action __slotRenderer_default) {
-var numbers = __data.numbers;
-var enabled = __data.enabled;
+void Render_Slot_3_default(CRoot_ForEachLoop1 __data,List numbers,boolean enabled = true) {
var __index = __data.__index;
var i = __data.i;
var __outerIndex7 = 0;
@@ -115,9 +113,7 @@ Render_Component_MtContext6(__data: __data, arg3: (new test()));
<#+
}
-void Render_Slot_4_default(CRoot __data,Action __slotRenderer_default) {
-var numbers = __data.numbers;
-var enabled = __data.enabled;
-Render_Component_MtContext2(__data: __data, __slotRenderer_default: () => Render_Slot_8_default(__data: __data, __slotRenderer_default: __slotRenderer_default));
+void Render_Slot_4_default(CRoot __data,List numbers,boolean enabled = true) {
+Render_Component_MtContext2(__data: __data, __slotRenderer_default: () => Render_Slot_8_default(__data: __data, __slotRenderer_default: () => DoNothing()));
}
#>
\ No newline at end of file