46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
namespace ln.templates.elements
|
|||
|
{
|
|||
|
public class IncludeElement : Element
|
|||
|
{
|
|||
|
Expression TargetExpression { get; set; }
|
|||
|
|
|||
|
public IncludeElement(ContainerElement container,Expression targetExpression)
|
|||
|
:base(container)
|
|||
|
{
|
|||
|
TargetExpression = targetExpression;
|
|||
|
}
|
|||
|
|
|||
|
public void Generate(TextWriter writer, Template.Context context,String templatePath)
|
|||
|
{
|
|||
|
Template iTemplate = context.Provider.FindTemplate(templatePath);
|
|||
|
Template.Context iContext = new Template.Context(context, null);
|
|||
|
String iContent = iTemplate.Generate(iContext);
|
|||
|
|
|||
|
writer.Write(iContent);
|
|||
|
}
|
|||
|
|
|||
|
public override void Generate(TextWriter writer, Template.Context context)
|
|||
|
{
|
|||
|
object target = TargetExpression.Evaluate(context.ExpressionContext);
|
|||
|
|
|||
|
if (target is IEnumerable<String>)
|
|||
|
{
|
|||
|
IEnumerable<String> targets = (IEnumerable<String>)target;
|
|||
|
foreach (String t in targets)
|
|||
|
{
|
|||
|
Generate(writer, context, t);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Generate(writer, context, target as String);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|