public void RenderPartialWithContainedContent()
        {
            var partial = Chunks(
                new SendLiteralChunk {
                Text = "["
            },
                new RenderSectionChunk(),
                new SendLiteralChunk {
                Text = "]"
            });


            var renderPartial = new RenderPartialChunk {
                FileContext = new FileContext {
                    Contents = partial[0]
                }
            };
            var chunks = Chunks(
                new SendLiteralChunk {
                Text = "("
            },
                renderPartial,
                new SendLiteralChunk {
                Text = ")"
            });

            renderPartial.Body.Add(new SendLiteralChunk {
                Text = "From inside caller"
            });

            _compiler.CompileView(chunks, new[] { chunks[0], partial[0] });
            var contents = ExecuteView();

            Assert.AreEqual("([From inside caller])", contents);
        }
 protected override void Visit(RenderPartialChunk chunk)
 {
     var priorPartial = _currentPartial;
     _currentPartial = chunk;
     Accept(chunk.FileContext.Contents);
     _currentPartial = priorPartial;
 }
Exemple #3
0
 public DetectCodeExpressionVisitor(RenderPartialChunk currentPartial)
 {
     if (currentPartial != null)
     {
         EnterRenderPartial(currentPartial);
     }
 }
Exemple #4
0
 protected override void Visit(RenderPartialChunk chunk)
 {
     References.Add(chunk);
     Accept(chunk.Body);
     foreach (var chunks in chunk.Sections.Values)
         Accept(chunks);
 }
Exemple #5
0
        protected override void Visit(UseImportChunk chunk)
        {
            RenderPartialChunk item = new RenderPartialChunk {
                Name = chunk.Name
            };

            this.References.Add(item);
        }
Exemple #6
0
 protected override void Visit(RenderPartialChunk chunk)
 {
     base.Accept(chunk.Body);
     foreach (IList <Chunk> list in chunk.Sections.Values)
     {
         base.Accept(list);
     }
 }
 protected override void Visit(RenderPartialChunk chunk)
 {
     Accept(chunk.Body);
     foreach (var chunks in chunk.Sections.Values)
     {
         Accept(chunks);
     }
 }
        protected void ExitRenderPartial(RenderPartialChunk expectedTopChunk)
        {
            RenderPartialChunk chunk = this.ExitRenderPartial();

            if (expectedTopChunk != chunk)
            {
                throw new CompilerException(string.Format("Internal compiler error. Expected to be leaving partial {0} but was {1}", expectedTopChunk.FileContext.ViewSourcePath, chunk.FileContext.ViewSourcePath));
            }
        }
 protected override void Visit(RenderPartialChunk chunk)
 {
     if (!this._noncyclic.Contains(chunk.FileContext.ViewSourcePath))
     {
         this._noncyclic.Push(chunk.FileContext.ViewSourcePath);
         base.Accept(chunk.FileContext.Contents);
         this._noncyclic.Pop();
     }
 }
        protected override void Visit(RenderPartialChunk chunk)
        {
            if (_noncyclic.Contains(chunk.FileContext.ViewSourcePath))
            {
                return;
            }

            _noncyclic.Push(chunk.FileContext.ViewSourcePath);
            Accept(chunk.FileContext.Contents);
            _noncyclic.Pop();
        }
 protected void EnterRenderPartial(RenderPartialChunk chunk)
 {
     if (this._renderPartialStack.Any <RenderPartialChunk>(recursed => recursed.FileContext == chunk.FileContext))
     {
         StringBuilder builder = new StringBuilder();
         foreach (RenderPartialChunk chunk2 in this._renderPartialStack.Concat <RenderPartialChunk>(new RenderPartialChunk[] { chunk }))
         {
             builder.Append(chunk2.Position.SourceContext.FileName).Append("(").Append(chunk2.Position.Line).Append(",").Append(chunk2.Position.Line).Append("): rendering partial '").Append(chunk2.Name).AppendLine("'");
         }
         throw new CompilerException(string.Format("Recursive rendering of partial files not possible.\r\n{0}", builder));
     }
     this._renderPartialStack.Push(chunk);
 }
        protected override void Visit(RenderSectionChunk chunk)
        {
            RenderPartialChunk chunk2 = base.ExitRenderPartial();

            if (string.IsNullOrEmpty(chunk.Name))
            {
                base.Accept(chunk2.Body);
            }
            else if (chunk2.Sections.ContainsKey(chunk.Name))
            {
                base.Accept(chunk2.Sections[chunk.Name]);
            }
            else
            {
                base.EnterRenderPartial(chunk2);
                base.Accept(chunk.Default);
                base.ExitRenderPartial(chunk2);
            }
            base.EnterRenderPartial(chunk2);
        }
Exemple #13
0
 protected void EnterRenderPartial(RenderPartialChunk chunk)
 {
     // throw an exception if a partial is entered recursively
     if (_renderPartialStack.Any(recursed => recursed.FileContext == chunk.FileContext))
     {
         var sb = new StringBuilder();
         foreach (var recursed in _renderPartialStack.Concat(new[] { chunk }))
         {
             sb
             .Append(recursed.Position.SourceContext.FileName)
             .Append("(")
             .Append(recursed.Position.Line)
             .Append(",")
             .Append(recursed.Position.Line)
             .Append("): rendering partial '")
             .Append(recursed.Name)
             .AppendLine("'");
         }
         throw new CompilerException(string.Format("Recursive rendering of partial files not possible.\r\n{0}", sb));
     }
     _renderPartialStack.Push(chunk);
 }
        private void VisitRender(SpecialNode node, SpecialNodeInspector inspector)
        {
            var partial = inspector.TakeAttribute("partial");

            if (partial != null)
            {
                var scope = new ScopeChunk {
                    Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk {
                            Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
                        });
                    }

                    var renderPartial = new RenderPartialChunk {
                        Name = partial.Value, Position = Locate(inspector.OriginalNode)
                    };
                    Chunks.Add(renderPartial);

                    using (new Frame(this, renderPartial.Body, renderPartial.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var sectionAttr = inspector.TakeAttribute("section");

                string sectionName = null;
                if (sectionAttr != null)
                {
                    sectionName = sectionAttr.Value;
                }

                var scope = new ScopeChunk {
                    Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk {
                            Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
                        });
                    }
                    var render = new RenderSectionChunk {
                        Name = sectionName
                    };
                    Chunks.Add(render);
                    using (new Frame(this, render.Default))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
        }
Exemple #15
0
 protected override void Visit(RenderPartialChunk chunk)
 {
     EnterRenderPartial(chunk);
     Accept(chunk.FileContext.Contents);
     ExitRenderPartial(chunk);
 }
 public DetectCodeExpressionVisitor(RenderPartialChunk currentPartial)
 {
     _currentPartial = currentPartial;
 }
Exemple #17
0
        private void VisitUse(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var file = inspector.TakeAttribute("file");
            if (file != null)
            {
                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var useFileChunk = new RenderPartialChunk { Name = file.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(useFileChunk);
                    using (new Frame(this, useFileChunk.Body, useFileChunk.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var contentAttr = inspector.TakeAttribute("content");
                var namespaceAttr = inspector.TakeAttribute("namespace");
                var assemblyAttr = inspector.TakeAttribute("assembly");
                var importAttr = inspector.TakeAttribute("import");
                var masterAttr = inspector.TakeAttribute("master");
                var pageBaseTypeAttr = inspector.TakeAttribute("pageBaseType");

                if (contentAttr != null)
                {
                    var useContentChunk = new UseContentChunk { Name = contentAttr.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(useContentChunk);
                    using (new Frame(this, useContentChunk.Default))
                    {
                        Accept(specialNode.Body);
                    }
                }
                else if (namespaceAttr != null || assemblyAttr != null)
                {
                    if (namespaceAttr != null)
                    {
                        var useNamespaceChunk = new UseNamespaceChunk { Namespace = AsCode(namespaceAttr) };
                        AddUnordered(useNamespaceChunk);
                    }

                    if (assemblyAttr != null)
                    {
                        var useAssemblyChunk = new UseAssemblyChunk { Assembly = assemblyAttr.Value };
                        AddUnordered(useAssemblyChunk);
                    }
                }
                else if (importAttr != null)
                {
                    var useImportChunk = new UseImportChunk { Name = importAttr.Value };
                    AddUnordered(useImportChunk);
                }
                else if (masterAttr != null)
                {
                    var useMasterChunk = new UseMasterChunk { Name = masterAttr.Value };
                    AddUnordered(useMasterChunk);
                }
                else if (pageBaseTypeAttr != null)
                {
                    var usePageBaseTypeChunk = new PageBaseTypeChunk { BaseClass = AsCode(pageBaseTypeAttr) };
                    AddUnordered(usePageBaseTypeChunk);
                }
                else
                {
                    throw new CompilerException("Special node use had no understandable attributes");
                }
            }
        }
Exemple #18
0
        private void VisitRender(SpecialNode node, SpecialNodeInspector inspector)
        {
            var partial = inspector.TakeAttribute("partial");

            if (partial != null)
            {
                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var renderPartial = new RenderPartialChunk { Name = partial.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(renderPartial);

                    using (new Frame(this, renderPartial.Body, renderPartial.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var sectionAttr = inspector.TakeAttribute("section");

                string sectionName = null;
                if (sectionAttr != null)
                    sectionName = sectionAttr.Value;

                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var render = new RenderSectionChunk { Name = sectionName };
                    Chunks.Add(render);
                    using (new Frame(this, render.Default))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
        }
 protected override void Visit(RenderPartialChunk chunk)
 {
     EnterRenderPartial(chunk);
     Accept(chunk.FileContext.Contents);
     ExitRenderPartial(chunk);
 }
Exemple #20
0
        protected override void Visit(RenderPartialChunk chunk)
        {
            if (_noncyclic.Contains(chunk.FileContext.ViewSourcePath))
                return;

            _noncyclic.Push(chunk.FileContext.ViewSourcePath);
            Accept(chunk.FileContext.Contents);
            _noncyclic.Pop();
        }
 protected abstract void Visit(RenderPartialChunk chunk);
Exemple #22
0
        private void VisitUse(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode node = inspector.TakeAttribute("file");

            if (node != null)
            {
                ScopeChunk item = new ScopeChunk {
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(item);
                using (new Frame(this, item.Body))
                {
                    foreach (AttributeNode node2 in inspector.Attributes)
                    {
                        LocalVariableChunk chunk2 = new LocalVariableChunk {
                            Name     = node2.Name,
                            Value    = this.AsTextOrientedCode(node2),
                            Position = this.Locate(node2)
                        };
                        this.Chunks.Add(chunk2);
                    }
                    RenderPartialChunk chunk3 = new RenderPartialChunk {
                        Name     = node.Value,
                        Position = this.Locate(inspector.OriginalNode)
                    };
                    this.Chunks.Add(chunk3);
                    using (new Frame(this, chunk3.Body, chunk3.Sections))
                    {
                        base.Accept(inspector.Body);
                    }
                    return;
                }
            }
            AttributeNode node3 = inspector.TakeAttribute("content");
            AttributeNode attr  = inspector.TakeAttribute("namespace");
            AttributeNode node5 = inspector.TakeAttribute("assembly");
            AttributeNode node6 = inspector.TakeAttribute("import");
            AttributeNode node7 = inspector.TakeAttribute("master");
            AttributeNode node8 = inspector.TakeAttribute("pageBaseType");

            if (node3 != null)
            {
                UseContentChunk chunk6 = new UseContentChunk {
                    Name     = node3.Value,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk6);
                using (new Frame(this, chunk6.Default))
                {
                    base.Accept(specialNode.Body);
                    return;
                }
            }
            if ((attr != null) || (node5 != null))
            {
                if (attr != null)
                {
                    UseNamespaceChunk chunk = new UseNamespaceChunk {
                        Namespace = this.AsCode(attr)
                    };
                    this.AddUnordered(chunk);
                }
                if (node5 != null)
                {
                    UseAssemblyChunk chunk10 = new UseAssemblyChunk {
                        Assembly = node5.Value
                    };
                    this.AddUnordered(chunk10);
                }
            }
            else if (node6 != null)
            {
                UseImportChunk chunk12 = new UseImportChunk {
                    Name = node6.Value
                };
                this.AddUnordered(chunk12);
            }
            else if (node7 != null)
            {
                UseMasterChunk chunk14 = new UseMasterChunk {
                    Name = node7.Value
                };
                this.AddUnordered(chunk14);
            }
            else
            {
                if (node8 == null)
                {
                    throw new CompilerException("Special node use had no understandable attributes");
                }
                PageBaseTypeChunk chunk16 = new PageBaseTypeChunk {
                    BaseClass = this.AsCode(node8)
                };
                this.AddUnordered(chunk16);
            }
        }
 public DetectCodeExpressionVisitor(RenderPartialChunk currentPartial)
 {
     if (currentPartial != null)
         EnterRenderPartial(currentPartial);
 }
        private void VisitUse(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var file = inspector.TakeAttribute("file");

            if (file != null)
            {
                var scope = new ScopeChunk {
                    Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk {
                            Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
                        });
                    }

                    var useFileChunk = new RenderPartialChunk {
                        Name = file.Value, Position = Locate(inspector.OriginalNode)
                    };
                    Chunks.Add(useFileChunk);
                    using (new Frame(this, useFileChunk.Body, useFileChunk.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var contentAttr      = inspector.TakeAttribute("content");
                var namespaceAttr    = inspector.TakeAttribute("namespace");
                var assemblyAttr     = inspector.TakeAttribute("assembly");
                var importAttr       = inspector.TakeAttribute("import");
                var masterAttr       = inspector.TakeAttribute("master");
                var pageBaseTypeAttr = inspector.TakeAttribute("pageBaseType");

                if (contentAttr != null)
                {
                    var useContentChunk = new UseContentChunk {
                        Name = contentAttr.Value, Position = Locate(inspector.OriginalNode)
                    };
                    Chunks.Add(useContentChunk);
                    using (new Frame(this, useContentChunk.Default))
                    {
                        Accept(specialNode.Body);
                    }
                }
                else if (namespaceAttr != null || assemblyAttr != null)
                {
                    if (namespaceAttr != null)
                    {
                        var useNamespaceChunk = new UseNamespaceChunk {
                            Namespace = AsCode(namespaceAttr)
                        };
                        AddUnordered(useNamespaceChunk);
                    }
                    if (assemblyAttr != null)
                    {
                        var useAssemblyChunk = new UseAssemblyChunk {
                            Assembly = assemblyAttr.Value
                        };
                        AddUnordered(useAssemblyChunk);
                    }
                }
                else if (importAttr != null)
                {
                    var useImportChunk = new UseImportChunk {
                        Name = importAttr.Value
                    };
                    AddUnordered(useImportChunk);
                }
                else if (masterAttr != null)
                {
                    var useMasterChunk = new UseMasterChunk {
                        Name = masterAttr.Value
                    };
                    AddUnordered(useMasterChunk);
                }
                else if (pageBaseTypeAttr != null)
                {
                    var usePageBaseTypeChunk = new PageBaseTypeChunk {
                        BaseClass = AsCode(pageBaseTypeAttr)
                    };
                    AddUnordered(usePageBaseTypeChunk);
                }
                else
                {
                    throw new CompilerException("Special node use had no understandable attributes");
                }
            }
        }
 protected void EnterRenderPartial(RenderPartialChunk chunk)
 {
     // throw an exception if a partial is entered recursively
     if (_renderPartialStack.Any(recursed => recursed.FileContext == chunk.FileContext))
     {
         var sb = new StringBuilder();
         foreach (var recursed in _renderPartialStack.Concat(new[] { chunk }))
         {
             sb
                 .Append(recursed.Position.SourceContext.FileName)
                 .Append("(")
                 .Append(recursed.Position.Line)
                 .Append(",")
                 .Append(recursed.Position.Line)
                 .Append("): rendering partial '")
                 .Append(recursed.Name)
                 .AppendLine("'");
         }
         throw new CompilerException(string.Format("Recursive rendering of partial files not possible.\r\n{0}", sb));
     }
     _renderPartialStack.Push(chunk);
 }
 protected void ExitRenderPartial(RenderPartialChunk expectedTopChunk)
 {
     var topChunk = ExitRenderPartial();
     if (expectedTopChunk != topChunk)
     {
         throw new CompilerException(string.Format(
                                         "Internal compiler error. Expected to be leaving partial {0} but was {1}",
                                         expectedTopChunk.FileContext.ViewSourcePath,
                                         topChunk.FileContext.ViewSourcePath));
     }
 }
 protected abstract void Visit(RenderPartialChunk chunk);
Exemple #28
0
        private void VisitRender(SpecialNode node, SpecialNodeInspector inspector)
        {
            AttributeNode node2 = inspector.TakeAttribute("partial");

            if (node2 != null)
            {
                ScopeChunk chunk = new ScopeChunk {
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk);
                using (new Frame(this, chunk.Body))
                {
                    foreach (AttributeNode node3 in inspector.Attributes)
                    {
                        LocalVariableChunk chunk2 = new LocalVariableChunk {
                            Name     = node3.Name,
                            Value    = this.AsTextOrientedCode(node3),
                            Position = this.Locate(node3)
                        };
                        this.Chunks.Add(chunk2);
                    }
                    RenderPartialChunk chunk3 = new RenderPartialChunk {
                        Name     = node2.Value,
                        Position = this.Locate(inspector.OriginalNode)
                    };
                    this.Chunks.Add(chunk3);
                    using (new Frame(this, chunk3.Body, chunk3.Sections))
                    {
                        base.Accept(inspector.Body);
                    }
                    return;
                }
            }
            AttributeNode node4 = inspector.TakeAttribute("segment");

            if (base.Context.ParseSectionTagAsSegment && (node4 == null))
            {
                node4 = inspector.TakeAttribute("section");
            }
            string str = null;

            if (node4 != null)
            {
                str = node4.Value;
            }
            ScopeChunk item = new ScopeChunk {
                Position = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                foreach (AttributeNode node5 in inspector.Attributes)
                {
                    LocalVariableChunk chunk7 = new LocalVariableChunk {
                        Name     = node5.Name,
                        Value    = this.AsTextOrientedCode(node5),
                        Position = this.Locate(node5)
                    };
                    this.Chunks.Add(chunk7);
                }
                RenderSectionChunk chunk8 = new RenderSectionChunk {
                    Name = str
                };
                this.Chunks.Add(chunk8);
                using (new Frame(this, chunk8.Default))
                {
                    base.Accept(inspector.Body);
                }
            }
        }