Beispiel #1
0
        /// <summary>
        /// Renders the code block specified into a string
        /// </summary>
        /// <param name="context">The template context</param>
        /// <param name="block">The code block to render</param>
        /// <param name="flags">The template flags</param>
        /// <returns>The rendered block</returns>
        public string Render
        (
            ref TemplateContext context,
            CodeBlock block,
            params TemplateFlag[] flags
        )
        {
            Validate.IsNotNull(block);

            var loop = (WhileLoop)block;

            var result = _expressionEvaluator.Evaluate
                         (
                ref context,
                loop.ConditionExpression
                         );

            var builder = new StringBuilder();

            while (result)
            {
                var renderedBody = _collectionRenderer.Render
                                   (
                    ref context,
                    loop.Blocks,
                    flags
                                   );

                builder.Append(renderedBody);

                result = _expressionEvaluator.Evaluate
                         (
                    ref context,
                    loop.ConditionExpression
                         );
            }

            return(builder.ToString());
        }
        /// <summary>
        /// Renders the code block specified into a string
        /// </summary>
        /// <param name="context">The template context</param>
        /// <param name="block">The code block to render</param>
        /// <param name="flags">The template flags</param>
        /// <returns>The rendered block</returns>
        public string Render
        (
            ref TemplateContext context,
            CodeBlock block,
            params TemplateFlag[] flags
        )
        {
            Validate.IsNotNull(block);

            var binding = (ConditionalBinding)block;
            var value   = default(object);

            var result = _expressionEvaluator.Evaluate
                         (
                ref context,
                binding.ConditionExpression
                         );

            if (result)
            {
                value = ResolveValue
                        (
                    ref context,
                    binding.TrueValue,
                    binding.TrueValueType
                        );
            }
            else
            {
                value = ResolveValue
                        (
                    ref context,
                    binding.FalseValue,
                    binding.FalseValueType
                        );
            }

            return(ToString(value, flags));
        }
Beispiel #3
0
        /// <summary>
        /// Renders the code block specified into a string
        /// </summary>
        /// <param name="context">The template context</param>
        /// <param name="block">The code block to render</param>
        /// <param name="flags">The template flags</param>
        /// <returns>The rendered block</returns>
        public string Render
        (
            ref TemplateContext context,
            CodeBlock block,
            params TemplateFlag[] flags
        )
        {
            Validate.IsNotNull(block);

            var statement    = (IfStatement)block;
            var renderedBody = String.Empty;

            var result = _expressionEvaluator.Evaluate
                         (
                ref context,
                statement.ConditionExpression
                         );

            if (result)
            {
                renderedBody = _collectionRenderer.Render
                               (
                    ref context,
                    statement.Blocks,
                    flags
                               );
            }
            else if (statement.ElseIfConditions.Any())
            {
                foreach (var elseCondition in statement.ElseIfConditions)
                {
                    result = _expressionEvaluator.Evaluate
                             (
                        ref context,
                        elseCondition.ConditionExpression
                             );

                    if (result)
                    {
                        renderedBody = _collectionRenderer.Render
                                       (
                            ref context,
                            elseCondition.Blocks,
                            flags
                                       );

                        break;
                    }
                }
            }

            if (false == result && statement.ElseContent != null)
            {
                renderedBody = _collectionRenderer.Render
                               (
                    ref context,
                    statement.ElseContent.Blocks,
                    flags
                               );
            }

            return(renderedBody);
        }