diff --git a/Nustache.Core/StartSection.cs b/Nustache.Core/Block.cs
similarity index 72%
rename from Nustache.Core/StartSection.cs
rename to Nustache.Core/Block.cs
index 76f495e..1260b3d 100644
--- a/Nustache.Core/StartSection.cs
+++ b/Nustache.Core/Block.cs
@@ -1,8 +1,8 @@
namespace Nustache.Core
{
- public class StartSection : Container
+ public class Block : Section
{
- public StartSection(string name, params Part[] children)
+ public Block(string name, params Part[] children)
: base(name)
{
Load(children);
@@ -22,7 +22,7 @@ public override void Render(RenderContext context)
#region Boring stuff
- public bool Equals(StartSection other)
+ public bool Equals(Block other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
@@ -33,8 +33,8 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof(StartSection)) return false;
- return Equals((StartSection)obj);
+ if (obj.GetType() != typeof(Block)) return false;
+ return Equals((Block)obj);
}
public override int GetHashCode()
@@ -44,7 +44,7 @@ public override int GetHashCode()
public override string ToString()
{
- return string.Format("StartSection(\"{0}\")", Name);
+ return string.Format("Block(\"{0}\")", Name);
}
#endregion
diff --git a/Nustache.Core/Nustache.Core.csproj b/Nustache.Core/Nustache.Core.csproj
index c153d49..8a9c29d 100644
--- a/Nustache.Core/Nustache.Core.csproj
+++ b/Nustache.Core/Nustache.Core.csproj
@@ -45,7 +45,7 @@
-
+
@@ -55,7 +55,7 @@
-
+
diff --git a/Nustache.Core/Parser.cs b/Nustache.Core/Parser.cs
index 7af5a33..2fb913d 100644
--- a/Nustache.Core/Parser.cs
+++ b/Nustache.Core/Parser.cs
@@ -1,38 +1,32 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
namespace Nustache.Core
{
public class Parser
{
- public IEnumerable Parse(IEnumerable parts)
+ public void Parse(Section section, IEnumerable parts)
{
- var containerStack = new Stack();
- Container container = null;
+ if (section == null)
+ throw new ArgumentNullException("section");
+
+ var sectionStack = new Stack();
+ sectionStack.Push(section);
foreach (var part in parts)
{
- if (container != null)
- {
- container.Add(part);
- }
- else
- {
- if (!(part is Container))
- {
- yield return part;
- }
- }
+ section.Add(part);
- if (part is Container)
+ if (part is Section)
{
- containerStack.Push(container);
- container = (Container)part;
+ sectionStack.Push(section);
+ section = (Section)part;
}
else if (part is EndSection)
{
var endSection = (EndSection)part;
- if (container == null)
+ if (sectionStack.Count == 1)
{
throw new NustacheException(
string.Format(
@@ -40,23 +34,16 @@ public IEnumerable Parse(IEnumerable parts)
endSection.Name));
}
- if (endSection.Name != container.Name)
+ if (endSection.Name != section.Name)
{
throw new NustacheException(
string.Format(
"End section {0} does not match start section {1}!",
endSection.Name,
- container.Name));
- }
-
- var lastStartSection = containerStack.Pop();
-
- if (lastStartSection == null)
- {
- yield return container;
+ section.Name));
}
- container = lastStartSection;
+ section = sectionStack.Pop();
}
}
}
diff --git a/Nustache.Core/RenderContext.cs b/Nustache.Core/RenderContext.cs
index 2380567..1f49efa 100644
--- a/Nustache.Core/RenderContext.cs
+++ b/Nustache.Core/RenderContext.cs
@@ -8,7 +8,7 @@ namespace Nustache.Core
public class RenderContext
{
private const int IncludeLimit = 1024;
- private readonly Stack _containerStack = new Stack();
+ private readonly Stack _sectionStack = new Stack();
private readonly Stack
-
+