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())); }
private static string GetExcerpt(ICssNode node) { if (node == null) { return(null); } return(node.ToCss()); }
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); } }
void Setup(ICssNode child) { var rule = child as CssRule; if (rule != null) { rule.Owner = this as ICssStyleSheet; rule.Parent = this as ICssRule; } }
void Teardown(ICssNode child) { var rule = child as CssRule; if (rule != null) { rule.Parent = null; rule.Owner = null; } }
protected void ReplaceAll(ICssNode node) { Clear(); _source = node.SourceCode; foreach (var child in node.Children) { AppendChild(child); } }
public void InsertBefore(ICssNode referenceChild, ICssNode child) { if (referenceChild != null) { var index = _children.IndexOf(referenceChild); InsertChild(index, child); } else { AppendChild(child); } }
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; } } }
/// <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); } }
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); } }
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); } } } } }
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 }); }
private void Enqueue(Document document, string url, ICssNode node, CancellationToken ct) { Enqueue(document, url, null, GetExcerpt(node), ct); }
public void RemoveChild(ICssNode child) { Teardown(child); _children.Remove(child); }
/// <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>()); }
public void InsertChild(Int32 index, ICssNode child) { Setup(child); _children.Insert(index, child); }
public void AppendChild(ICssNode child) { Setup(child); _children.Add(child); }
public CssAnalyseArgs(Document document, CssAnalyserTargets target, ICssNode node) : this(document, target, node, null) { }