Пример #1
0
 public UrlAttributeVisitor(VisitorContext context)
     : base(context)
 {
     _specs = new[]
     {
         new ElementSpecs("a", "href"),
         new ElementSpecs("applet", "codebase"),
         new ElementSpecs("area", "href"),
         new ElementSpecs("base", "href"),
         new ElementSpecs("blockquote", "cite"),
         new ElementSpecs("body", "background"),
         new ElementSpecs("del", "cite"),
         new ElementSpecs("form", "action"),
         new ElementSpecs("frame", "longdesc", "src"),
         new ElementSpecs("head", "profile"),
         new ElementSpecs("iframe", "longdesc", "src"),
         new ElementSpecs("img", "longdesc", "src", "usemap"),
         new ElementSpecs("input", "src", "usemap"),
         new ElementSpecs("ins", "cite"),
         new ElementSpecs("link", "href"),
         new ElementSpecs("object", "classid", "codebase", "data", "usemap"),
         new ElementSpecs("script", "src"),
         new ElementSpecs("q", "cite")
     };
 }
Пример #2
0
        public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
        {
            if (node.Name == "unittest")
                return new TestExtension();

            return null;
        }
Пример #3
0
        public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
        {
            if(_serviceProvider==null)
            {
              return null;
            }
            var componentFactory = (IViewComponentFactory)_serviceProvider.GetService(typeof(IViewComponentFactory));
            if (componentFactory == null || componentFactory.Registry == null)
                return null;

            ViewComponentInfo viewComponentInfo;
            lock (_cachedViewComponent)
            {
                if (!_cachedViewComponent.TryGetValue(node.Name, out viewComponentInfo))
                {
                    if (componentFactory.Registry.HasViewComponent(node.Name))
                    {
                        viewComponentInfo = new ViewComponentInfo(componentFactory.Create(node.Name));
                        _cachedViewComponent.Add(node.Name, viewComponentInfo);
                    }
                    else
                    {
                        _cachedViewComponent.Add(node.Name, null);
                    }
                }
            }

            if (viewComponentInfo != null)
            {
                return new ViewComponentExtension(node, viewComponentInfo);
            }

            return null;
        }
Пример #4
0
 public UrlAttributeVisitor(VisitorContext context) : base(context)
 {
     this._specs = new ElementSpecs[] {
         new ElementSpecs("a", new string[] { "href" }), new ElementSpecs("applet", new string[] { "codebase" }), new ElementSpecs("area", new string[] { "href" }), new ElementSpecs("base", new string[] { "href" }), new ElementSpecs("blockquote", new string[] { "cite" }), new ElementSpecs("body", new string[] { "background" }), new ElementSpecs("del", new string[] { "cite" }), new ElementSpecs("form", new string[] { "action" }), new ElementSpecs("frame", new string[] { "longdesc", "src" }), new ElementSpecs("head", new string[] { "profile" }), new ElementSpecs("iframe", new string[] { "longdesc", "src" }), new ElementSpecs("img", new string[] { "longdesc", "src", "usemap" }), new ElementSpecs("input", new string[] { "src", "usemap" }), new ElementSpecs("ins", new string[] { "cite" }), new ElementSpecs("link", new string[] { "href" }), new ElementSpecs("object", new string[] { "classid", "codebase", "data", "usemap" }),
         new ElementSpecs("script", new string[] { "src" }), new ElementSpecs("q", new string[] { "cite" })
     };
 }
Пример #5
0
        public override IList<Chunk> GetChunks(VisitorContext context, string path)
        {
            context.SyntaxProvider = this;
            context.ViewPath = path;

            var sourceContext = CreateSourceContext(context.ViewPath, context.ViewFolder);
            var position = new Position(sourceContext);

            var result = _grammar.Nodes(position);
            if (result.Rest.PotentialLength() != 0)
            {
                ThrowParseException(context.ViewPath, position, result.Rest);
            }

            context.Paint = result.Rest.GetPaint();

            var nodes = result.Value;
            foreach (var visitor in BuildNodeVisitors(context))
            {
                visitor.Accept(nodes);
                nodes = visitor.Nodes;
            }

            var chunkBuilder = new ChunkBuilderVisitor(context);
            chunkBuilder.Accept(nodes);
            return chunkBuilder.Chunks;
        }
Пример #6
0
        public ChunkBuilderVisitor(VisitorContext context)
            : base(context)
        {
            _nodePaint = Context.Paint.OfType<Paint<Node>>().ToDictionary(paint => paint.Value);

            Chunks = new List<Chunk>();
            _specialNodeMap = new Dictionary<string, Action<SpecialNode, SpecialNodeInspector>>
                                  {
                                      { "var", VisitVar },
                                      { "def", VisitVar },
                                      { "default", VisitDefault },
                                      { "global", (n, i) => VisitGlobal(n) },
                                      { "viewdata", (n, i) => VisitViewdata(i) },
                                      { "set", (n, i) => VisitSet(i) },
                                      { "for", VisitFor },
                                      { "test", VisitIf },
                                      { "if", VisitIf },
                                      { "else", (n, i) => VisitElse(i) },
                                      { "elseif", VisitElseIf },
                                      { "content", (n, i) => VisitContent(i) },
                                      { "use", VisitUse },
                                      { "macro", (n, i) => VisitMacro(i) },
                                      { "render", VisitRender },
                                      { "section", VisitSection },
                                      { "cache", VisitCache },
                                      { "markdown", VisitMarkdown }
                                  };
        }
Пример #7
0
        public ChunkBuilderVisitor(VisitorContext context)
            : base(context)
        {
            _nodePaint = Context.Paint.OfType <Paint <Node> >().ToDictionary(paint => paint.Value);

            Chunks          = new List <Chunk>();
            _specialNodeMap = new Dictionary <string, Action <SpecialNode, SpecialNodeInspector> >
            {
                { "var", VisitVar },
                { "def", VisitVar },
                { "default", VisitDefault },
                { "global", (n, i) => VisitGlobal(n) },
                { "viewdata", (n, i) => VisitViewdata(i) },
                { "set", (n, i) => VisitSet(i) },
                { "for", VisitFor },
                { "test", VisitIf },
                { "if", VisitIf },
                { "else", (n, i) => VisitElse(i) },
                { "elseif", VisitElseIf },
                { "content", (n, i) => VisitContent(i) },
                { "use", VisitUse },
                { "macro", (n, i) => VisitMacro(i) },
                { "render", VisitRender },
                { "segment", VisitSection },
                { "cache", VisitCache },
                { "markdown", VisitMarkdown }
            };
            if (context.ParseSectionTagAsSegment)
            {
                _specialNodeMap.Add("section", VisitSection);
            }
        }
Пример #8
0
        public override IList<Chunk> GetChunks(VisitorContext context, string path)
        {
            context.SyntaxProvider = this;
            context.ViewPath = path;

            var sourceContext = CreateSourceContext(context.ViewPath, context.ViewFolder);
            var position = new Position(sourceContext);

            var isShadeExtension = string.Equals(Path.GetExtension(path), Constants.DotShade, StringComparison.OrdinalIgnoreCase);

            var parser = (isShadeExtension ? _grammar.OffsetNodes : _grammar.Nodes);
            var result = parser(position);
            if (result.Rest.PotentialLength() != 0)
            {
                ThrowParseException(context.ViewPath, position, result.Rest);
            }

            context.Paint = result.Rest.GetPaint();

            var nodes = result.Value;
            foreach (var visitor in BuildNodeVisitors(context))
            {
                visitor.Accept(nodes);
                nodes = visitor.Nodes;
            }

            var chunkBuilder = new ChunkBuilderVisitor(context);
            chunkBuilder.Accept(nodes);
            return chunkBuilder.Chunks;
        }
Пример #9
0
 public SpecialNodeVisitor(VisitorContext context)
     : base(context)
 {
     _containingNames = new List<string>(new[] { "var", "def", "default", "for", "use", "content", "test", "if", "else", "elseif", "macro", "render", "segment", "cache", "markdown", "ignore" });
     _nonContainingNames = new List<string>(new[] { "global", "set", "viewdata" });
     if(context.ParseSectionTagAsSegment)
         _containingNames.Add("section");
 }
 public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
 {
     ISparkElementTransformer elementTransformer = _sparkElementTransformerService.CreateElementTransformer(node);
     if(elementTransformer is NullSparkElementTransformer)
     {
         return null;
     }
     return new SparkOverrideExtension(node, elementTransformer);
 }
        public TestElseElementVisitor(VisitorContext context) : base(context)
        {
            Frame frame = new Frame {
                Nodes = new List <Node>()
            };

            this._frame = frame;
            this._stack = new Stack <Frame>();
        }
		public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
		{
			IEnumerable<IReplacement> replacements = GetApplicableReplacements(node);
			if (replacements.Any())
			{
				return new SparkExtension(node, replacements);
			}
			return null;
		}
Пример #13
0
 public SpecialNodeVisitor(VisitorContext context)
     : base(context)
 {
     _containingNames    = new List <string>(new[] { "var", "def", "default", "for", "use", "content", "test", "if", "else", "elseif", "macro", "render", "segment", "cache", "markdown" });
     _nonContainingNames = new List <string>(new[] { "global", "set", "viewdata" });
     if (context.ParseSectionTagAsSegment)
     {
         _containingNames.Add("section");
     }
 }
Пример #14
0
 public TargetExtension(VisitorContext context, ElementNode targetElement, int targetExtensionCount)
 {
     _context = context;
     _targetElement = targetElement;
     _targetExtensionCount = targetExtensionCount;
     _idAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "id");
     _classAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "class");
     _descriptionAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "description");
     _targetAttribute = _targetElement.Attributes.SingleOrDefault(attr => attr.Name == "target");
 }
Пример #15
0
 public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
 {
     if (string.Equals(node.Name, "div", StringComparison.OrdinalIgnoreCase))
     {
         return new TargetExtension(context, node, ++_TargetExtensionCount);
     } if (string.Equals(node.Name, "functions", StringComparison.OrdinalIgnoreCase))
     {
         return new FunctionsExtension(context, node);
     }
     return null;
 }
 public PrefixExpandingVisitor(VisitorContext context) : base(context)
 {
     this._prefixes = new List <PrefixSpecs>();
     this._prefixes = new List <PrefixSpecs> {
         new PrefixSpecs("segment", "http://sparkviewengine.com/segment/", "segment", "name"), new PrefixSpecs("macro", "http://sparkviewengine.com/macro/", "macro", "name"), new PrefixSpecs("content", "http://sparkviewengine.com/content/", "content", "name"), new PrefixSpecs("use", "http://sparkviewengine.com/use/", "use", "content"), new PrefixSpecs("render", "http://sparkviewengine.com/render/", "render", "segment")
     };
     if (context.ParseSectionTagAsSegment)
     {
         this._prefixes.Add(new PrefixSpecs("render", "http://sparkviewengine.com/render/", "render", "section"));
         this._prefixes.Add(new PrefixSpecs("section", "http://sparkviewengine.com/section/", "section", "name"));
     }
 }
Пример #17
0
 public PrefixExpandingVisitor(VisitorContext context)
     : base(context)
 {
     _prefixes = new[]
     {
         new PrefixSpecs("section", Constants.SectionNamespace, "section", "name"),
         new PrefixSpecs("macro", Constants.MacroNamespace, "macro", "name"),
         new PrefixSpecs("content", Constants.ContentNamespace, "content", "name"),
         new PrefixSpecs("use", Constants.UseNamespace, "use", "content"),
         new PrefixSpecs("render", Constants.RenderNamespace, "render", "section")
     };
 }
Пример #18
0
        public override IList<Chunk> GetChunks(VisitorContext context, string path)
        {
            if (!_releaseMode) return base.GetChunks(context, path);
            context.SyntaxProvider = this;
            context.ViewPath = path;

            var sourceContext = CreateSourceContext(context.ViewPath, context.ViewFolder);
            var position = new Position(sourceContext);

            var result = _grammar.Nodes(position);
            if (result.Rest.PotentialLength() != 0)
            {
                ThrowParseException(context.ViewPath, position, result.Rest);
            }

            context.Paint = result.Rest.GetPaint();

            var nodes = result.Value;

            //Minification
            ((List<Node>)nodes).RemoveAll(x => (x.GetType() == typeof(CommentNode)));
            var nodesToRem = new List<Node>();
            foreach (var textNode in nodes.OfType<TextNode>())
            {
                if (String.IsNullOrEmpty(textNode.Text.Trim()))
                {
                    nodesToRem.Add(textNode);
                    continue;
                }
                textNode.Text = Regex.Replace(textNode.Text, "\\s+", " ");
            }
            ((List<Node>)nodes).RemoveAll(x => nodesToRem.Contains(x));
            foreach (var elementNode in nodes.OfType<ElementNode>())
            {
                elementNode.PreceedingWhitespace = null;
            }
            foreach (var elementNode in nodes.OfType<EndElementNode>())
            {
                elementNode.PreceedingWhitespace = null;
            }
            //end of Minification

            foreach (var visitor in BuildNodeVisitors(context))
            {
                visitor.Accept(nodes);
                nodes = visitor.Nodes;
            }

            var chunkBuilder = new ChunkBuilderVisitor(context);
            chunkBuilder.Accept(nodes);
            return chunkBuilder.Chunks;
        }
Пример #19
0
        public WhitespaceCleanerVisitor(VisitorContext context)
            : base(context)
        {
            this.nodePaint = Context.Paint.OfType <Paint <Node> >().ToDictionary(paint => paint.Value);

            this.specialNodeMap = new Dictionary <string, Action <SpecialNode, SpecialNodeInspector> >
            {
                { "for", VisitFor },
                { "test", VisitIf },
                { "if", VisitIf },
                { "else", VisitIf },
                { "elseif", VisitIf },
            };
        }
Пример #20
0
        public WhitespaceCleanerVisitor(VisitorContext context) : base(context)
        {
            this.nodes     = new List <Node>();
            this.nodePaint = base.Context.Paint.OfType <Paint <Node> >().ToDictionary <Paint <Node>, Node>(paint => paint.Value);
            Dictionary <string, Action <SpecialNode, SpecialNodeInspector> > dictionary = new Dictionary <string, Action <SpecialNode, SpecialNodeInspector> >();

            dictionary.Add("for", new Action <SpecialNode, SpecialNodeInspector>(this.VisitFor));
            dictionary.Add("test", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            dictionary.Add("if", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            dictionary.Add("else", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            dictionary.Add("elseif", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            dictionary.Add("unless", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            this.specialNodeMap = dictionary;
        }
 public SpecialNodeVisitor(VisitorContext context) : base(context)
 {
     this._extensionNodes  = new Stack <ExtensionNode>();
     this._nodes           = new List <Node>();
     this._stack           = new Stack <IList <Node> >();
     this._containingNames = new List <string>(new string[] {
         "var", "def", "default", "for", "use", "content", "test", "if", "else", "elseif", "unless", "macro", "render", "segment", "cache", "markdown",
         "ignore"
     });
     this._nonContainingNames = new List <string>(new string[] { "global", "set", "viewdata" });
     if (context.ParseSectionTagAsSegment)
     {
         this._containingNames.Add("section");
     }
 }
Пример #22
0
 public NamespaceVisitor(VisitorContext context)
     : base(context)
 {
     FrameData.Nametable = new Dictionary <string, string>();
     if (!string.IsNullOrEmpty(context.Prefix))
     {
         Context.Namespaces = NamespacesType.Qualified;
         FrameData.Nametable[context.Prefix] = Constants.Namespace;
         FrameData.Nametable["content"]      = Constants.ContentNamespace;
         FrameData.Nametable["use"]          = Constants.UseNamespace;
         FrameData.Nametable["macro"]        = Constants.MacroNamespace;
         FrameData.Nametable["section"]      = Constants.SectionNamespace;
         FrameData.Nametable["render"]       = Constants.RenderNamespace;
     }
 }
Пример #23
0
        public override IList<Chunk> GetChunks(VisitorContext context, string path)
        {
            context.ViewPath = path;
            var sourceContext = CreateSourceContext(context.ViewPath, context.ViewFolder);
            var position = new Position(sourceContext);

            var nodes = _grammar.Nodes(position);
            if (nodes.Rest.PotentialLength() != 0)
            {
                ThrowParseException(context.ViewPath, position, nodes.Rest);
            }
            context.Paint = nodes.Rest.GetPaint();

            var chunkBuilder = new ChunkBuilderVisitor(context);
            chunkBuilder.Accept(nodes.Value);
            return chunkBuilder.Chunks;
        }
Пример #24
0
        public override IList<Node> IncludeFile(VisitorContext context, string path, string parse)
        {
            var existingPath = context.ViewPath;

            var directoryPath = Path.GetDirectoryName(context.ViewPath);
            var relativePath = path.Replace('/', '\\');
            while (relativePath.StartsWith("..\\"))
            {
                directoryPath = Path.GetDirectoryName(directoryPath);
                relativePath = relativePath.Substring(3);
            }

            context.ViewPath = Path.Combine(directoryPath, relativePath);

            var sourceContext = CreateSourceContext(context.ViewPath, context.ViewFolder);

            switch (parse)
            {
                case "text":
                    var encoded = sourceContext.Content
                        .Replace("&", "&amp;")
                        .Replace("<", "&lt;")
                        .Replace(">", "&gt;");
                    return new[] { new TextNode(encoded) };
                case "html":
                    return new[] { new TextNode(sourceContext.Content) };
            }

            var position = new Position(sourceContext);
            var result = _grammar.Nodes(position);
            if (result.Rest.PotentialLength() != 0)
            {
                ThrowParseException(context.ViewPath, position, result.Rest);
            }

            context.Paint = context.Paint.Union(result.Rest.GetPaint());

            var namespaceVisitor = new NamespaceVisitor(context);
            namespaceVisitor.Accept(result.Value);

            var includeVisitor = new IncludeVisitor(context);
            includeVisitor.Accept(namespaceVisitor.Nodes);

            context.ViewPath = existingPath;
            return includeVisitor.Nodes;
        }
 public NamespaceVisitor(VisitorContext context) : base(context)
 {
     base.FrameData.Nametable = new Dictionary <string, string>();
     if (!string.IsNullOrEmpty(context.Prefix))
     {
         base.Context.Namespaces = NamespacesType.Qualified;
         base.FrameData.Nametable[context.Prefix] = "http://sparkviewengine.com/";
         base.FrameData.Nametable["content"]      = "http://sparkviewengine.com/content/";
         base.FrameData.Nametable["use"]          = "http://sparkviewengine.com/use/";
         base.FrameData.Nametable["macro"]        = "http://sparkviewengine.com/macro/";
         base.FrameData.Nametable["segment"]      = "http://sparkviewengine.com/segment/";
         base.FrameData.Nametable["render"]       = "http://sparkviewengine.com/render/";
         if (context.ParseSectionTagAsSegment)
         {
             base.FrameData.Nametable["section"] = "http://sparkviewengine.com/section/";
         }
     }
 }
Пример #26
0
 public PrefixExpandingVisitor(VisitorContext context)
     : base(context)
 {
     _prefixes = new List <PrefixSpecs>
     {
         new PrefixSpecs("segment", Constants.SegmentNamespace, "segment", "name"),
         new PrefixSpecs("macro", Constants.MacroNamespace, "macro", "name"),
         new PrefixSpecs("content", Constants.ContentNamespace, "content", "name"),
         new PrefixSpecs("use", Constants.UseNamespace, "use", "content"),
         new PrefixSpecs("render", Constants.RenderNamespace, "render", "segment")
     };
     if (!context.ParseSectionTagAsSegment)
     {
         return;
     }
     _prefixes.Add(new PrefixSpecs("render", Constants.RenderNamespace, "render", "section"));
     _prefixes.Add(new PrefixSpecs("section", Constants.SectionNamespace, "section", "name"));
 }
Пример #27
0
 public ISparkExtension CreateExtension(VisitorContext context, ElementNode node)
 {
     //what is better: create different extensions for each tags or place all code into one extension?
     switch (node.Name)
     {
         case "body":
             return new BodyTagSparkExtension(node);
         case "form":
             return new FormTagSparkExtension(node);
         case "a":
             return new AnchorTagSparkExtension(node);
         case "link":
             return new StaticResourcesTagsSparkExtension(node, "href");
         case "script":
             return new StaticResourcesTagsSparkExtension(node, "src");
         case "img":
             return new StaticResourcesTagsSparkExtension(node, "src");
         default:
             return null;
     }
 }
Пример #28
0
        public void FindLoopParameters()
        {
            var context = new VisitorContext
                              {
                                  SyntaxProvider = new DefaultSyntaxProvider(new SparkSettings())
                              };
            var nodes = ParseNodes("<for each='var x in new [] {1,2,3}'>${xIndex}${xIsLast}</for>",
                                   new SpecialNodeVisitor(context));

            var visitor = new ChunkBuilderVisitor(context);
            visitor.Accept(nodes);

            var expressionVisitor = new DetectCodeExpressionVisitor(null);
            var index = expressionVisitor.Add("xIndex");
            var count = expressionVisitor.Add("xCount");
            var isFirst = expressionVisitor.Add("xIsFirst");
            var isLast = expressionVisitor.Add("xIsLast");
            expressionVisitor.Accept(visitor.Chunks);

            Assert.IsTrue(index.Detected);
            Assert.IsFalse(count.Detected);
            Assert.IsFalse(isFirst.Detected);
            Assert.IsTrue(isLast.Detected);
        }
Пример #29
0
 protected AbstractNodeVisitor(VisitorContext context)
 {
     Context = context;
 }
Пример #30
0
 public TestElseElementVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #31
0
 public ForEachAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #32
0
 private IList<INodeVisitor> BuildNodeVisitors(VisitorContext context)
 {
     return new INodeVisitor[]
                {
                    new NamespaceVisitor(context),
                    new IncludeVisitor(context),
                    new PrefixExpandingVisitor(context),
                    new SpecialNodeVisitor(context),
                    new CacheAttributeVisitor(context),
                    new WhitespaceCleanerVisitor(context),
                    new ForEachAttributeVisitor(context),
                    new ConditionalAttributeVisitor(context),
                    new TestElseElementVisitor(context),
                    new OnceAttributeVisitor(context),
                    new UrlAttributeVisitor(context),
                    new BindingExpansionVisitor(context)
                };
 }
Пример #33
0
 public BindingExpansionVisitor(VisitorContext context)
     : base(context)
 {
 }
 protected NodeVisitor(VisitorContext context) : base(context)
 {
     this.PushFrame(new List <Node>(), Activator.CreateInstance <TFrameData>());
 }
Пример #35
0
 public abstract IList<Node> IncludeFile(VisitorContext context, string path, string parse);
Пример #36
0
 protected AbstractNodeVisitor(VisitorContext context)
 {
     Context = context;
 }
Пример #37
0
 protected SpecialAttributeVisitorBase(VisitorContext context)
     : base(context)
 {
 }
Пример #38
0
 public ForEachAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #39
0
        void LoadInternal(string viewPath)
        {
            if (string.IsNullOrEmpty(viewPath))
                return;

            var newEntry = BindEntry(viewPath);

            var context = new VisitorContext
                                         {
                                             ViewFolder = ViewFolder,
                                             Prefix = Prefix,
                                             ExtensionFactory = ExtensionFactory,
                                             PartialFileNames = FindPartialFiles(viewPath)
                                         };
            newEntry.Chunks = SyntaxProvider.GetChunks(context, viewPath);

            var fileReferenceVisitor = new FileReferenceVisitor();
            fileReferenceVisitor.Accept(newEntry.Chunks);

            foreach (var useFile in fileReferenceVisitor.References)
            {
                var referencePath = ResolveReference(viewPath, useFile.Name);

                if (!string.IsNullOrEmpty(referencePath))
                {
                    useFile.FileContext = BindEntry(referencePath).FileContext;
                }
            }
        }
 public IncludeVisitor(VisitorContext context) : base(context)
 {
 }
Пример #41
0
 public BindingExpansionVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #42
0
 public OnceAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #43
0
 public IndentationVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #44
0
 public CacheAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #45
0
 public CacheAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #46
0
 public override IList<Node> IncludeFile(VisitorContext context, string path, string parse)
 {
     throw new System.NotImplementedException();
 }
Пример #47
0
 public abstract IList<Chunk> GetChunks(VisitorContext context, string path);
Пример #48
0
 public TestElseElementVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #49
0
 protected NodeVisitor(VisitorContext context) : base(context)
 {
     PushFrame(new List <Node>(), new TFrameData());
 }
Пример #50
0
 public OnceAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #51
0
        public static IList<Chunk> ParseElementChunks(string content, int position)
        {
            var node = ParseNode(content, position);
            var contentToParse = node is ElementNode ? GetElementNodeAsString((ElementNode)node) : content;

            var grammar = new MarkupGrammar();
            var visitorContext = new VisitorContext { SyntaxProvider = new DefaultSyntaxProvider(new ParserSettings()) };
            var result = grammar.Nodes(Source(contentToParse));
            var nodes = result.Value;
            foreach (var visitor in BuildChunkVisitors(visitorContext))
            {
                visitor.Accept(nodes);
                nodes = visitor.Nodes;
            }

            var chunkBuilder = new ChunkBuilderVisitor(visitorContext);
            chunkBuilder.Accept(nodes);
            var chunks = chunkBuilder.Chunks;
            return chunks;
        }
Пример #52
0
        public ChunkBuilderVisitor(VisitorContext context) : base(context)
        {
            Action <SpecialNode, SpecialNodeInspector> action  = null;
            Action <SpecialNode, SpecialNodeInspector> action2 = null;
            Action <SpecialNode, SpecialNodeInspector> action3 = null;
            Action <SpecialNode, SpecialNodeInspector> action4 = null;
            Action <SpecialNode, SpecialNodeInspector> action5 = null;
            Action <SpecialNode, SpecialNodeInspector> action6 = null;

            this._nodePaint = base.Context.Paint.OfType <Paint <Node> >().ToDictionary <Paint <Node>, Node>(paint => paint.Value);
            this.Chunks     = new List <Chunk>();
            Dictionary <string, Action <SpecialNode, SpecialNodeInspector> > dictionary = new Dictionary <string, Action <SpecialNode, SpecialNodeInspector> >();

            dictionary.Add("var", new Action <SpecialNode, SpecialNodeInspector>(this.VisitVar));
            dictionary.Add("def", new Action <SpecialNode, SpecialNodeInspector>(this.VisitVar));
            dictionary.Add("default", new Action <SpecialNode, SpecialNodeInspector>(this.VisitDefault));
            if (action == null)
            {
                action = (n, i) => this.VisitGlobal(n);
            }
            dictionary.Add("global", action);
            if (action2 == null)
            {
                action2 = (n, i) => this.VisitViewdata(i);
            }
            dictionary.Add("viewdata", action2);
            if (action3 == null)
            {
                action3 = (n, i) => this.VisitSet(i);
            }
            dictionary.Add("set", action3);
            dictionary.Add("for", new Action <SpecialNode, SpecialNodeInspector>(this.VisitFor));
            dictionary.Add("test", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            dictionary.Add("if", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIf));
            if (action4 == null)
            {
                action4 = (n, i) => this.VisitElse(i);
            }
            dictionary.Add("else", action4);
            dictionary.Add("elseif", new Action <SpecialNode, SpecialNodeInspector>(this.VisitElseIf));
            dictionary.Add("unless", new Action <SpecialNode, SpecialNodeInspector>(this.VisitUnless));
            if (action5 == null)
            {
                action5 = (n, i) => this.VisitContent(i);
            }
            dictionary.Add("content", action5);
            dictionary.Add("use", new Action <SpecialNode, SpecialNodeInspector>(this.VisitUse));
            if (action6 == null)
            {
                action6 = (n, i) => this.VisitMacro(i);
            }
            dictionary.Add("macro", action6);
            dictionary.Add("render", new Action <SpecialNode, SpecialNodeInspector>(this.VisitRender));
            dictionary.Add("segment", new Action <SpecialNode, SpecialNodeInspector>(this.VisitSection));
            dictionary.Add("cache", new Action <SpecialNode, SpecialNodeInspector>(this.VisitCache));
            dictionary.Add("markdown", new Action <SpecialNode, SpecialNodeInspector>(this.VisitMarkdown));
            dictionary.Add("ignore", new Action <SpecialNode, SpecialNodeInspector>(this.VisitIgnore));
            this._specialNodeMap = dictionary;
            if (context.ParseSectionTagAsSegment)
            {
                this._specialNodeMap.Add("section", new Action <SpecialNode, SpecialNodeInspector>(this.VisitSection));
            }
        }
Пример #53
0
 public ConditionalAttributeVisitor(VisitorContext context)
     : base(context)
 {
 }
Пример #54
0
 private static IList<INodeVisitor> BuildChunkVisitors(VisitorContext context)
 {
     return new INodeVisitor[]
                {
                    new NamespaceVisitor(context),
                    new IncludeVisitor(context),
                    new PrefixExpandingVisitor(context),
                    new SpecialNodeVisitor(context),
                    new CacheAttributeVisitor(context),
                    new ForEachAttributeVisitor(context),
                    new ConditionalAttributeVisitor(context),
                    new OmitExtraLinesVisitor(context),
                    new TestElseElementVisitor(context),
                    new OnceAttributeVisitor(context),
                    new UrlAttributeVisitor(context),
                    //new BindingExpansionVisitor(context)
                };
 }
Пример #55
0
        private void LoadInternal(string viewPath)
        {
            if (string.IsNullOrEmpty(viewPath))
            {
                return;
            }

            var newEntry = this.BindEntry(viewPath);

            var context = new VisitorContext
            {
                ViewFolder = this.ViewFolder,
                Prefix = this.Prefix,
                ExtensionFactory = this.ExtensionFactory,
                PartialFileNames = this.FindPartialFiles(viewPath),
                Bindings = this.FindBindings(viewPath),
                ParseSectionTagAsSegment = this.ParseSectionTagAsSegment
            };
            newEntry.Chunks = this.SyntaxProvider.GetChunks(context, viewPath);

            var fileReferenceVisitor = new FileReferenceVisitor();
            fileReferenceVisitor.Accept(newEntry.Chunks);

            foreach (var useFile in fileReferenceVisitor.References)
            {
                var referencePath = this.ResolveReference(viewPath, useFile.Name);

                if (!string.IsNullOrEmpty(referencePath))
                {
                    useFile.FileContext = this.BindEntry(referencePath).FileContext;
                }
            }
        }
 public NodeVisitor(VisitorContext context) : base(context)
 {
 }