예제 #1
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;a&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "a", reader.EndTag)
                }
            });

            if (tagToken.FindAttribute("NavigateUrl") is { } navigateUrl)
            {
                yield return(new Suggestion()
                {
                    Description = "Change <code>NavigateUrl</code> to <code>href</code>",
                    Fixes = new FixAction[]
                    {
                        new RenameAttributeFix(navigateUrl, "a")
                    }
                });
            }
        }
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;dot:GridViewTextColumn&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:GridViewTextColumn", reader.EndTag)
                }
            });

            if (tagToken.FindAttribute("DataField") is { } dataField)
            {
                yield return(new Suggestion()
                {
                    Description = "Change <code>DataField</code> to <code>ValueBinding</code>",
                    Fixes = new FixAction[]
                    {
                        new RenameAttributeFix(dataField, "ValueBinding"),
                        new SetAttributeValueBindingFix(tagToken, "ValueBinding", dataField.GetValue()),
                    }
                });
            }
        }
예제 #3
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            var id = tagToken.FindOrGenerateId();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;dot:TextBox&gt;</code> and generate a viewmodel property",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:TextBox", reader.EndTag),
                    new SetAttributeValueBindingFix(tagToken, "Text", id),
                    new AddViewModelPropertyFix(id, "string")
                }
            });

            var autoPostBack = tagToken.FindAttribute("AutoPostBack");

            if (autoPostBack != null)
            {
                var changedEventName = "On" + id + "Changed";

                yield return(new Suggestion()
                {
                    Description = "Add a viewmodel command to handle the text change",
                    Fixes = new FixAction[]
                    {
                        new RemoveAttributeFix(tagToken, autoPostBack),
                        new SetAttributeCommandBindingFix(tagToken, "Changed", changedEventName),
                        new AddViewModelMethodFix(changedEventName, "void", $"// handle {id} property change")
                    }
                });
            }
        }
예제 #4
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            var id = tagToken.FindOrGenerateId();

            var commandName = "On" + id + "Click";

            yield return(new Suggestion()
            {
                Description = $"Change to <code>&lt;dot:{tagToken.TagNameWithoutPrefix}&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:" + tagToken.TagNameWithoutPrefix, reader.EndTag),
                    new SetAttributeCommandBindingFix(tagToken, "Click", commandName),
                    new AddViewModelMethodFix(commandName, "void", $"// handle click on {id} button")
                }
            });

            var onclick = tagToken.FindAttribute("OnClick");

            if (onclick != null)
            {
                yield return(new Suggestion()
                {
                    Description = $"Remove <code>OnClick</code> attribute",
                    Fixes = new FixAction[]
                    {
                        new RemoveAttributeFix(tagToken, onclick)
                    }
                });
            }
        }
예제 #5
0
 protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken)
 {
     yield return(new Suggestion()
     {
         Description = "Change <code>ToolTip</code> to <code>title</code>",
         Fixes = new FixAction[]
         {
             new RenameAttributeFix(attributeToken, "title")
         }
     });
 }
예제 #6
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;dot:Content&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:Content", reader.EndTag)
                }
            });
        }
예제 #7
0
 protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken)
 {
     if (string.Equals(attributeToken.GetValue(), "server", StringComparison.CurrentCultureIgnoreCase))
     {
         yield return(new Suggestion()
         {
             Description = @"DotVVM doesn't need <code>runat=""server""</code> attributes.",
             Fixes = new[]
             {
                 new RemoveAttributeFix(tagToken, attributeToken)
             }
         });
     }
 }
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken)
        {
            if (attributeToken.GetValue().StartsWith("{value"))
            {
                yield break;
            }

            var enabledProperty = tagToken.FindOrGenerateId() + "Enabled";

            yield return(new Suggestion()
            {
                Description = "Add viewmodel property to guide the <code>Enabled</code> state",
                Fixes = new FixAction[]
                {
                    new SetAttributeValueBindingFix(tagToken, "Enabled", enabledProperty),
                    new AddViewModelPropertyFix(enabledProperty, "bool")
                }
            });
        }
        private IList <AspxToken> ReadTokens(BeginTagToken beginTag)
        {
            var elementTokens = new List <AspxToken>
            {
                beginTag
            };

            if (!beginTag.IsSelfClosing)
            {
                // read all tags until the end tag
                var openTags = new Stack <string>();
                openTags.Push(beginTag.TagName);

                var token = GetNextToken();
                while (token != null)
                {
                    elementTokens.Add(token);

                    if (token is BeginTagToken b && !b.IsSelfClosing)
                    {
                        openTags.Push(b.TagName);
                    }
                    else if (token is EndTagToken e)
                    {
                        if (openTags.Contains(e.TagName, StringComparer.CurrentCultureIgnoreCase))
                        {
                            // ignore closing tags that are not on the stack
                            var lastTag = openTags.Pop();
                            while (!string.Equals(e.TagName, lastTag, StringComparison.CurrentCultureIgnoreCase) && openTags.Any())
                            {
                                openTags.Pop();
                            }
                        }

                        if (!openTags.Any())
                        {
                            break;
                        }
                    }

                    token = GetNextToken();
                }
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;dot:UpdateProgress&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:UpdateProgress", reader.EndTag)
                }
            });

            if (reader.Elements.TryGetValue("ContentTemplate", out var contentTemplate))
            {
                yield return(new Suggestion()
                {
                    Description = "Remove the <code>ContentTemplate</code> wrapper element",
                    Fixes = new FixAction[]
                    {
                        new RemoveTokenFix(contentTemplate[0]),
                        new RemoveTokenFix(contentTemplate[^ 1])
예제 #11
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;dot:Repeater&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "dot:Repeater", reader.EndTag)
                }
            });

            if (reader.Elements.TryGetValue("HeaderTemplate", out var headerTemplate))
            {
                yield return(new Suggestion()
                {
                    Description = "Move <code>HeaderTemplate</code> before the control",
                    Fixes = new FixAction[]
                    {
                        new MoveTokenRangeFix(headerTemplate.ElementAt(1), headerTemplate.Count - 2, tagToken, Placement.Before),
                        new RemoveTokenFix(headerTemplate[0]),
                        new RemoveTokenFix(headerTemplate[^ 1])
예제 #12
0
        protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory)
        {
            var reader = readerFactory();

            yield return(new Suggestion()
            {
                Description = "Change to <code>&lt;img&gt;</code>",
                Fixes = new FixAction[]
                {
                    new RenameElementFix(tagToken, "img", reader.EndTag)
                }
            });

            if (tagToken.FindAttribute("ImageUrl") is { } imageUrl)
            {
                yield return(new Suggestion()
                {
                    Description = "Change <code>ImageUrl</code> to <code>src</code>",
                    Fixes = new FixAction[]
                    {
                        new RenameAttributeFix(imageUrl, "src")
                    }
                });
            }

            if (tagToken.FindAttribute("AlternateText") is { } alternateText)
            {
                yield return(new Suggestion()
                {
                    Description = "Change <code>AlternateText</code> to <code>alt</code>",
                    Fixes = new FixAction[]
                    {
                        new RenameAttributeFix(alternateText, "alt")
                    }
                });
            }
        }
예제 #13
0
 public RemoveAttributeFix(BeginTagToken tag, AttributeToken attribute)
 {
     Tag       = tag;
     Attribute = attribute;
 }
예제 #14
0
 public RenameElementFix(BeginTagToken tag, string newName, EndTagToken endTag = null)
 {
     Tag     = tag;
     NewName = newName;
     EndTag  = endTag;
 }
예제 #15
0
 public SetAttributeCommandBindingFix(BeginTagToken tag, string name, string commandName)
 {
     Tag         = tag;
     Name        = name;
     CommandName = commandName;
 }
예제 #16
0
 protected abstract IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken);
 public SetAttributeValueBindingFix(BeginTagToken tag, string name, string viewModelProperty)
 {
     Tag  = tag;
     Name = name;
     ViewModelProperty = viewModelProperty;
 }
예제 #18
0
 protected abstract IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory);