Beispiel #1
0
        private Import(Node path, Value features, ImportOptions option)
        {
            if (path == null)
                throw new ParserException("Imports do not allow expressions");

            OriginalPath = path;
            Features = features;
            ImportOptions = option;
        }
Beispiel #2
0
        private Import(string path, IImporter importer, Value features)
        {
            if (path == null)
                throw new ParserException("Imports do not allow expressions");

            Importer = importer;
            Path = path;
            Features = features;

            ImportAction = Importer.Import(this); // it is assumed to be css if it cannot be found as less
        }
Beispiel #3
0
        public override Node Evaluate(Env env)
        {
            Node returnNode = null;
            Value value;

            if (Values.Count == 1 && string.IsNullOrEmpty(Important))
                returnNode = Values[0].Evaluate(env);
            else
            {
                returnNode = value = new Value(Values.Select(n => n.Evaluate(env)), Important);
                value.PreImportantComments = this.PreImportantComments;
            }

            return returnNode.ReducedFrom<Node>(this);
        }
Beispiel #4
0
        private Import(string path, IImporter importer, Value features)
        {
            Importer = importer;
            Path = path;
            Features = features;

            if (path.EndsWith(".css"))
            {
                Css = true;
            } else
            {
                Css = !Importer.Import(this); // it is assumed to be css if it cannot be found as less

                if (Css && path.EndsWith(".less"))
                {
                    throw new FileNotFoundException("You are importing a file ending in .less that cannot be found.", path);
                }
            }
        }
 public Media Media(NodeList rules, Value features, NodeLocation location)
 {
   return new Media(features, rules) { Location = location };
 }
 public Import Import(Quoted path, Value features, ImportOptions option, NodeLocation location)
 {
   return new Import(path, features, option) { Location = location };
 }
Beispiel #7
0
        /// <summary>
        ///  Evaluate when you have a media inside another media
        /// </summary>
        protected Node EvalNested(Env env, Node features, Ruleset ruleset)
        {
            var path = new NodeList<Media>(env.MediaPath.ToList());
            path.Add(this);

            NodeList<NodeList> derivedPath = new NodeList<NodeList>();

            // Extract the media-query conditions separated with `,` (OR).
            for (int i = 0; i < path.Count; i++)
            {
                Node pathComponent;
                Value value = path[i].Features as Value;
                if (value != null)
                {
                    pathComponent = value.Values;
                }
                else
                {
                    pathComponent = path[i].Features;
                }

                derivedPath.Add((pathComponent as NodeList) ?? new NodeList() { pathComponent });
            }

            // Trace all permutations to generate the resulting media-query.
            //
            // (a, b and c) with nested (d, e) ->
            //    a and d
            //    a and e
            //    b and c and d
            //    b and c and e

            NodeList<NodeList> pathWithAnds = new NodeList<NodeList>();

            foreach (NodeList node in derivedPath)
            {
                pathWithAnds.Add(node);
                pathWithAnds.Add(new NodeList() { new TextNode("and") });
            }

            pathWithAnds.RemoveAt(pathWithAnds.Count - 1);

            Features = new Value(Permute(pathWithAnds), null);

            // Fake a tree-node that doesn't output anything.
            return new Ruleset(new NodeList<Selector>(), new NodeList());
        }
Beispiel #8
0
 public Import(Url path, Value features, ImportOptions option)
     : this((Node)path, features, option)
 {
     OriginalPath = path;
     Path = path.GetUnadjustedUrl();
 }
Beispiel #9
0
 public Import(Quoted path, Value features, ImportOptions option)
     : this((Node)path, features, option)
 {
     OriginalPath = path;
 }
Beispiel #10
0
 public Import(Url path, IImporter importer, Value features)
     : this(path.GetUnadjustedUrl(), importer, features)
 {
     OriginalPath = path;
 }
Beispiel #11
0
 public Import(Quoted path, IImporter importer, Value features)
     : this(path.Value, importer, features)
 {
     OriginalPath = path;
 }
Beispiel #12
0
 public Import(Quoted path, IImporter importer, Value features, bool isOnce)
     : this(path.Value, importer, features, isOnce)
 {
     OriginalPath = path;
 }
Beispiel #13
0
        public override Node Evaluate(Env env)
        {
            var found = false;
            var closures = env.FindRulesets(Selector);

            if(closures == null)
                throw new ParsingException(Selector.ToCSS(env).Trim() + " is undefined", Index);

            env.Rule = this;

            var rules = new NodeList();

            if (PreComments)
                rules.AddRange(PreComments);

            foreach (var closure in closures)
            {
                var ruleset = closure.Ruleset;

                var matchType = ruleset.MatchArguments(Arguments, env);

                if (matchType == MixinMatch.ArgumentMismatch)
                    continue;

                found = true;

                if (matchType == MixinMatch.GuardFail)
                    continue;

                if (ruleset is MixinDefinition)
                {
                    try
                    {
                        var mixin = ruleset as MixinDefinition;
                        rules.AddRange(mixin.Evaluate(Arguments, env, closure.Context).Rules);
                    }
                    catch (ParsingException e)
                    {
                        throw new ParsingException(e.Message, e.Index, Index);
                    }
                }
                else
                {
                    if (ruleset.Rules != null)
                    {
                        var nodes = new NodeList(ruleset.Rules);
                        NodeHelper.ExpandNodes<MixinCall>(env, nodes);

                        rules.AddRange(nodes);
                    }
                }
            }
            if (PostComments)
                rules.AddRange(PostComments);

            env.Rule = null;

            if (!found)
            {
                var message = String.Format("No matching definition was found for `{0}({1})`",
                                            Selector.ToCSS(env).Trim(),
                                            StringExtensions.JoinStrings(Arguments.Select(a => a.Value.ToCSS(env)), ", "));
                throw new ParsingException(message, Index);
            }

            if (Important)
            {
                var importantRules = new NodeList();

                foreach (Node node in rules)
                {
                    Rule r = node as Rule;
                    if (r != null)
                    {
                        var valueNode = r.Value;
                        var value = valueNode as Value;
                        if (value != null)
                        {
                            value = new Value(value.Values, "!important").ReducedFrom<Value>(value);
                        }
                        else
                        {
                            value = new Value(new NodeList() { valueNode }, "!important");
                        }

                        importantRules.Add((new Rule(r.Name, value)).ReducedFrom<Rule>(r));
                    }
                    else
                    {
                        importantRules.Add(node);
                    }
                }

                return importantRules;
            }
            else
            {
                return rules;
            }
        }