Пример #1
0
 public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
 {
     foreach (var item in sequence)
     {
         if (item is WordExpressionToken)
         {
             yield return(HandlebarsExpression.Path(((WordExpressionToken)item).Value));
         }
         else
         {
             yield return(item);
         }
     }
 }
        protected override Expression VisitDeferredSectionExpression(DeferredSectionExpression dsex)
        {
            Action <object, BindingContext, Action <TextWriter, object> > method;

            if (dsex.Path.Path.StartsWith("#"))
            {
                method = RenderSection;
            }
            else if (dsex.Path.Path.StartsWith("^"))
            {
                method = RenderEmptySection;
            }
            else
            {
                throw new HandlebarsCompilerException("Tried to compile a section expression that did not begin with # or ^");
            }
            return(Expression.Call(
                       method.Method,
                       HandlebarsExpression.Path(dsex.Path.Path.Substring(1)),
                       _context.BindingContext,
                       new FunctionBuilder(_context.Configuration).Compile(dsex.Body, _context.BindingContext)));
        }