forked from jdiamond/Nustache
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted Container base class. Looking for internal template definit…
…ions uses a Container stack.
- Loading branch information
Showing
11 changed files
with
158 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Nustache.Core | ||
{ | ||
public class Container : Part | ||
{ | ||
private readonly string _name; | ||
private readonly List<Part> _children = new List<Part>(); | ||
private readonly Dictionary<string, TemplateDefinition> _templateDefinitions = | ||
new Dictionary<string, TemplateDefinition>(); | ||
|
||
public Container(string name) | ||
{ | ||
_name = name; | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return _name; } | ||
} | ||
|
||
public IEnumerable<Part> Children { get { return _children; } } | ||
|
||
public void Load(IEnumerable<Part> parts) | ||
{ | ||
foreach (var part in parts) | ||
{ | ||
Add(part); | ||
} | ||
} | ||
|
||
public void Add(Part child) | ||
{ | ||
if (child is TemplateDefinition) | ||
{ | ||
var templateDefinition = (TemplateDefinition)child; | ||
_templateDefinitions.Add(templateDefinition.Name, templateDefinition); | ||
} | ||
else | ||
{ | ||
_children.Add(child); | ||
} | ||
} | ||
|
||
public TemplateDefinition GetTemplateDefinition(string name) | ||
{ | ||
TemplateDefinition templateDefinition; | ||
_templateDefinitions.TryGetValue(name, out templateDefinition); | ||
return templateDefinition; | ||
} | ||
|
||
public override void Render(RenderContext context) | ||
{ | ||
foreach (var child in _children) | ||
{ | ||
child.Render(context); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.