private void VisitViewdata(SpecialNodeInspector inspector)
        {
            var      defaultAttr  = inspector.TakeAttribute("default");
            Snippets defaultValue = null;

            if (defaultAttr != null)
            {
                defaultValue = AsCode(defaultAttr);
            }

            var modelAttr = inspector.TakeAttribute("model");

            if (modelAttr != null)
            {
                var typeInspector = new TypeInspector(AsCode(modelAttr));
                AddUnordered(new ViewDataModelChunk {
                    TModel = typeInspector.Type, TModelAlias = typeInspector.Name
                });
            }

            foreach (var attr in inspector.Attributes)
            {
                var typeInspector = new TypeInspector(AsCode(attr));
                AddUnordered(new ViewDataChunk
                {
                    Type     = typeInspector.Type,
                    Name     = typeInspector.Name ?? attr.Name,
                    Key      = attr.Name,
                    Default  = defaultValue,
                    Position = Locate(attr)
                });
            }
        }
Exemple #2
0
        private void VisitViewdata(SpecialNodeInspector inspector)
        {
            AttributeNode attr     = inspector.TakeAttribute("default");
            Snippets      snippets = null;

            if (attr != null)
            {
                snippets = this.AsTextOrientedCode(attr);
            }
            AttributeNode node2 = inspector.TakeAttribute("model");

            if (node2 != null)
            {
                TypeInspector      inspector2 = new TypeInspector(this.AsCode(node2));
                ViewDataModelChunk chunk      = new ViewDataModelChunk {
                    TModel      = inspector2.Type,
                    TModelAlias = inspector2.Name
                };
                this.AddUnordered(chunk);
            }
            foreach (AttributeNode node3 in inspector.Attributes)
            {
                TypeInspector inspector3 = new TypeInspector(this.AsCode(node3));
                ViewDataChunk chunk2     = new ViewDataChunk {
                    Type     = inspector3.Type,
                    Name     = inspector3.Name ?? node3.Name,
                    Key      = node3.Name,
                    Default  = snippets,
                    Position = this.Locate(node3)
                };
                this.AddUnordered(chunk2);
            }
        }
        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");

            var unlessChunk = new ConditionalChunk {
                Type = ConditionalType.Unless, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode)
            };

            Chunks.Add(unlessChunk);
            using (new Frame(this, unlessChunk.Body))
                Accept(specialNode.Body);
        }
Exemple #4
0
        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode    attr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");
            ConditionalChunk item = new ConditionalChunk {
                Type      = ConditionalType.Unless,
                Condition = this.AsCode(attr),
                Position  = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(specialNode.Body);
            }
        }
        private void VisitElse(SpecialNodeInspector inspector)
        {
            if (!SatisfyElsePrecondition())
            {
                throw new CompilerException("An 'else' may only follow an 'if' or 'elseif'.");
            }

            var ifAttr = inspector.TakeAttribute("if");

            if (ifAttr == null)
            {
                var elseChunk = new ConditionalChunk {
                    Type = ConditionalType.Else, Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(elseChunk);
                using (new Frame(this, elseChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                var elseIfChunk = new ConditionalChunk {
                    Type = ConditionalType.ElseIf, Condition = AsCode(ifAttr), Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(elseIfChunk);
                using (new Frame(this, elseIfChunk.Body))
                    Accept(inspector.Body);
            }
        }
Exemple #6
0
        private void VisitElse(SpecialNodeInspector inspector)
        {
            if (!this.SatisfyElsePrecondition())
            {
                throw new CompilerException("An 'else' may only follow an 'if' or 'elseif'.");
            }
            AttributeNode attr = inspector.TakeAttribute("if");

            if (attr == null)
            {
                ConditionalChunk chunk = new ConditionalChunk {
                    Type     = ConditionalType.Else,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk);
                using (new Frame(this, chunk.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            ConditionalChunk item = new ConditionalChunk {
                Type      = ConditionalType.ElseIf,
                Condition = this.AsCode(attr),
                Position  = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(inspector.Body);
            }
        }
Exemple #7
0
        private void VisitDefault(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            Frame frame = null;

            if (!specialNode.Element.IsEmptyElement)
            {
                ScopeChunk item = new ScopeChunk {
                    Position = this.Locate(specialNode.Element)
                };
                this.Chunks.Add(item);
                frame = new Frame(this, item.Body);
            }
            AttributeNode attr     = inspector.TakeAttribute("type");
            Snippets      snippets = (attr != null) ? this.AsCode(attr) : "var";

            foreach (AttributeNode node2 in inspector.Attributes)
            {
                DefaultVariableChunk chunk3 = new DefaultVariableChunk {
                    Type     = snippets,
                    Name     = node2.Name,
                    Value    = this.AsTextOrientedCode(node2),
                    Position = this.Locate(node2)
                };
                this.Chunks.Add(chunk3);
            }
            base.Accept(specialNode.Body);
            if (frame != null)
            {
                frame.Dispose();
            }
        }
        private void VisitVar(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            Frame frame = null;

            if (!specialNode.Element.IsEmptyElement)
            {
                var scope = new ScopeChunk {
                    Position = Locate(specialNode.Element)
                };
                Chunks.Add(scope);
                frame = new Frame(this, scope.Body);
            }

            var typeAttr = inspector.TakeAttribute("type");
            var type     = typeAttr != null?AsCode(typeAttr) : (Snippets)"var";

            foreach (var attr in inspector.Attributes)
            {
                Chunks.Add(new LocalVariableChunk {
                    Type = type, Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
                });
            }

            Accept(specialNode.Body);

            if (frame != null)
            {
                frame.Dispose();
            }
        }
        protected void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!FirstChildBeginsWithNewline(specialNode))
            {
                var eachAttr      = inspector.TakeAttribute("each");
                var eachInspector = new ForEachInspector(AsCode(eachAttr));

                var code = eachInspector.Recognized ? eachInspector.VariableName + "IsFirst" : "Once(\"" + Guid.NewGuid() + "\")";

                var newNode = new SpecialNode(new ElementNode("if", new[] { new AttributeNode("condition", code) }, false))
                {
                    Body = new [] {
                        new TextNode(specialNode.Element.PreceedingWhitespace),
                    },
                };

                var newBody = new List <Node>();
                newBody.Add(newNode);
                if (specialNode.Body != null)
                {
                    newBody.AddRange(specialNode.Body);
                }

                specialNode.Body = newBody;
            }

            specialNode.Element.PreceedingWhitespace = string.Empty;
        }
        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");

            var onceAttr = inspector.TakeAttribute("once");

            if (conditionAttr == null && onceAttr == null)
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }

            Frame ifFrame = null;

            if (conditionAttr != null)
            {
                var ifChunk = new ConditionalChunk {
                    Type = ConditionalType.If, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(ifChunk);
                ifFrame = new Frame(this, ifChunk.Body);
            }

            Frame onceFrame = null;

            if (onceAttr != null)
            {
                var onceChunk = new ConditionalChunk {
                    Type = ConditionalType.Once, Condition = onceAttr.AsCodeInverted(), Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(onceChunk);
                onceFrame = new Frame(this, onceChunk.Body);
            }

            Accept(specialNode.Body);

            if (onceFrame != null)
            {
                onceFrame.Dispose();
            }

            if (ifFrame != null)
            {
                ifFrame.Dispose();
            }
        }
Exemple #11
0
        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode attr  = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");
            AttributeNode node2 = inspector.TakeAttribute("once");

            if ((attr == null) && (node2 == null))
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }
            Frame frame = null;

            if (attr != null)
            {
                ConditionalChunk item = new ConditionalChunk {
                    Type      = ConditionalType.If,
                    Condition = this.AsCode(attr),
                    Position  = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(item);
                frame = new Frame(this, item.Body);
            }
            Frame frame2 = null;

            if (node2 != null)
            {
                ConditionalChunk chunk3 = new ConditionalChunk {
                    Type      = ConditionalType.Once,
                    Condition = node2.AsCodeInverted(),
                    Position  = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk3);
                frame2 = new Frame(this, chunk3.Body);
            }
            base.Accept(specialNode.Body);
            if (frame2 != null)
            {
                frame2.Dispose();
            }
            if (frame != null)
            {
                frame.Dispose();
            }
        }
        private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var keyAttr     = inspector.TakeAttribute("key");
            var expiresAttr = inspector.TakeAttribute("expires");
            var signalAttr  = inspector.TakeAttribute("signal");

            var chunk = new CacheChunk {
                Position = Locate(specialNode.Element)
            };

            if (keyAttr != null)
            {
                chunk.Key = AsCode(keyAttr);
            }
            else
            {
                chunk.Key = "\"\"";
            }

            if (expiresAttr != null)
            {
                chunk.Expires = AsCode(expiresAttr);
            }
            else
            {
                chunk.Expires = "";
            }

            if (signalAttr != null)
            {
                chunk.Signal = AsCode(signalAttr);
            }
            else
            {
                chunk.Signal = "";
            }

            Chunks.Add(chunk);
            using (new Frame(this, chunk.Body))
                Accept(inspector.Body);
        }
Exemple #13
0
        private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode attr  = inspector.TakeAttribute("key");
            AttributeNode node2 = inspector.TakeAttribute("expires");
            AttributeNode node3 = inspector.TakeAttribute("signal");
            CacheChunk    item  = new CacheChunk {
                Position = this.Locate(specialNode.Element)
            };

            if (attr != null)
            {
                item.Key = this.AsCode(attr);
            }
            else
            {
                item.Key = "\"\"";
            }
            if (node2 != null)
            {
                item.Expires = this.AsCode(node2);
            }
            else
            {
                item.Expires = "";
            }
            if (node3 != null)
            {
                item.Signal = this.AsCode(node3);
            }
            else
            {
                item.Signal = "";
            }
            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(inspector.Body);
            }
        }
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            var name  = inspector.TakeAttribute("name");
            var macro = new MacroChunk {
                Name = name.Value, Position = Locate(inspector.OriginalNode)
            };

            foreach (var attr in inspector.Attributes)
            {
                macro.Parameters.Add(new MacroParameter {
                    Name = attr.Name, Type = AsCode(attr)
                });
            }
            AddUnordered(macro);
            using (new Frame(this, macro.Body))
            {
                Accept(inspector.Body);
            }
        }
        private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var eachAttr = inspector.TakeAttribute("each");

            var forEachChunk = new ForEachChunk {
                Code = AsCode(eachAttr), Position = Locate(specialNode.Element)
            };

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

                Accept(specialNode.Body);
            }
        }
Exemple #16
0
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            AttributeNode node  = inspector.TakeAttribute("name");
            MacroChunk    chunk = new MacroChunk {
                Name     = node.Value,
                Position = this.Locate(inspector.OriginalNode)
            };

            foreach (AttributeNode node2 in inspector.Attributes)
            {
                MacroParameter item = new MacroParameter {
                    Name = node2.Name,
                    Type = this.AsCode(node2)
                };
                chunk.Parameters.Add(item);
            }
            this.AddUnordered(chunk);
            using (new Frame(this, chunk.Body))
            {
                base.Accept(inspector.Body);
            }
        }
Exemple #17
0
 protected void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     if (!this.FirstChildBeginsWithNewline(specialNode))
     {
         AttributeNode    attr       = inspector.TakeAttribute("each");
         ForEachInspector inspector2 = new ForEachInspector(this.AsCode(attr));
         string           str        = inspector2.Recognized ? (inspector2.VariableName + "IsFirst") : ("Once(\"" + Guid.NewGuid() + "\")");
         SpecialNode      node2      = new SpecialNode(new ElementNode("if", new AttributeNode[] { new AttributeNode("condition", str) }, false))
         {
             Body = new TextNode[] { new TextNode(specialNode.Element.PreceedingWhitespace) }
         };
         List <Node> list = new List <Node> {
             node2
         };
         if (specialNode.Body != null)
         {
             list.AddRange(specialNode.Body);
         }
         specialNode.Body = list;
     }
     specialNode.Element.PreceedingWhitespace = string.Empty;
 }
        private void VisitSection(SpecialNode node, SpecialNodeInspector inspector)
        {
            if (SectionChunks == null)
            {
                throw new CompilerException("Section cannot be used at this location", Locate(node.Element));
            }

            var name = inspector.TakeAttribute("name");

            if (name == null)
            {
                throw new CompilerException("Section element must have a name attribute", Locate(node.Element));
            }

            IList <Chunk> sectionChunks;

            if (!SectionChunks.TryGetValue(name.Value, out sectionChunks))
            {
                sectionChunks = new List <Chunk>();
                SectionChunks.Add(name.Value, sectionChunks);
            }

            var scope = new ScopeChunk {
                Position = Locate(inspector.OriginalNode)
            };

            sectionChunks.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)
                    });
                }

                Accept(inspector.Body);
            }
        }
Exemple #19
0
        private void VisitSection(SpecialNode node, SpecialNodeInspector inspector)
        {
            IList <Chunk> list;

            if (this.SectionChunks == null)
            {
                throw new CompilerException("Section cannot be used at this location", this.Locate(node.Element));
            }
            AttributeNode node2 = inspector.TakeAttribute("name");

            if (node2 == null)
            {
                throw new CompilerException("Section element must have a name attribute", this.Locate(node.Element));
            }
            if (!this.SectionChunks.TryGetValue(node2.Value, out list))
            {
                list = new List <Chunk>();
                this.SectionChunks.Add(node2.Value, list);
            }
            ScopeChunk item = new ScopeChunk {
                Position = this.Locate(inspector.OriginalNode)
            };

            list.Add(item);
            using (new Frame(this, item.Body))
            {
                foreach (AttributeNode node3 in inspector.Attributes)
                {
                    LocalVariableChunk chunk2 = new LocalVariableChunk {
                        Name     = node3.Name,
                        Value    = this.AsCode(node3),
                        Position = this.Locate(node3)
                    };
                    this.Chunks.Add(chunk2);
                }
                base.Accept(inspector.Body);
            }
        }
Exemple #20
0
        private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            AttributeNode attr = inspector.TakeAttribute("each");
            ForEachChunk  item = new ForEachChunk {
                Code     = this.AsCode(attr),
                Position = this.Locate(specialNode.Element)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                foreach (AttributeNode node2 in inspector.Attributes)
                {
                    AssignVariableChunk chunk2 = new AssignVariableChunk {
                        Name     = node2.Name,
                        Value    = this.AsCode(node2),
                        Position = this.Locate(node2)
                    };
                    this.Chunks.Add(chunk2);
                }
                base.Accept(specialNode.Body);
            }
        }
Exemple #21
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);
                    }
                }
            }
        }
Exemple #22
0
        private void VisitMacro(SpecialNodeInspector inspector)
        {
            var name = inspector.TakeAttribute("name");
            var macro = new MacroChunk { Name = name.Value, Position = Locate(inspector.OriginalNode) };
            foreach (var attr in inspector.Attributes)
            {
                macro.Parameters.Add(new MacroParameter { Name = attr.Name, Type = AsCode(attr) });
            }

            AddUnordered(macro);
            using (new Frame(this, macro.Body))
            {
                Accept(inspector.Body);
            }
        }
Exemple #23
0
        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");

            var onceAttr = inspector.TakeAttribute("once");

            if (conditionAttr == null && onceAttr == null)
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }

            Frame ifFrame = null;
            if (conditionAttr != null)
            {
                var ifChunk = new ConditionalChunk { Type = ConditionalType.If, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
                Chunks.Add(ifChunk);
                ifFrame = new Frame(this, ifChunk.Body);
            }

            Frame onceFrame = null;
            if (onceAttr != null)
            {
                var onceChunk = new ConditionalChunk { Type = ConditionalType.Once, Condition = onceAttr.AsCodeInverted(), Position = Locate(inspector.OriginalNode) };
                Chunks.Add(onceChunk);
                onceFrame = new Frame(this, onceChunk.Body);
            }

            Accept(specialNode.Body);

            if (onceFrame != null)
                onceFrame.Dispose();

            if (ifFrame != null)
                ifFrame.Dispose();
        }
Exemple #24
0
        private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var eachAttr = inspector.TakeAttribute("each");

            var forEachChunk = new ForEachChunk { Code = AsCode(eachAttr), Position = Locate(specialNode.Element) };
            Chunks.Add(forEachChunk);
            using (new Frame(this, forEachChunk.Body))
            {
                foreach (var attr in inspector.Attributes)
                {
                    Chunks.Add(new AssignVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                }

                Accept(specialNode.Body);
            }
        }
Exemple #25
0
        private void VisitElseIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!SatisfyElsePrecondition())
                throw new CompilerException("An 'elseif' may only follow an 'if' or 'elseif'.");

            var conditionAttr = inspector.TakeAttribute("condition");
            var elseIfChunk = new ConditionalChunk { Type = ConditionalType.ElseIf, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
            Chunks.Add(elseIfChunk);
            using (new Frame(this, elseIfChunk.Body))
                Accept(specialNode.Body);
        }
        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 #27
0
        private void VisitVar(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            Frame frame = null;
            if (!specialNode.Element.IsEmptyElement)
            {
                var scope = new ScopeChunk { Position = Locate(specialNode.Element) };
                Chunks.Add(scope);
                frame = new Frame(this, scope.Body);
            }

            var typeAttr = inspector.TakeAttribute("type");
            var type = typeAttr != null ? AsCode(typeAttr) : (Snippets)"var";

            foreach (var attr in inspector.Attributes)
            {
                Chunks.Add(new LocalVariableChunk { Type = type, Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
            }

            Accept(specialNode.Body);

            if (frame != null)
                frame.Dispose();
        }
Exemple #28
0
        private void VisitContent(SpecialNodeInspector inspector)
        {
            AttributeNode node  = inspector.TakeAttribute("name");
            AttributeNode node2 = inspector.TakeAttribute("var");
            AttributeNode node3 = inspector.TakeAttribute("def");
            AttributeNode attr  = inspector.TakeAttribute("set");

            if (node != null)
            {
                ContentChunk item = new ContentChunk {
                    Name     = node.Value,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(item);
                using (new Frame(this, item.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            if ((node2 != null) || (node3 != null))
            {
                LocalVariableChunk chunk3 = new LocalVariableChunk {
                    Name = this.AsCode(node2 ?? node3),
                    Type = "string"
                };
                this.Chunks.Add(chunk3);
                ContentSetChunk chunk4 = new ContentSetChunk {
                    Variable = chunk3.Name,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk4);
                using (new Frame(this, chunk4.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            if (attr != null)
            {
                AttributeNode   node5  = inspector.TakeAttribute("add");
                ContentSetChunk chunk7 = new ContentSetChunk {
                    Variable = this.AsCode(attr),
                    Position = this.Locate(inspector.OriginalNode)
                };
                if (node5 != null)
                {
                    if (node5.Value != "before")
                    {
                        if (node5.Value != "after")
                        {
                            if (node5.Value != "replace")
                            {
                                throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                            }
                            chunk7.AddType = ContentAddType.Replace;
                        }
                        else
                        {
                            chunk7.AddType = ContentAddType.AppendAfter;
                        }
                    }
                    else
                    {
                        chunk7.AddType = ContentAddType.InsertBefore;
                    }
                }
                this.Chunks.Add(chunk7);
                using (new Frame(this, chunk7.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            throw new CompilerException("content element must have name, var, def, or set attribute");
        }
Exemple #29
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);
                }
            }
        }
Exemple #30
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);
            }
        }
Exemple #31
0
        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");

            var unlessChunk = new ConditionalChunk { Type = ConditionalType.Unless, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
            Chunks.Add(unlessChunk);
            using (new Frame(this, unlessChunk.Body))
                Accept(specialNode.Body);
        }
        private void VisitContent(SpecialNodeInspector inspector)
        {
            var nameAttr = inspector.TakeAttribute("name");
            var varAttr  = inspector.TakeAttribute("var");
            var defAttr  = inspector.TakeAttribute("def");
            var setAttr  = inspector.TakeAttribute("set");

            if (nameAttr != null)
            {
                var contentChunk = new ContentChunk {
                    Name = nameAttr.Value, Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(contentChunk);
                using (new Frame(this, contentChunk.Body))
                    Accept(inspector.Body);
            }
            else if (varAttr != null || defAttr != null)
            {
                var variableChunk = new LocalVariableChunk {
                    Name = AsCode(varAttr ?? defAttr), Type = "string"
                };
                Chunks.Add(variableChunk);

                var contentSetChunk = new ContentSetChunk {
                    Variable = variableChunk.Name, Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else if (setAttr != null)
            {
                var addAttr = inspector.TakeAttribute("add");

                var contentSetChunk = new ContentSetChunk {
                    Variable = AsCode(setAttr), Position = Locate(inspector.OriginalNode)
                };

                if (addAttr != null)
                {
                    if (addAttr.Value == "before")
                    {
                        contentSetChunk.AddType = ContentAddType.InsertBefore;
                    }
                    else if (addAttr.Value == "after")
                    {
                        contentSetChunk.AddType = ContentAddType.AppendAfter;
                    }
                    else if (addAttr.Value == "replace")
                    {
                        contentSetChunk.AddType = ContentAddType.Replace;
                    }
                    else
                    {
                        throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                    }
                }

                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                throw new CompilerException("content element must have name, var, def, or set attribute");
            }
        }
Exemple #33
0
        private void VisitSection(SpecialNode node, SpecialNodeInspector inspector)
        {
            if (SectionChunks == null)
                throw new CompilerException("Section cannot be used at this location", Locate(node.Element));

            var name = inspector.TakeAttribute("name");
            if (name == null)
                throw new CompilerException("Section element must have a name attribute", Locate(node.Element));

            IList<Chunk> sectionChunks;
            if (!SectionChunks.TryGetValue(name.Value, out sectionChunks))
            {
                sectionChunks = new List<Chunk>();
                SectionChunks.Add(name.Value, sectionChunks);
            }

            var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
            sectionChunks.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) });
                }

                Accept(inspector.Body);
            }
        }
Exemple #34
0
        private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var keyAttr = inspector.TakeAttribute("key");
            var expiresAttr = inspector.TakeAttribute("expires");
            var signalAttr = inspector.TakeAttribute("signal");

            var chunk = new CacheChunk { Position = Locate(specialNode.Element) };

            if (keyAttr != null)
                chunk.Key = AsCode(keyAttr);
            else
                chunk.Key = "\"\"";

            if (expiresAttr != null)
                chunk.Expires = AsCode(expiresAttr);
            else
                chunk.Expires = "";

            if (signalAttr != null)
                chunk.Signal = AsCode(signalAttr);
            else
                chunk.Signal = "";

            Chunks.Add(chunk);
            using (new Frame(this, chunk.Body))
                Accept(inspector.Body);
        }
Exemple #35
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 #36
0
        private void VisitContent(SpecialNodeInspector inspector)
        {
            var nameAttr = inspector.TakeAttribute("name");
            var varAttr = inspector.TakeAttribute("var");
            var defAttr = inspector.TakeAttribute("def");
            var setAttr = inspector.TakeAttribute("set");

            if (nameAttr != null)
            {
                var contentChunk = new ContentChunk { Name = nameAttr.Value, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentChunk);
                using (new Frame(this, contentChunk.Body))
                    Accept(inspector.Body);
            }
            else if (varAttr != null || defAttr != null)
            {
                var variableChunk = new LocalVariableChunk { Name = AsCode(varAttr ?? defAttr), Type = "string" };
                Chunks.Add(variableChunk);

                var contentSetChunk = new ContentSetChunk { Variable = variableChunk.Name, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else if (setAttr != null)
            {
                var addAttr = inspector.TakeAttribute("add");

                var contentSetChunk = new ContentSetChunk { Variable = AsCode(setAttr), Position = Locate(inspector.OriginalNode) };

                if (addAttr != null)
                {
                    if (addAttr.Value == "before")
                        contentSetChunk.AddType = ContentAddType.InsertBefore;
                    else if (addAttr.Value == "after")
                        contentSetChunk.AddType = ContentAddType.AppendAfter;
                    else if (addAttr.Value == "replace")
                        contentSetChunk.AddType = ContentAddType.Replace;
                    else
                        throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                }

                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                throw new CompilerException("content element must have name, var, def, or set attribute");
            }
        }
Exemple #37
0
        private void VisitViewdata(SpecialNodeInspector inspector)
        {
            var defaultAttr = inspector.TakeAttribute("default");
            Snippets defaultValue = null;
            if (defaultAttr != null)
                defaultValue = AsCode(defaultAttr);

            var modelAttr = inspector.TakeAttribute("model");
            if (modelAttr != null)
            {
                var typeInspector = new TypeInspector(AsCode(modelAttr));
                AddUnordered(new ViewDataModelChunk { TModel = typeInspector.Type, TModelAlias = typeInspector.Name });
            }

            foreach (var attr in inspector.Attributes)
            {
                var typeInspector = new TypeInspector(AsCode(attr));
                AddUnordered(new ViewDataChunk
                                 {
                                     Type = typeInspector.Type,
                                     Name = typeInspector.Name ?? attr.Name,
                                     Key = attr.Name,
                                     Default = defaultValue,
                                     Position = Locate(attr)
                                 });
            }
        }
        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);
                    }
                }
            }
        }