Пример #1
0
 public DocumentAtRule(IEnumerable <Expression> specifiers, RuleBlock block)
 {
     this.block      = block;
     this.specifiers = specifiers.ToList();
 }
Пример #2
0
 public PageAtRule(Selector additionalSelector, RuleBlock block)
 {
     this.additionalSelector = additionalSelector;
     this.block = block;
 }
Пример #3
0
        protected override IEnumerable <LessNode> EvaluateCore(EvaluationContext context)
        {
            if (Guard?.SatisfiedBy(context) == false)
            {
                yield break;
            }

            var evaluatedSelectors = Selectors.Inherit(context.CurrentScope.Selectors).EvaluateSingle <SelectorList>(context);

            evaluatedSelectors.AddExtenders(context);

            using (context.EnterScope(evaluatedSelectors)) {
                (var rules, var others) = Block.Evaluate(context).Split <Rule, Statement>();

                if (rules.Count > 0)
                {
                    var ruleLookup = new HashSet <Rule>();

                    for (var i = rules.Count - 1; i >= 0; i--)
                    {
                        var r = rules[i];
                        if (ruleLookup.Contains(r))
                        {
                            rules.RemoveAt(i);
                        }
                        else
                        {
                            ruleLookup.Add(r);
                        }
                    }

                    var evaluatedBlock = new RuleBlock(rules);

                    var evaluatedRuleset =
                        new Ruleset(evaluatedSelectors, evaluatedBlock);

                    yield return(evaluatedRuleset);
                }

                foreach (var statement in others)
                {
                    if (statement is Ruleset rs)
                    {
                        context.CurrentScope.Parent.DeclareRuleset(rs);

                        yield return(rs);
                    }
                    else if (statement is MediaBlock media)
                    {
                        yield return(media.Bubble(context));
                    }
                    else if (statement is Stylesheet || statement is ImportStatement)
                    {
                        yield return(statement);
                    }
                    else
                    {
                        throw new EvaluationException($"Unexpected statement type after evaluating rule block: {statement.GetType()}");
                    }
                }
            }
        }
Пример #4
0
 public Ruleset(SelectorList selectors, RuleBlock block)
 {
     this.Selectors = selectors;
     Guard          = null;
     this.Block     = block;
 }
Пример #5
0
 public Ruleset(SelectorList selectors, RulesetGuard guard, RuleBlock block)
 {
     this.Selectors = selectors;
     Guard          = guard;
     this.Block     = block;
 }
Пример #6
0
 public GenericAtRule(Identifier identifier, Expression value, RuleBlock block)
 {
     this.identifier = identifier;
     this.value      = value;
     this.block      = block;
 }