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

            context.Stack(() =>
            {
                context["block"] = new BlockDrop(this, result);
                RenderAll(GetNodeList(blockState), context, result);
            });
        }
Esempio n. 2
0
        public override Task RenderAsync(Context context, TextWriter result)
        {
            BlockRenderState blockState = BlockRenderState.Find(context);

            return(context.Stack(() =>
            {
                context["block"] = new BlockDrop(this, result);
                return RenderAllAsync(GetNodeList(blockState), context, result);
            }));
        }
Esempio n. 3
0
        public async Task CallSuperAsync(Context context, TextWriter result)
        {
            BlockRenderState blockState = BlockRenderState.Find(context);

            if (blockState != null &&
                blockState.Parents.TryGetValue(this, out Block parent) &&
                parent != null)
            {
                await parent.RenderAsync(context, result).ConfigureAwait(false);
            }
        }
Esempio n. 4
0
        public void CallSuper(Context context, TextWriter result)
        {
            BlockRenderState blockState = BlockRenderState.Find(context);

            if (blockState != null &&
                blockState.Parents.TryGetValue(this, out Block parent) &&
                parent != null)
            {
                parent.Render(context, result);
            }
        }
Esempio n. 5
0
        public async override Task RenderAsync(Context context, TextWriter result)
        {
            // Get the template or template content and then either copy it (since it will be modified) or parse it
            IFileSystem fileSystem = context.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            Template template = null;
            if (fileSystem is ITemplateFileSystem templateFileSystem)
            {
                template = await templateFileSystem.GetTemplateAsync(context, this.templateName).ConfigureAwait(false);
            }

            if (template == null)
            {
                string source = await fileSystem.ReadTemplateFileAsync(context, this.templateName).ConfigureAwait(false);
                template = Template.Parse(source);
            }

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

            await 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 (Block block in this.NodeList.OfType<Block>().Concat(orphanedBlocks))
                {
                    Block pb = parentBlocks.Find(b => b.BlockName == block.BlockName);

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

                        pb.AddParent(blockState.Parents, pb.GetNodeList(blockState));
                        blockState.NodeLists[pb] = block.GetNodeList(blockState);
                    }
                    else if (this.IsExtending(template))
                    {
                        ((List<Block>)context.Scopes[0]["extends"]).Add(block);
                    }
                }

                return template.RenderAsync(result, RenderParameters.FromContext(context, result.FormatProvider));
            }).ConfigureAwait(false);
        }
Esempio n. 6
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
            IFileSystem fileSystem = context.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            object      file       = fileSystem.ReadTemplateFile(context, _templateName);
            Template    template   = file as Template;

            template = template ?? Template.Parse(file == null ? null : file.ToString());

            List <Block>     parentBlocks   = FindBlocks(template.Root, null);
            List <Block>     orphanedBlocks = ((List <Block>)context.Scopes[0]["extends"]) ?? new List <Block>();
            BlockRenderState 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 (Block block in NodeList.OfType <Block>().Concat(orphanedBlocks))
                {
                    Block pb = parentBlocks.Find(b => b.BlockName == block.BlockName);

                    if (pb != null)
                    {
                        Block parent;
                        if (blockState.Parents.TryGetValue(block, out 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));
            });
        }