예제 #1
0
파일: Block.cs 프로젝트: frank-hliva/Deep
        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);
            });
        }
예제 #2
0
파일: Block.cs 프로젝트: mwadams/dotliquid
        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);
            }));
        }
예제 #3
0
파일: Block.cs 프로젝트: mwadams/dotliquid
        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);
            }
        }
예제 #4
0
파일: Block.cs 프로젝트: zyj0021/dotliquid
        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);
            }
        }
예제 #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);
        }
예제 #6
0
파일: Extends.cs 프로젝트: frank-hliva/Deep
        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));
            });
        }