Skip to content

Commit

Permalink
Merge branch 'gordonmleigh-90a696d' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanx committed Apr 14, 2015
2 parents f37ab5e + 0a74253 commit 4cbc281
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Nustache.Core.Tests/Describe_Template_Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using System.Collections.Generic;
using System;

namespace Nustache.Core.Tests
{
Expand Down Expand Up @@ -214,6 +216,42 @@ public void It_can_include_templates_defined_in_outer_templates()
Assert.AreEqual("beforeOUTSIDEafter", result);
}

[Test]
public void It_can_include_templates_over_three_levels()
{
var result = Render.StringToString("{{<t1}}One{{/t1}}{{<t2}}{{>t1}}Two{{/t2}}{{<t3}}{{>t2}}Three{{/t3}}{{>t3}}", null);

Assert.AreEqual("OneTwoThree", result);
}


[Test]
public void It_can_include_templates_over_three_levels_with_external_includes()
{
var baseTemplate = new Template("Base");
baseTemplate.Load(new StringReader("Base{{>BaseContent}}"));

var masterTemplate = new Template("Master");
masterTemplate.Load(new StringReader("{{<BaseContent}}Master{{>MasterContent}}{{/BaseContent}}{{>Base}}"));

var templates = new Dictionary<string, Template>();
templates.Add("Base", baseTemplate);
templates.Add("Master", masterTemplate);

TemplateLocator locateTemplate =
name =>
{
Template ret;
templates.TryGetValue(name, out ret);
if (ret == null) throw new KeyNotFoundException(string.Format("The view '{0}' could not be found.", name));
return ret;
};

var result = Render.StringToString("{{<MasterContent}}Hello{{/MasterContent}}{{>Master}}", null, locateTemplate);

Assert.AreEqual("BaseMasterHello", result);
}

[Test]
public void It_allows_templates_to_be_overridden_in_sections()
{
Expand Down
4 changes: 4 additions & 0 deletions Nustache.Core/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ public void Include(string templateName, string indent)

if (template != null)
{
// push the included template on the stack so that internally defined templates can be resolved properly later.
// designed to pass test Describe_Template_Render.It_can_include_templates_over_three_levels_with_external_includes()
this.Enter(template);
template.Render(this);
this.Exit();
}
}

Expand Down

0 comments on commit 4cbc281

Please sign in to comment.