Helper() public static méthode

public static Helper ( string helperName ) : HandlebarsDotNet.Compiler.HelperExpression
helperName string
Résultat HandlebarsDotNet.Compiler.HelperExpression
 Expression Visit(Expression expression)
 {
     if (expression is HelperExpression helperExpression)
     {
         var originalArguments = helperExpression.Arguments.ToArray();
         var arguments         = ConvertTokens(originalArguments)
                                 .Cast <Expression>()
                                 .ToArray();
         if (!arguments.SequenceEqual(originalArguments))
         {
             return(HandlebarsExpression.Helper(
                        helperExpression.HelperName,
                        arguments,
                        helperExpression.IsRaw));
         }
     }
     if (expression is SubExpressionExpression subExpression)
     {
         Expression childExpression = Visit(subExpression.Expression);
         if (childExpression != subExpression.Expression)
         {
             return(HandlebarsExpression.SubExpression(childExpression));
         }
     }
     return(expression);
 }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                if (item is StartExpressionToken)
                {
                    yield return(item);

                    item = GetNext(enumerator);
                    if (item is Expression)
                    {
                        yield return(item);

                        continue;
                    }
                    var word = item as WordExpressionToken;
                    if (word != null && IsRegisteredHelperName(word.Value))
                    {
                        yield return(HandlebarsExpression.Helper(word.Value));
                    }
                    else
                    {
                        yield return(item);
                    }
                }
                else
                {
                    yield return(item);
                }
            }
        }
        protected virtual Expression VisitHelperExpression(HelperExpression hex)
        {
            var arguments = VisitExpressionList(hex.Arguments);

            if (arguments != hex.Arguments)
            {
                return(HandlebarsExpression.Helper(hex.HelperName, hex.IsBlock, arguments, hex.IsRaw));
            }
            return(hex);
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                switch (item)
                {
                case HelperExpression helper:
                {
                    var helperArguments = AccumulateArguments(enumerator);
                    yield return(HandlebarsExpression.Helper(
                                     helper.HelperName,
                                     helper.IsBlock,
                                     helperArguments,
                                     helper.IsRaw));

                    yield return(enumerator.Current);

                    break;
                }

                case PathExpression path:
                {
                    var helperArguments = AccumulateArguments(enumerator);
                    if (helperArguments.Count > 0)
                    {
                        yield return(HandlebarsExpression.Helper(
                                         path.Path,
                                         false,
                                         helperArguments,
                                         ((EndExpressionToken)enumerator.Current)?.IsRaw ?? false));

                        yield return(enumerator.Current);
                    }
                    else
                    {
                        yield return(path);

                        yield return(enumerator.Current);
                    }

                    break;
                }

                default:
                    yield return(item);

                    break;
                }
            }
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                if (!(item is StartExpressionToken token))
                {
                    yield return(item);

                    continue;
                }

                var isRaw = token.IsRaw;
                yield return(token);

                item = GetNext(enumerator);
                switch (item)
                {
                case Expression _:
                    yield return(item);

                    continue;

                case WordExpressionToken word when IsRegisteredHelperName(word.Value):
                    yield return(HandlebarsExpression.Helper(word.Value, false, isRaw, word.Context));

                    break;

                case WordExpressionToken word when IsRegisteredBlockHelperName(word.Value, isRaw):
                {
                    yield return(HandlebarsExpression.Helper(word.Value, true, isRaw, word.Context));

                    break;
                }

                case WordExpressionToken word when IsUnregisteredBlockHelperName(word.Value, isRaw, sequence):
                {
                    var expression = HandlebarsExpression.Helper(word.Value, true, isRaw, word.Context);
                    expression.IsBlock = true;
                    yield return(expression);

                    break;
                }

                default:
                    yield return(item);

                    break;
                }
            }
        }
        private static SubExpressionExpression BuildSubExpression(IEnumerator <object> enumerator)
        {
            object item = GetNext(enumerator);
            var    path = item as PathExpression;

            if (path == null)
            {
                throw new HandlebarsCompilerException("Found a sub-expression that does not contain a path expression");
            }
            var helperArguments = AccumulateSubExpression(enumerator);

            return(HandlebarsExpression.SubExpression(
                       HandlebarsExpression.Helper(
                           path.Path,
                           helperArguments)));
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                if (item is StartExpressionToken)
                {
                    var isRaw = ((StartExpressionToken)item).IsRaw;
                    yield return(item);

                    item = GetNext(enumerator);
                    if (item is Expression)
                    {
                        yield return(item);

                        continue;
                    }
                    if (item is WordExpressionToken word)
                    {
                        if (IsRegisteredHelperName(word.Value))
                        {
                            yield return(HandlebarsExpression.Helper(word.Value));
                        }
                        else if (IsRegisteredBlockHelperName(word.Value, isRaw))
                        {
                            yield return(HandlebarsExpression.Helper(word.Value, isRaw));
                        }
                        else
                        {
                            yield return(item);
                        }
                    }
                    else
                    {
                        yield return(item);
                    }
                }
                else
                {
                    yield return(item);
                }
            }
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                if (item is HelperExpression)
                {
                    var helper          = item as HelperExpression;
                    var helperArguments = AccumulateArguments(enumerator);
                    yield return(HandlebarsExpression.Helper(
                                     helper.HelperName,
                                     helperArguments,
                                     helper.IsRaw));

                    yield return(enumerator.Current);
                }
                else if (item is PathExpression)
                {
                    var helperArguments = AccumulateArguments(enumerator);
                    if (helperArguments.Count > 0)
                    {
                        var path = item as PathExpression;
                        yield return(HandlebarsExpression.Helper(
                                         path.Path,
                                         helperArguments,
                                         (enumerator.Current as EndExpressionToken).IsRaw));

                        yield return(enumerator.Current);
                    }
                    else
                    {
                        yield return(item);

                        yield return(enumerator.Current);
                    }
                }
                else
                {
                    yield return(item);
                }
            }
        }
Exemple #9
0
 protected override Expression VisitHelperExpression(HelperExpression hex)
 {
     return(HandlebarsExpression.Helper(
                hex.HelperName,
                hex.Arguments.Select(Visit)));
 }