Пример #1
0
        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;
        }
Пример #2
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)
                });
            }
        }
Пример #3
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();
            }
        }
Пример #4
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);
            }
        }
Пример #5
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();
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
0
 private void VisitSet(SpecialNodeInspector inspector)
 {
     foreach (var attr in inspector.Attributes)
     {
         Chunks.Add(new AssignVariableChunk {
             Name = attr.Name, Value = AsCode(attr), Position = Locate(attr)
         });
     }
 }
Пример #9
0
        private void VisitMarkdown(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            MarkdownChunk item = new MarkdownChunk();

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(inspector.Body);
            }
        }
Пример #10
0
        private void VisitMarkdown(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var markdownChunk = new MarkdownChunk();

            Chunks.Add(markdownChunk);
            using (new Frame(this, markdownChunk.Body))
            {
                Accept(inspector.Body);
            }
        }
Пример #11
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);
        }
Пример #12
0
 private void VisitSet(SpecialNodeInspector inspector)
 {
     foreach (AttributeNode node in inspector.Attributes)
     {
         AssignVariableChunk item = new AssignVariableChunk {
             Name     = node.Name,
             Value    = this.AsTextOrientedCode(node),
             Position = this.Locate(node)
         };
         this.Chunks.Add(item);
     }
 }
Пример #13
0
 protected void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     if (!this.FirstChildBeginsWithNewline(specialNode))
     {
         List <Node> list = new List <Node> {
             new TextNode(specialNode.Element.PreceedingWhitespace)
         };
         if (specialNode.Body != null)
         {
             list.AddRange(specialNode.Body);
         }
         specialNode.Body = list;
     }
     specialNode.Element.PreceedingWhitespace = string.Empty;
 }
Пример #14
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);
            }
        }
Пример #15
0
        protected void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!FirstChildBeginsWithNewline(specialNode))
            {
                var newBody = new List <Node>();
                newBody.Add(new TextNode(specialNode.Element.PreceedingWhitespace));
                if (specialNode.Body != null)
                {
                    newBody.AddRange(specialNode.Body);
                }

                specialNode.Body = newBody;
            }

            specialNode.Element.PreceedingWhitespace = string.Empty;
        }
Пример #16
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();
            }
        }
Пример #17
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();
            }
        }
Пример #18
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);
            }
        }
Пример #19
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);
        }
Пример #20
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);
            }
        }
Пример #21
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);
            }
        }
Пример #22
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);
            }
        }
Пример #23
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;
 }
Пример #24
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);
            }
        }
Пример #25
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);
            }
        }
Пример #26
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);
            }
        }
Пример #27
0
        private void VisitMarkdown(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var markdownChunk = new MarkdownChunk();

            Chunks.Add(markdownChunk);
            using (new Frame(this, markdownChunk.Body))
            {
                Accept(inspector.Body);
            }
        }
Пример #28
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);
            }
        }
Пример #29
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();
        }
Пример #30
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);
            }
        }
Пример #31
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);
        }
Пример #32
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");
            }
        }
Пример #33
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);
        }
Пример #34
0
 private void VisitSet(SpecialNodeInspector inspector)
 {
     foreach (var attr in inspector.Attributes)
     {
         Chunks.Add(new AssignVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
     }
 }
Пример #35
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);
        }
Пример #36
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);
                    }
                }
            }
        }
Пример #37
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();
        }
Пример #38
0
 private void VisitIgnore(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     Accept(specialNode.Body);
 }
Пример #39
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");
            }
        }
Пример #40
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);
            }
        }
Пример #41
0
 private void VisitIgnore(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     Accept(specialNode.Body);
 }
Пример #42
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");
                }
            }
        }
Пример #43
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");
                }
            }
        }
Пример #44
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)
                                 });
            }
        }
Пример #45
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);
                    }
                }
            }
        }