示例#1
0
 public CssAnalyseArgs(Document document, CssAnalyserTargets target, ICssNode node, IElement element)
     : base(document)
 {
     Target  = target;
     Node    = node;
     Element = element;
 }
        /// <summary>
        /// Gets all descendents of the provided node.
        /// </summary>
        /// <param name="node">The node to examine.</param>
        /// <returns>An iterator over all contained nodes.</returns>
        public static IEnumerable <ICssNode> GetAllDescendents(this ICssNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.Children.SelectMany(m => m.GetAllDescendents()));
        }
示例#3
0
        private static string GetExcerpt(ICssNode node)
        {
            if (node == null)
            {
                return(null);
            }

            return(node.ToCss());
        }
示例#4
0
        private void HandleCss(Document document, string baseUrl, ICssNode node, CancellationToken ct)
        {
            GatherUrls(document, baseUrl, node, ct);

            foreach (var child in node.Children)
            {
                HandleCss(document, baseUrl, child, ct);
            }
        }
示例#5
0
        void Setup(ICssNode child)
        {
            var rule = child as CssRule;

            if (rule != null)
            {
                rule.Owner  = this as ICssStyleSheet;
                rule.Parent = this as ICssRule;
            }
        }
示例#6
0
        void Teardown(ICssNode child)
        {
            var rule = child as CssRule;

            if (rule != null)
            {
                rule.Parent = null;
                rule.Owner  = null;
            }
        }
示例#7
0
        protected void ReplaceAll(ICssNode node)
        {
            Clear();
            _source = node.SourceCode;

            foreach (var child in node.Children)
            {
                AppendChild(child);
            }
        }
示例#8
0
 public void InsertBefore(ICssNode referenceChild, ICssNode child)
 {
     if (referenceChild != null)
     {
         var index = _children.IndexOf(referenceChild);
         InsertChild(index, child);
     }
     else
     {
         AppendChild(child);
     }
 }
示例#9
0
 public void InsertBefore(ICssNode referenceChild, ICssNode child)
 {
     if (referenceChild != null)
     {
         var index = _children.IndexOf(referenceChild);
         InsertChild(index, child);
     }
     else
     {
         AppendChild(child);
     }
 }
示例#10
0
 public void ReplaceChild(ICssNode oldChild, ICssNode newChild)
 {
     for (var i = 0; i < _children.Count; i++)
     {
         if (Object.ReferenceEquals(oldChild, _children[i]))
         {
             Teardown(oldChild);
             Setup(newChild);
             _children[i] = newChild;
             return;
         }
     }
 }
示例#11
0
 public void ReplaceChild(ICssNode oldChild, ICssNode newChild)
 {
     for (var i = 0; i < _children.Count; i++)
     {
         if (Object.ReferenceEquals(oldChild, _children[i]))
         {
             Teardown(oldChild);
             Setup(newChild);
             _children[i] = newChild;
             return;
         }
     }
 }
示例#12
0
        /// <summary>
        /// Gets all descendents of the provided node.
        /// </summary>
        /// <param name="node">The node to examine.</param>
        /// <returns>An iterator over all contained nodes.</returns>
        public static IEnumerable <T> GetAll <T>(this ICssNode node)
            where T : IStyleFormattable
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node is T)
            {
                yield return((T)node);
            }

            foreach (var entity in node.Children.SelectMany(m => m.GetAll <T>()))
            {
                yield return(entity);
            }
        }
示例#13
0
 protected void ReplaceSingle(ICssNode oldNode, ICssNode newNode)
 {
     if (oldNode != null)
     {
         if (newNode != null)
         {
             ReplaceChild(oldNode, newNode);
         }
         else
         {
             RemoveChild(oldNode);
         }
     }
     else if (newNode != null)
     {
         AppendChild(newNode);
     }
 }
示例#14
0
 private void GatherUrls(Document document, string baseUrl, ICssNode node, CancellationToken ct)
 {
     if (node is ICssProperty propertyRule)
     {
         string value = propertyRule.Value;
         if (value != null)
         {
             var parts = value.Split(',');
             foreach (var part in parts)
             {
                 var url = Utilities.ParseCssUrl(part);
                 if (url != null)
                 {
                     var finalUrl = GetAbsoluteUrl(new Url(baseUrl ?? document.Url), url);
                     Enqueue(document, finalUrl, propertyRule, ct);
                 }
             }
         }
     }
 }
示例#15
0
        private AnalyserResultItem CreateEmptyRuleResultItem(CssAnalyseArgs args, ICssNode node)
        {
            string excerpt = null;

            if (args.Target == CssAnalyserTargets.HtmlStyleAttribute)
            {
                excerpt = args.Element.OuterHtml;
            }

            if (excerpt == null)
            {
                excerpt = node.ToCss();
            }

            return(new AnalyserResultItem()
            {
                Category = Categories.Performance,
                Type = AnalyserResultType.Warning,
                Message = "Rule is empty",
                Excerpt = excerpt
            });
        }
示例#16
0
 private void Enqueue(Document document, string url, ICssNode node, CancellationToken ct)
 {
     Enqueue(document, url, null, GetExcerpt(node), ct);
 }
示例#17
0
 public void RemoveChild(ICssNode child)
 {
     Teardown(child);
     _children.Remove(child);
 }
示例#18
0
        protected void ReplaceAll(ICssNode node)
        {
            Clear();
            _source = node.SourceCode;

            foreach (var child in node.Children)
            {
                AppendChild(child);
            }
        }
示例#19
0
 protected void ReplaceSingle(ICssNode oldNode, ICssNode newNode)
 {
     if (oldNode != null)
     {
         if (newNode != null)
         {
             ReplaceChild(oldNode, newNode);
         }
         else
         {
             RemoveChild(oldNode);
         }
     }
     else if (newNode != null)
     {
         AppendChild(newNode);
     }
 }
示例#20
0
 public void RemoveChild(ICssNode child)
 {
     Teardown(child);
     _children.Remove(child);
 }
示例#21
0
 /// <summary>
 /// Gets the comments contained in the sheet, if any.
 /// </summary>
 /// <param name="node">The node to examine.</param>
 /// <returns>An iterator over all comments.</returns>
 public static IEnumerable <ICssComment> GetComments(this ICssNode node)
 {
     return(node.GetAll <ICssComment>());
 }
示例#22
0
        void Setup(ICssNode child)
        {
            var rule = child as CssRule;

            if (rule != null)
            {
                rule.Owner = this as ICssStyleSheet;
                rule.Parent = this as ICssRule;
            }
        }
示例#23
0
 public void InsertChild(Int32 index, ICssNode child)
 {
     Setup(child);
     _children.Insert(index, child);
 }
示例#24
0
        void Teardown(ICssNode child)
        {
            var rule = child as CssRule;

            if (rule != null)
            {
                rule.Parent = null;
                rule.Owner = null;
            }
        }
示例#25
0
 public void AppendChild(ICssNode child)
 {
     Setup(child);
     _children.Add(child);
 }
示例#26
0
 public void AppendChild(ICssNode child)
 {
     Setup(child);
     _children.Add(child);
 }
示例#27
0
 public void InsertChild(Int32 index, ICssNode child)
 {
     Setup(child);
     _children.Insert(index, child);
 }
示例#28
0
 public CssAnalyseArgs(Document document, CssAnalyserTargets target, ICssNode node)
     : this(document, target, node, null)
 {
 }