/// <summary>
        /// Gets the arguments and mapped parameters from the given node.
        /// </summary>
        /// <param name="block">The target block.</param>
        /// <param name="context">The render context.</param>
        /// <returns>The set of arguments and mapped parameters.</returns>
        protected virtual Tuple <object[], Dictionary <string, object> > GetArgumentsAndMappedParameters(Block block, RenderContext context)
        {
            var arguments = new List <object>();
            var maps      = new Dictionary <string, object>();

            var items = block.Children.OfType <Span>().Where(c => c.Kind == SpanKind.Parameter || c.Kind == SpanKind.Map);

            foreach (var span in items)
            {
                if (span.Kind == SpanKind.Parameter)
                {
                    arguments.Add(context.ResolveValue(span));
                }
                else
                {
                    var    symbols = span.Symbols.Cast <HandlebarsSymbol>().ToList();
                    string key     = symbols[0].Content;

                    object value = context.ResolveValue(span);

                    if (maps.ContainsKey(key))
                    {
                        maps[key] = value;
                    }
                    else
                    {
                        maps.Add(key, value);
                    }
                }
            }

            return(Tuple.Create(arguments.ToArray(), maps));
        }
        /// <inheritdoc />
        protected override void Render(Block block, object[] arguments, Dictionary <string, object> maps, RenderContext context, TextWriter writer)
        {
            string name = block.Name;

            var children = block.Children.ToList();

            // Get the TagElement block.
            var tagElement = (Block)children[0];
            // Determine if the block prefix symbol (either # or ^) is a caret.
            bool isNegatedSection = tagElement.Children.Cast <Span>().Where(s => s.Kind == SpanKind.MetaCode).ToArray()[1].Content == "^";

            children.RemoveAt(0);
            children.RemoveAt(children.Count - 1);

            if (string.IsNullOrEmpty(name))
            {
                // Nothing we can do.
                return;
            }

            object value = context.ResolveValue(name, false);

            if (value == null && !isNegatedSection)
            {
                // No value, nothing we can do :-(
                return;
            }

            if ((value is IEnumerable) && !(value is string) && !isNegatedSection)
            {
                RenderEnumerable((IEnumerable)value, context, children, null);
            }
            else
            {
                bool isTruthy = IsTruthy(value);

                // Treat this as a conditional block.
                if (isTruthy != isNegatedSection)
                {
                    if (isTruthy)
                    {
                        // Create a scope around the value.
                        using (var scope = context.BeginScope(value))
                        {
                            RenderChildren(children, context);
                        }
                    }
                    else
                    {
                        RenderChildren(children, context);
                    }
                }
            }
        }
		/// <inheritdoc />
		protected override void Render(Block block, object[] arguments, Dictionary<string, object> maps, RenderContext context, TextWriter writer)
		{
			string name = block.Name;

			var children = block.Children.ToList();

			// Get the TagElement block.
			var tagElement = (Block)children[0];
			// Determine if the block prefix symbol (either # or ^) is a caret.
			bool isNegatedSection = tagElement.Children.Cast<Span>().Where(s => s.Kind == SpanKind.MetaCode).ToArray()[1].Content == "^";

			children.RemoveAt(0);
			children.RemoveAt(children.Count - 1);

			if (string.IsNullOrEmpty(name))
			{
				// Nothing we can do.
				return;
			}

			object value = context.ResolveValue(name, false);
			if (value == null && !isNegatedSection)
			{
				// No value, nothing we can do :-(
				return;
			}

			if ((value is IEnumerable) && !(value is string) && !isNegatedSection)
			{
				RenderEnumerable((IEnumerable)value, context, children, null);
			}
			else
			{
				bool isTruthy = IsTruthy(value);

				// Treat this as a conditional block.
				if (isTruthy != isNegatedSection)
				{
					if (isTruthy)
					{
						// Create a scope around the value.
						using (var scope = context.BeginScope(value))
						{
							RenderChildren(children, context);
						}
					}
					else
					{
						RenderChildren(children, context);
					}
				}
			}
		}
		/// <inheritdoc />
		public override void Render(Span target, RenderContext context, TextWriter writer)
		{
			object value = context.ResolveValue(target);

			Write(context, writer, value);
		}
Beispiel #5
0
        /// <inheritdoc />
        public override void Render(Span target, RenderContext context, TextWriter writer)
        {
            object value = context.ResolveValue(target);

            Write(context, writer, value);
        }