48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using System.Runtime.Remoting.Contexts;
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|