using System;
using System.Collections.Generic;
namespace mustache
{
///
/// Defines a tag that changes the scope to the object passed as an argument.
///
internal sealed class WithTagDefinition : ContentTagDefinition
{
private const string contextParameter = "context";
///
/// Initializes a new instance of a WithTagDefinition.
///
public WithTagDefinition()
: base("with", true)
{
}
///
/// Gets whether the tag only exists within the scope of its parent.
///
protected override bool GetIsContextSensitive()
{
return false;
}
///
/// Gets the parameters that can be passed to the tag.
///
/// The parameters.
protected override IEnumerable GetParameters()
{
return new TagParameter[] { new TagParameter(contextParameter) { IsRequired = true } };
}
///
/// Gets the scopes to use for generating the tag's content.
///
/// The current scope.
/// The arguments that were passed to the tag.
/// The scopes to use for generating the tag's content.
public override IEnumerable GetChildScopes(KeyScope scope, Dictionary arguments)
{
object context = arguments[contextParameter];
yield return scope.CreateChildScope(context);
}
}
}