Ejemplo n.º 1
0
 public CssAnalyseArgs(Document document, CssAnalyserTargets target, ICssNode node, IElement element)
     : base(document)
 {
     Target  = target;
     Node    = node;
     Element = element;
 }
Ejemplo n.º 2
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 <ICssNode> GetAllDescendents(this ICssNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.Children.SelectMany(m => m.GetAllDescendents()));
        }
Ejemplo n.º 3
0
        private static string GetExcerpt(ICssNode node)
        {
            if (node == null)
            {
                return(null);
            }

            return(node.ToCss());
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
        void Setup(ICssNode child)
        {
            var rule = child as CssRule;

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

            if (rule != null)
            {
                rule.Parent = null;
                rule.Owner  = null;
            }
        }
Ejemplo n.º 7
0
        protected void ReplaceAll(ICssNode node)
        {
            Clear();
            _source = node.SourceCode;

            foreach (var child in node.Children)
            {
                AppendChild(child);
            }
        }
Ejemplo n.º 8
0
 public void InsertBefore(ICssNode referenceChild, ICssNode child)
 {
     if (referenceChild != null)
     {
         var index = _children.IndexOf(referenceChild);
         InsertChild(index, child);
     }
     else
     {
         AppendChild(child);
     }
 }
Ejemplo n.º 9
0
 public void InsertBefore(ICssNode referenceChild, ICssNode child)
 {
     if (referenceChild != null)
     {
         var index = _children.IndexOf(referenceChild);
         InsertChild(index, child);
     }
     else
     {
         AppendChild(child);
     }
 }
Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 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
            });
        }
Ejemplo n.º 16
0
 private void Enqueue(Document document, string url, ICssNode node, CancellationToken ct)
 {
     Enqueue(document, url, null, GetExcerpt(node), ct);
 }
Ejemplo n.º 17
0
 public void RemoveChild(ICssNode child)
 {
     Teardown(child);
     _children.Remove(child);
 }
Ejemplo n.º 18
0
        protected void ReplaceAll(ICssNode node)
        {
            Clear();
            _source = node.SourceCode;

            foreach (var child in node.Children)
            {
                AppendChild(child);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 20
0
 public void RemoveChild(ICssNode child)
 {
     Teardown(child);
     _children.Remove(child);
 }
Ejemplo n.º 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>());
 }
Ejemplo n.º 22
0
        void Setup(ICssNode child)
        {
            var rule = child as CssRule;

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

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