示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        public override void Render(Context context, TextWriter result)
        {
            var blockState = BlockRenderState.Find(context);

            context.Stack(() =>
            {
                context["block"] = new BlockDrop(context.Template, this, result);
                RenderAll(GetNodeList(blockState), context, result);
            });
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        public void CallSuper(Context context, TextWriter result)
        {
            var blockState = BlockRenderState.Find(context);

            if (blockState != null &&
                blockState.Parents.TryGetValue(this, out var parent) &&
                parent != null)
            {
                parent.Render(context, result);
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        public override void Render(Context context, TextWriter result)
        {
            // Get the template or template content and then either copy it (since it will be modified) or parse it
            var      fileSystem         = context.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            var      templateFileSystem = fileSystem as ITemplateFileSystem;
            Template template           = null;

            if (templateFileSystem != null)
            {
                template = templateFileSystem.GetTemplate(context, _templateName);
            }
            if (template == null)
            {
                var source = fileSystem.ReadTemplateFile(context, _templateName);
                template = Template.Parse(source, template.FileSystem);
            }

            var parentBlocks   = FindBlocks(template.Root, null);
            var orphanedBlocks = ((List <Block>)context.Scopes.First()["extends"]) ?? new List <Block>();
            var blockState     = BlockRenderState.Find(context) ?? new BlockRenderState();

            context.Stack(() =>
            {
                context["blockstate"] = blockState;         // Set or copy the block state down to this scope
                context["extends"]    = new List <Block>(); // Holds Blocks that were not found in the parent
                foreach (var block in NodeList.OfType <Block>().Concat(orphanedBlocks))
                {
                    var pb = parentBlocks.Find(b => b.BlockName == block.BlockName);

                    if (pb != null)
                    {
                        if (blockState.Parents.TryGetValue(block, out var parent))
                        {
                            blockState.Parents[pb] = parent;
                        }

                        pb.AddParent(blockState.Parents, pb.GetNodeList(blockState));
                        blockState.NodeLists[pb] = block.GetNodeList(blockState);
                    }
                    else if (IsExtending(template))
                    {
                        ((List <Block>)context.Scopes.First()["extends"]).Add(block);
                    }
                }
                template.Render(result, RenderParameters.FromContext(context, result.FormatProvider));
            });
        }