2013-07-20 16:06:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Mustache
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Defines a tag that outputs the current index within an each loop.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal sealed class IndexTagDefinition : InlineTagDefinition
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of an IndexTagDefinition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IndexTagDefinition()
|
2013-08-17 03:35:46 +00:00
|
|
|
|
: base("index", true)
|
2013-07-20 16:06:38 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the text to output.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="writer">The writer to write the output to.</param>
|
|
|
|
|
/// <param name="arguments">The arguments passed to the tag.</param>
|
2013-08-17 03:35:46 +00:00
|
|
|
|
/// <param name="contextScope">Extra data passed along with the context.</param>
|
|
|
|
|
public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope contextScope)
|
2013-07-20 16:06:38 +00:00
|
|
|
|
{
|
2013-08-17 03:35:46 +00:00
|
|
|
|
object index;
|
|
|
|
|
if (contextScope.TryFind("index", out index))
|
|
|
|
|
{
|
|
|
|
|
writer.Write(index);
|
|
|
|
|
}
|
2013-07-20 16:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|