Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Nustache.Compilation.Tests/Compiled_Templates_Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ public class SubObject
public SubObject Sub { get; set; }
}

public class TreeNode : List<TreeNode>
{
public string Name { get; set; }

public IEnumerable<TreeNode> Children
{
get
{
yield return this;

foreach (var child in this)
{
foreach (var descendant in child.Children)
{
yield return descendant;
}

}
}
}

public TreeNode(string name)
{
Name = name;
}
}


[TestFixture]
public class Compiled_Templates_Support
{
Expand Down Expand Up @@ -219,6 +247,27 @@ public void Partials()
Assert.AreEqual("a I am in you after partial", result);
}

[Test]
public void Partials_Multiple_Usage()
{
var template = Template("{{>text}} after partial {{>text}}");
var compiled = template.Compile<TestObject>(name =>
name == "text" ? Template("{{TestString}} {{#Sub.TestBool}}I am in you{{/Sub.TestBool}}") : null);
var result = compiled(new TestObject { TestString = "a", Sub = new SubObject { TestBool = true } });
Assert.AreEqual("a I am in you after partial a I am in you", result);
}

[Test]
public void Partials_Recursion_Not_Supported()
{
Assert.That(() =>
{
var template = Template(@"{{<recursive_partial}}{{#Children}}<li>{{Name}}<ul>{{>recursive_partial}}</ul></li>{{/Children}}{{/recursive_partial}}{{>recursive_partial}}");
var compiled = template.Compile<TreeNode>(null);
},
Throws.Exception.InstanceOf<NustacheException>().With.Message.StartsWith("You have reached the include limit of"));
}

[Test]
public void Internal_Templates_AKA_Inline_Partials()
{
Expand Down
5 changes: 0 additions & 5 deletions Nustache.Compilation/CompileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class CompileContext
private readonly Stack<Expression> _targetObjectStack = new Stack<Expression>();
private readonly Stack<Section> _sectionStack = new Stack<Section>();
private readonly TemplateLocator templateLocator;
private readonly List<string> _includedTemplates = new List<string>();

public CompileContext(Section section, Type targetType, Expression dataParam, TemplateLocator templateLocator)
{
Expand Down Expand Up @@ -195,10 +194,6 @@ internal Expression Include(string templateName, string indent)

TemplateDefinition templateDefinition = GetTemplateDefinition(templateName);

if (_includedTemplates.Contains(templateName))
throw new NustacheException("Unsupported: Compiled recursive templates will be supported in a later release");
_includedTemplates.Add(templateName);

if (templateDefinition != null)
{
compiled = templateDefinition.Compile(this);
Expand Down