Beispiel #1
0
        public override void Render(Context context, TextWriter result)
        {
            var blockState = BlockRenderState.Find(context);

            context.Stack(() =>
            {
                context["block"] = new BlockDrop(this, result);
                RenderAll(GetNodeList(blockState), context, result);
            });
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
            }

            var parentBlocks   = FindBlocks(template.Root, null);
            var orphanedBlocks = ((List <Block>)context.Scopes[0]["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[0]["extends"]).Add(block);
                    }
                }
                template.Render(result, RenderParameters.FromContext(context, result.FormatProvider));
            });
        }