Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

54 lines (44 sloc) 1.381 kB
using System;
using System.Text.RegularExpressions;
namespace Nustache.Core
{
public class VariableReference : Part
{
private static readonly Regex _notEscapedRegex = new Regex(@"^\{(.+?)\}$");
private readonly string _path;
private readonly bool _escaped;
public VariableReference(string path)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
_path = path;
var match = _notEscapedRegex.Match(path);
_escaped = !match.Success;
if (match.Success)
{
_path = match.Groups[1].Value;
}
}
public string Path { get { return _path; } }
public override void Render(RenderContext context)
{
object value = context.GetValue(_path);
if (value != null)
{
context.Write(_escaped
? Encoders.HtmlEncode(value.ToString())
: value.ToString());
}
}
public override string Source()
{
return "{{" + _path + "}}";
}
public override string ToString()
{
return string.Format("VariableReference(\"{0}\")", _path);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.