public bool Prune(AST.Options options) { if (options.HasFlag(AST.Options.DontTrackContext)) { Context = null; } return(PruneAll(options) || PruneEmpty(options)); }
private void PruneRawText(AST.Options options) { if (options.HasFlag(AST.Options.PruneRawTexts)) { Raw = null; foreach (var attr in _attributes.Values) { attr.Raw = null; } } }
private void PruneContext(AST.Options options) { if (options.HasFlag(AST.Options.DontTrackContext)) { foreach (var attribute in Attributes.Values.SelectMany(x => x.Nodes)) { attribute.Prune(AST.Options.DontTrackContext); } Context = null; } }
public bool PruneEmpty(AST.Options options) { if (!options.HasFlag(AST.Options.TrimEmptyTextNodes)) { return(false); } if (Value.Trim().Length == 0) { return(true); } return(false); }
public override bool Prune(AST.Options options) { if (options.HasFlag(AST.Options.DontTrackContext)) { Context = null; } if (options.HasFlag(AST.Options.PruneTemplates)) { return(true); } base.Prune(options); return(false); }
private void PruneNaturalLanguage(AST.Options options) { if (options.HasFlag(AST.Options.NaturalLanguage)) { Name = LanguageHelper.DashProperty(Name); Group = LanguageHelper.DashProperty(Name); var mapped = new Dictionary <string, TagAttributeNode>(); foreach (var pair in _attributes) { mapped[LanguageHelper.DashProperty(pair.Key)] = pair.Value; } _attributes = mapped; } }
public bool Prune(AST.Options options) { if (options.HasFlag(AST.Options.DontTrackContext)) { Context = null; } if (options.HasFlag(AST.Options.FlatExpression)) { _children.Clear(); } foreach (var expressionNode in _children) { expressionNode.Prune(options); } return(false); }
public virtual bool Prune(AST.Options options) { if (options.HasFlag(AST.Options.InlineTemplates)) { var expanded = new List <INode>(); foreach (var child in _children) { var templateChild = child as TemplateNode; if (templateChild != null) { expanded.AddRange(templateChild.Nodes); } else { expanded.Add(child); } } _children = expanded; } _children = _children.Where(c => !c.Prune(options)).ToList(); if (options.HasFlag(AST.Options.ExcludeTemplateContainers)) { var expanded = new List <INode>(); foreach (var child in _children) { var containerChild = child as TemplateContainerNode; if (containerChild != null) { expanded.AddRange(containerChild.Nodes); } else { expanded.Add(child); } } _children = expanded; } return(_children.Count == 0); }
public override bool Prune(AST.Options options) { PruneRawText(options); PruneNaturalLanguage(options); PruneContext(options); //Empty tag before prune. Not wise to remove if (_attributes.Count == 0 && _children.Count == 0) { return(false); } var prune = base.Prune(options); foreach (var attribute in _attributes.Keys.ToList()) { var c = _attributes[attribute].Nodes.All(a => a.Prune(options)); if (c && !options.HasFlag(AST.Options.IncludeUnspecifiedAttributes)) { _attributes.Remove(attribute); } } return(prune && _attributes.Count == 0); }
private bool PruneAll(AST.Options options) { return(options.HasFlag(AST.Options.TrimAllTextNodes)); }