Ejemplo n.º 1
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @namespace = documentNode.FindPrimaryNamespace();
            var @class     = documentNode.FindPrimaryClass();

            if (@namespace == null || @class == null)
            {
                // Nothing to do, bail. We can't function without the standard structure.
                return;
            }

            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];

                for (var j = node.Children.Count - 1; j >= 0; j--)
                {
                    var attributeNode = node.Children[j] as ComponentAttributeExtensionNode;
                    if (attributeNode != null &&
                        attributeNode.TagHelper != null &&
                        attributeNode.TagHelper.IsRefTagHelper())
                    {
                        RewriteUsage(@class, node, j, attributeNode);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @namespace = documentNode.FindPrimaryNamespace();
            var @class     = documentNode.FindPrimaryClass();

            if (@namespace == null || @class == null)
            {
                // Nothing to do, bail. We can't function without the standard structure.
                return;
            }

            // For each bind *usage* we need to rewrite the tag helper node to map to basic constructs.
            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];

                ProcessDuplicates(node);

                for (var j = node.Children.Count - 1; j >= 0; j--)
                {
                    var attributeNode = node.Children[j] as ComponentAttributeExtensionNode;
                    if (attributeNode != null &&
                        attributeNode.TagHelper != null &&
                        attributeNode.TagHelper.IsBindTagHelper())
                    {
                        RewriteUsage(node, j, attributeNode);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @namespace = documentNode.FindPrimaryNamespace();
            var @class     = documentNode.FindPrimaryClass();

            if (@namespace == null || @class == null)
            {
                // Nothing to do, bail. We can't function without the standard structure.
                return;
            }

            var context = new Context(@namespace, @class);

            // For each VCTH *usage* we need to rewrite the tag helper node to use the tag helper runtime to construct
            // and set properties on the the correct field, and using the name of the type we will generate.
            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];
                foreach (var tagHelper in node.TagHelpers)
                {
                    RewriteUsage(context, node, tagHelper);
                }
            }

            // Then for each VCTH *definition* that we've seen we need to generate the class that implements
            // ITagHelper and the field that will hold it.
            foreach (var tagHelper in context.TagHelpers)
            {
                AddField(context, tagHelper);
                AddTagHelperClass(context, tagHelper);
            }
        }
Ejemplo n.º 4
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @namespace = documentNode.FindPrimaryNamespace();
            var @class     = documentNode.FindPrimaryClass();

            if (@namespace == null || @class == null)
            {
                // Nothing to do, bail. We can't function without the standard structure.
                return;
            }

            // For each component *usage* we need to rewrite the tag helper node to map to the relevant component
            // APIs.
            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                var node = nodes[i];
                if (node.TagHelpers.Count > 1)
                {
                    node.Diagnostics.Add(BlazorDiagnosticFactory.Create_MultipleComponents(node.Source, node.TagName, node.TagHelpers));
                }

                RewriteUsage(node, node.TagHelpers[0]);
            }
        }
Ejemplo n.º 5
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                ProcessAttributes(nodes[i]);
            }
        }
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @class = documentNode.FindPrimaryClass();

            if (@class == null)
            {
                // Bail if we can't find a class node, we need to be able to create fields.
                return;
            }

            var context = new Context(@class);

            // First find all tag helper nodes that require the default tag helper runtime.
            //
            // This phase lowers the conceptual nodes to default runtime nodes we only care about those.
            var tagHelperNodes = documentNode
                                 .FindDescendantNodes <TagHelperIntermediateNode>()
                                 .Where(IsTagHelperRuntimeNode)
                                 .ToArray();

            if (tagHelperNodes.Length == 0)
            {
                // If nothing uses the default runtime then we're done.
                return;
            }

            AddDefaultRuntime(context);

            // Each tagHelperNode should be rewritten to use the default tag helper runtime. That doesn't necessarily
            // mean that all of these tag helpers are the default kind, just that them are compatible with ITagHelper.
            for (var i = 0; i < tagHelperNodes.Length; i++)
            {
                var tagHelperNode = tagHelperNodes[i];

                RewriteBody(tagHelperNode);
                RewriteHtmlAttributes(tagHelperNode);
                AddExecute(tagHelperNode);

                // We need to find all of the 'default' kind tag helpers and rewrite their usage site to use the
                // extension nodes for the default tag helper runtime (ITagHelper).
                foreach (var tagHelper in tagHelperNode.TagHelpers)
                {
                    RewriteUsage(context, tagHelperNode, tagHelper);
                }
            }

            // Then for each 'default' kind tag helper we need to generate the field that will hold it.
            foreach (var tagHelper in context.TagHelpers)
            {
                AddField(context, tagHelper);
            }
        }
Ejemplo n.º 7
0
    protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
    {
        if (!IsComponentDocument(documentNode))
        {
            return;
        }

        var cssScope = codeDocument.GetCssScope();

        if (string.IsNullOrEmpty(cssScope))
        {
            return;
        }

        var nodes = documentNode.FindDescendantNodes <MarkupElementIntermediateNode>();

        for (var i = 0; i < nodes.Count; i++)
        {
            ProcessElement(nodes[i], cssScope);
        }
    }
Ejemplo n.º 8
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var cssScope = codeDocument.GetCssScope();

            if (string.IsNullOrEmpty(cssScope))
            {
                return;
            }

            if (!string.Equals(documentNode.DocumentKind, "mvc.1.0.view", StringComparison.Ordinal) &&
                !string.Equals(documentNode.DocumentKind, "mvc.1.0.razor-page", StringComparison.Ordinal))
            {
                return;
            }

            var scopeWithSeparator = " " + cssScope;
            var nodes = documentNode.FindDescendantNodes <HtmlContentIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                ProcessElement(nodes[i], scopeWithSeparator);
            }
        }
Ejemplo n.º 9
0
        protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
        {
            var @namespace = documentNode.FindPrimaryNamespace();
            var @class     = documentNode.FindPrimaryClass();

            if (@namespace == null || @class == null)
            {
                // Nothing to do, bail. We can't function without the standard structure.
                return;
            }

            // For each component *usage* we need to rewrite the tag helper node to map to the relevant component
            // APIs.
            var nodes = documentNode.FindDescendantNodes <TagHelperIntermediateNode>();

            for (var i = 0; i < nodes.Count; i++)
            {
                var count = 0;
                var node  = nodes[i];
                for (var j = 0; j < node.TagHelpers.Count; j++)
                {
                    if (node.TagHelpers[j].IsComponentTagHelper())
                    {
                        // Only allow a single component tag helper per element. We also have some *special* tag helpers
                        // and they should have already been processed by now.
                        if (count++ > 1)
                        {
                            node.Diagnostics.Add(BlazorDiagnosticFactory.Create_MultipleComponents(node.Source, node.TagName, node.TagHelpers));
                            break;
                        }

                        RewriteUsage(node, node.TagHelpers[j]);
                    }
                }
            }
        }