Beispiel #1
0
        public override Node Evaluate(Env env)
        {
            OriginalPath = OriginalPath.Evaluate(env);
            var quoted = OriginalPath as Quoted;
            if (quoted != null)
            {
                Path = quoted.Value;
            }

            ImportAction action = GetImportAction(env.Parser.Importer);
            if (action == Importers.ImportAction.ImportNothing)
            {
                return new NodeList().ReducedFrom<NodeList>(this);
            }

            Node features = null;

            if (Features)
                features = Features.Evaluate(env);

            if (action == ImportAction.LeaveImport)
                return new Import(OriginalPath, features);

            if (action == ImportAction.ImportCss)
            {
                var importCss = new Import(OriginalPath, null) { _importAction = ImportAction.ImportCss, InnerContent = InnerContent };
                if (features)
                    return new Media(features, new NodeList() { importCss });
                return importCss;
            }

            using (env.Parser.Importer.BeginScope(this))
            {
                if (IsReference || IsOptionSet(ImportOptions, ImportOptions.Reference))
                {
                    // Walk the parse tree and mark all nodes as references.
                    IsReference = true;

                    Accept(referenceVisitor);
                }
                NodeHelper.RecursiveExpandNodes<Import>(env, InnerRoot.Rules);
            }

            var rulesList = new NodeList(InnerRoot.Rules).ReducedFrom<NodeList>(this);
            if (features)
            {
                return new Media(features, rulesList);
            }

            return rulesList;
        }
Beispiel #2
0
        public override Node Evaluate(Env env)
        {
            OriginalPath = OriginalPath.Evaluate(env);
            var quoted = OriginalPath as Quoted;

            if (quoted != null)
            {
                Path = quoted.Value;
            }

            ImportAction action = GetImportAction(env.Parser.Importer);

            if (action == Importers.ImportAction.ImportNothing)
            {
                return(new NodeList().ReducedFrom <NodeList>(this));
            }

            Node features = null;

            if (Features)
            {
                features = Features.Evaluate(env);
            }

            if (action == ImportAction.LeaveImport)
            {
                return(new Import(OriginalPath, features));
            }

            if (action == ImportAction.ImportCss)
            {
                var importCss = new Import(OriginalPath, null)
                {
                    _importAction = ImportAction.ImportCss, InnerContent = InnerContent
                };
                if (features)
                {
                    return(new Media(features, new NodeList()
                    {
                        importCss
                    }));
                }
                return(importCss);
            }

            using (env.Parser.Importer.BeginScope(this))
            {
                if (IsReference || IsOptionSet(ImportOptions, ImportOptions.Reference))
                {
                    // Walk the parse tree and mark all nodes as references.
                    IsReference = true;

                    Accept(referenceVisitor);
                }
                NodeHelper.RecursiveExpandNodes <Import>(env, InnerRoot);
            }

            var rulesList = new NodeList(InnerRoot.Rules).ReducedFrom <NodeList>(this);

            if (features)
            {
                return(new Media(features, rulesList));
            }

            return(rulesList);
        }
Beispiel #3
0
        public override Node Evaluate(Env env)
        {
            Node features = null;

            if (Features)
                features = Features.Evaluate(env);

            if (ImportAction == ImportAction.LeaveImport)
                return new Import(OriginalPath, features);

            if (ImportAction == ImportAction.ImportCss)
            {
                var importCss = new Import(OriginalPath, null) { ImportAction = ImportAction.ImportCss, InnerContent = InnerContent };
                if (features)
                    return new Media(features, new NodeList() { importCss });
                return importCss;
            }

            NodeHelper.ExpandNodes<Import>(env, InnerRoot.Rules);

            var rulesList = new NodeList(InnerRoot.Rules).ReducedFrom<NodeList>(this);

            if (features)
            {
                return new Media(features, rulesList);
            }

            return rulesList;
        }
Beispiel #4
0
        public override Node Evaluate(Env env)
        {
            OriginalPath = OriginalPath.Evaluate(env);
            var quoted = OriginalPath as Quoted;
            if (quoted != null)
            {
                Path = quoted.Value;
            }

            ImportAction action = GetImportAction(env.Parser.Importer);
            if (action == Importers.ImportAction.ImportNothing)
            {
                return new NodeList().ReducedFrom<NodeList>(this);
            }

            Node features = null;

            if (Features)
                features = Features.Evaluate(env);

            if (action == ImportAction.LeaveImport)
                return new Import(OriginalPath, features);

            if (action == ImportAction.ImportCss)
            {
                var importCss = new Import(OriginalPath, null) { _importAction = ImportAction.ImportCss, InnerContent = InnerContent };
                if (features)
                    return new Media(features, new NodeList() { importCss });
                return importCss;
            }

            using (env.Parser.Importer.BeginScope(this))
            {
                if (IsReference || IsOptionSet(ImportOptions, ImportOptions.Reference))
                {
                    // Walk the parse tree and mark all nodes as references.
                    IsReference = true;

                    IVisitor referenceImporter = null;
                    referenceImporter = DelegateVisitor.For<Node>(node => {
                        var ruleset = node as Ruleset;
                        if (ruleset != null)
                        {
                            if (ruleset.Selectors != null)
                            {
                                ruleset.Selectors.Accept(referenceImporter);
                                ruleset.Selectors.IsReference = true;
                            }

                            if (ruleset.Rules != null)
                            {
                                ruleset.Rules.Accept(referenceImporter);
                                ruleset.Rules.IsReference = true;
                            }
                        }

                        var media = node as Media;
                        if (media != null)
                        {
                            media.Ruleset.Accept(referenceImporter);
                        }

                        var nodeList = node as NodeList;
                        if (nodeList != null)
                        {
                            nodeList.Accept(referenceImporter);
                        }
                        node.IsReference = true;

                        return node;
                    });
                    Accept(referenceImporter);
                }
                NodeHelper.ExpandNodes<Import>(env, InnerRoot.Rules);
            }

            var rulesList = new NodeList(InnerRoot.Rules).ReducedFrom<NodeList>(this);
            if (features)
            {
                return new Media(features, rulesList);
            }

            return rulesList;
        }