68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
// /**
|
|
// * File: TemplateElement.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ln.templates.html
|
|
{
|
|
public class TemplateElement : Element
|
|
{
|
|
Dictionary<string, Expression> expressions = new Dictionary<string, Expression>();
|
|
Dictionary<string, Expression> loops = new Dictionary<string, Expression>();
|
|
List<Expression> conditions = new List<Expression>();
|
|
|
|
|
|
public TemplateElement(string tagName)
|
|
:base(tagName)
|
|
{
|
|
}
|
|
|
|
public override void SetAttribute(string attributeName, string attributeValue)
|
|
{
|
|
if (attributeName.StartsWith("v-for:",StringComparison.InvariantCultureIgnoreCase))
|
|
loops.Add(attributeName.Substring(6), new Expression(attributeValue));
|
|
else if (attributeName.Equals("v-if",StringComparison.InvariantCultureIgnoreCase))
|
|
conditions.Add(new Expression(attributeValue));
|
|
else if (attributeName[0] == ':')
|
|
expressions.Add(attributeName.Substring(1), new Expression(attributeValue));
|
|
else
|
|
base.SetAttribute(attributeName, attributeValue);
|
|
}
|
|
|
|
public virtual void RenderTemplate(RenderContext renderContext)
|
|
{
|
|
|
|
|
|
renderContext.ContentWriter.Write("<{0}", Name);
|
|
foreach (KeyValuePair<String, String> attributePair in Attributes)
|
|
renderContext.ContentWriter.Write(" {0}=\"{1}\"", attributePair.Key, attributePair.Value);
|
|
renderContext.ContentWriter.Write(">");
|
|
|
|
if (!IsVoid)
|
|
{
|
|
foreach (Element element in Children)
|
|
{
|
|
if (element is TemplateElement templateElement)
|
|
{
|
|
templateElement.RenderTemplate(renderContext);
|
|
}
|
|
else
|
|
{
|
|
renderContext.ContentWriter.Write(element.ToString());
|
|
}
|
|
}
|
|
renderContext.ContentWriter.Write("</{0}>", Name);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|