private static void RenderEmptySection(object value, BindingContext context, Action<TextWriter, object> template)
 {
     if(IsFalseyOrEmpty(value) == false)
     {
         throw new HandlebarsRuntimeException("Tried to render a truthy or non-empty object in an inverted section");
     }
     template(context.TextWriter, null);
 }
Пример #2
0
 private static void InvokePartial(
     string partialName,
     BindingContext context,
     HandlebarsConfiguration configuration)
 {
     if(configuration.RegisteredTemplates.ContainsKey(partialName) == false)
     {
         throw new HandlebarsRuntimeException("Referenced partial name could not be resolved");
     }
     configuration.RegisteredTemplates[partialName](context.TextWriter, context);
 }
 private static void RenderSection(object value, BindingContext context, Action<TextWriter, object> template)
 {
     if(IsFalseyOrEmpty(value))
     {
         throw new HandlebarsRuntimeException("Tried to render a falsey or empty object in a section");
     }
     if(value is IEnumerable)
     {
         foreach(var item in ((IEnumerable)value))
         {
             template(context.TextWriter, item);
         }
     }
     else if(value != null)
     {
         template(context.TextWriter, value);
     }
     else
     {
         throw new HandlebarsRuntimeException("Could not render value for the section");
     }
 }
Пример #4
0
 public BindingContext(object value, TextWriter writer, BindingContext parent)
 {
     _value  = value;
     _writer = writer;
     _parent = parent;
 }
Пример #5
0
 public BindingContext(object value, TextWriter writer, BindingContext parent)
 {
     _value = value;
     _writer = writer;
     _parent = parent;
 }
Пример #6
0
 public ObjectEnumeratorBindingContext(BindingContext context)
     : base(context.Value, context.TextWriter, context.ParentContext)
 {
 }
Пример #7
0
        //TODO: make path resolution logic smarter
        private object ResolvePath(BindingContext context, string path)
        {
            if (_resolutionCache.ContainsKey(context) && _resolutionCache[context].ContainsKey(path))
            {
                return _resolutionCache[context][path];
            }
            var instance = context.Value;
            foreach(var segment in path.Split ('/'))
            {
                if(segment == "..")
                {
                    context = context.ParentContext;
                    if(context == null)
                    {
                        throw new HandlebarsCompilerException("Path expression tried to reference parent of root");
                    }
                }
                else if(segment == "this")
                {
                    continue;
                }
                else if (segment.StartsWith("@"))
                {
                    var contextValue = context.GetContextVariable(segment.Substring(1));
                    if (contextValue == null)
                    {
                        throw new HandlebarsRuntimeException("Couldn't bind to context variable");
                    }
                    instance = contextValue;
                    break;
                }
                else
                {
                    foreach (var memberName in segment.Split('.'))
                    {
                        try
                        {
                            instance = AccessMember(instance, memberName);
                        }
                        catch (Exception)
                        {
                            instance = new UndefinedBindingResult();
                            break;
                        }
                    }
                }
            }
            if (_resolutionCache.ContainsKey(context) == false)
            {
                _resolutionCache.Add(context, new Dictionary<string, object>());
            }
            _resolutionCache[context].Add(path, instance);
			return instance;
        }
Пример #8
0
 public ObjectEnumeratorBindingContext(BindingContext context)
     : base(context.Value, context.TextWriter, context.ParentContext)
 {
 }