public override Node Evaluate(Env env) { NodeList <Element> evaldElements = new NodeList <Element>(); foreach (Element element in Elements) { if (element.NodeValue is Extend) { if (env.MediaPath.Any()) { env.MediaPath.Peek().AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)), env); } else //Global extend { env.AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)), env); } } else { evaldElements.Add(element.Evaluate(env) as Element); } } return(new Selector(evaldElements).ReducedFrom <Selector>(this)); }
/// <summary> /// Evaluate Rules. Must only be run on a copy of the ruleset otherwise it will /// overwrite defintions that might be required later.. /// </summary> protected void EvaluateRules(Env env) { env.Frames.Push(this); for (var i = 0; i < Selectors.Count; i++) { Selectors[i] = Selectors[i].Evaluate(env) as Selector; } int mediaBlocks = env.MediaBlocks.Count; NodeHelper.ExpandNodes <MixinCall>(env, Rules); foreach (var r in Rules.OfType <Extend>().ToArray()) { env.AddExtension(this.Selectors.First(), r.Selectors); Rules.Remove(r); } for (var i = 0; i < Rules.Count; i++) { Rules[i] = Rules[i].Evaluate(env); } // if media blocks are inside this ruleset we have to "catch" the bubbling and // make sure they get this rulesets selectors for (var j = mediaBlocks; j < env.MediaBlocks.Count; j++) { env.MediaBlocks[j].BubbleSelectors(Selectors); } env.Frames.Pop(); }
/// <summary> /// Evaluate Rules. Must only be run on a copy of the ruleset otherwise it will /// overwrite defintions that might be required later.. /// </summary> protected void EvaluateRules(Env env) { env.Frames.Push(this); for (var i = 0; i < Selectors.Count; i++) { var evaluatedSelector = Selectors[i].Evaluate(env); var expandedSelectors = evaluatedSelector as IEnumerable <Selector>; if (expandedSelectors != null) { Selectors.RemoveAt(i); Selectors.InsertRange(i, expandedSelectors); } else { Selectors[i] = evaluatedSelector as Selector; } } int mediaBlocks = env.MediaBlocks.Count; NodeHelper.ExpandNodes <Import>(env, Rules); NodeHelper.ExpandNodes <MixinCall>(env, Rules); foreach (var r in Rules.OfType <Extend>().ToArray()) { foreach (var s in this.Selectors) { //If we're in a media block, then extenders can only apply to that media block if (env.MediaPath.Any()) { env.MediaPath.Peek().AddExtension(s, (Extend)r.Evaluate(env), env); } else //Global extend { env.AddExtension(s, (Extend)r.Evaluate(env), env); } } } for (var i = 0; i < Rules.Count; i++) { Rules[i] = Rules[i].Evaluate(env); } // if media blocks are inside this ruleset we have to "catch" the bubbling and // make sure they get this rulesets selectors for (var j = mediaBlocks; j < env.MediaBlocks.Count; j++) { env.MediaBlocks[j].BubbleSelectors(Selectors); } env.Frames.Pop(); }
public override Node Evaluate(Env env) { NodeList <Element> evaldElements = new NodeList <Element>(); foreach (Element element in Elements) { if (element.NodeValue is Extend) { if (env.MediaPath.Any()) { env.MediaPath.Peek().AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)), env); } else //Global extend { env.AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)), env); } } else { evaldElements.Add(element.Evaluate(env) as Element); } } var evaluatedSelector = new Selector(evaldElements).ReducedFrom <Selector>(this); if (evaluatedSelector.Elements.All(e => e.NodeValue == null)) { return(evaluatedSelector); } Parser.Tokenizer.SetupInput(evaluatedSelector.ToCSS(env), ""); var result = new NodeList <Selector>(); Selector selector; while (selector = Parsers.Selector(Parser)) { selector.IsReference = IsReference; result.Add(selector.Evaluate(env) as Selector); if (!Parser.Tokenizer.Match(',')) { break; } } return(result); }
public override Node Evaluate(Env env) { NodeList<Element> evaldElements = new NodeList<Element>(); foreach (Element element in Elements) { if (element.NodeValue is Extend) { env.AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)),env); } else { evaldElements.Add(element.Evaluate(env) as Element); } } return new Selector(evaldElements).ReducedFrom<Selector>(this); }
public override Node Evaluate(Env env) { NodeList <Element> evaldElements = new NodeList <Element>(); foreach (Element element in Elements) { if (element.NodeValue is Extend) { env.AddExtension(this, ((Extend)element.NodeValue).Selectors); } else { evaldElements.Add(element.Evaluate(env) as Element); } } return(new Selector(evaldElements).ReducedFrom <Selector>(this)); }
public override Node Evaluate(Env env) { NodeList<Element> evaldElements = new NodeList<Element>(); foreach (Element element in Elements) { if (element.NodeValue is Extend) { if (env.MediaPath.Any()) { env.MediaPath.Peek().AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)),env); } else //Global extend { env.AddExtension(this, (Extend)(((Extend)element.NodeValue).Evaluate(env)), env); } } else { evaldElements.Add(element.Evaluate(env) as Element); } } var evaluatedSelector = new Selector(evaldElements).ReducedFrom<Selector>(this); if (evaluatedSelector.Elements.All(e => e.NodeValue == null)) { return evaluatedSelector; } parser.Tokenizer.SetupInput(evaluatedSelector.ToCSS(env), ""); var result = new NodeList<Selector>(); Selector selector; while (selector = parsers.Selector(parser)) { selector.IsReference = IsReference; result.Add(selector.Evaluate(env) as Selector); if (!parser.Tokenizer.Match(',')) { break; } } return result; }