Ejemplo n.º 1
0
 public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext)
 {
     try
     {
         if (expressions.Any() == false)
         {
             return(_emptyLambda);
         }
         if (expressions.IsOneOf <Expression, DefaultExpression>() == true)
         {
             return(_emptyLambda);
         }
         var compilationContext = new CompilationContext(_configuration);
         var expression         = CreateExpressionBlock(expressions);
         expression = StaticReplacer.Replace(expression, compilationContext);
         expression = PartialBinder.Bind(expression, compilationContext);
         expression = IteratorBinder.Bind(expression, compilationContext);
         expression = BlockHelperFunctionBinder.Bind(expression, compilationContext);
         expression = DeferredSectionVisitor.Bind(expression, compilationContext);
         expression = HelperFunctionBinder.Bind(expression, compilationContext);
         expression = BoolishConverter.Convert(expression, compilationContext);
         expression = PathBinder.Bind(expression, compilationContext);
         expression = ContextBinder.Bind(expression, compilationContext, parentContext);
         return(expression);
     }
     catch (Exception ex)
     {
         throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template", ex);
     }
 }
Ejemplo n.º 2
0
        public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext, string templateName = null)
        {
            try
            {
                var expressionsList = expressions as IList <Expression> ?? expressions.ToList();

                if (expressionsList.Count == 0)
                {
                    return(EmptyLambda);
                }
                if (expressionsList.IsOneOf <Expression, DefaultExpression>())
                {
                    return(EmptyLambda);
                }
                var compilationContext = new CompilationContext(_configuration);
                var expression         = CreateExpressionBlock(expressionsList);
                expression = CommentVisitor.Visit(expression, compilationContext);
                expression = UnencodedStatementVisitor.Visit(expression, compilationContext);
                expression = PartialBinder.Bind(expression, compilationContext);
                expression = StaticReplacer.Replace(expression, compilationContext);
                expression = IteratorBinder.Bind(expression, compilationContext);
                expression = BlockHelperFunctionBinder.Bind(expression, compilationContext);
                expression = DeferredSectionVisitor.Bind(expression, compilationContext);
                expression = HelperFunctionBinder.Bind(expression, compilationContext);
                expression = BoolishConverter.Convert(expression, compilationContext);
                expression = PathBinder.Bind(expression, compilationContext);
                expression = SubExpressionVisitor.Visit(expression, compilationContext);
                expression = ContextBinder.Bind(expression, compilationContext, parentContext, templateName);
                return(expression);
            }
            catch (Exception ex)
            {
                throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template.", ex);
            }
        }