protected override Expression VisitBoolishExpression(BoolishExpression bex)
        {
            var condition = Visit(bex.Condition);

            condition = FunctionBuilder.Reduce(condition, _compilationContext);
            var @object = ExpressionShortcuts.Arg <object>(condition);

            return(ExpressionShortcuts.Call(() => HandlebarsUtils.IsTruthyOrNonEmpty(@object)));
        }
Beispiel #2
0
        public void Execute(IHandlebarsEngine engine, TextWriter output, HandlebarsBlockHelperOptions options,
                            dynamic context, params object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new HandlebarsException("{{with}} helper must have exactly one argument");
            }

            if (HandlebarsUtils.IsTruthyOrNonEmpty(arguments[0]))
            {
                options.Template(output, arguments[0]);
            }
            else
            {
                options.Inverse(output, context);
            }
        }
        private static void With(TextWriter output, HelperOptions options, dynamic context, params object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new HandlebarsException("{{with}} helper must have exactly one argument");
            }

            options.BlockParams(WithBlockParamsConfiguration, arguments[0]);

            if (HandlebarsUtils.IsTruthyOrNonEmpty(arguments[0]))
            {
                options.Template(output, arguments[0]);
            }
            else
            {
                options.Inverse(output, context);
            }
        }
 private void RegisterIfAndHelper(IHandlebars hbs)
 {
     hbs.RegisterHelper("ifand", (writer, options, context, arguments) =>
     {
         bool res = true;
         foreach (var arg in arguments)
         {
             res = res && HandlebarsUtils.IsTruthyOrNonEmpty(arg);
         }
         if (res)
         {
             options.Template(writer, (object)context);
         }
         else
         {
             options.Inverse(writer, (object)context);
         }
     });
 }
        public override void Invoke(TextWriter output, HelperOptions options, object context, params object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new HandlebarsException("{{with}} helper must have exactly one argument");
            }

            if (HandlebarsUtils.IsTruthyOrNonEmpty(arguments[0]))
            {
                using var frame = options.CreateFrame(arguments[0]);
                var blockParamsValues = new BlockParamsValues(frame, options.BlockParams);

                blockParamsValues.CreateProperty(0, out var _0);

                blockParamsValues[_0] = arguments[0];

                options.Template(output, frame);
            }
            else
            {
                options.Inverse(output, context);
            }
        }