예제 #1
0
파일: TreeBuilder.cs 프로젝트: gjunge/nLess
        /// <summary>
        /// TODO: Added quick fix for multipule mixins, but need to add mixins with variables which will changes things a bit
        /// </summary>
        /// <param name="node"></param>
        /// <param name="elementBlock"></param>
        //        private void OldMixin(PegNode node, Element element)
        //        {
        //            var root = element.GetRoot();
        //            foreach (var el in Selectors(node.child_, els => els))
        //                root = root.Descend(el.Selector, el);
        //            if (root.Children != null) element.Children.AddRange(root.Children);
        //        }
        private void Mixin(PegNode node, ElementBlock elementBlock)
        {
            var root = elementBlock.GetRoot();
            var rules = new List<INode>();
            foreach (var mixins in node.AsEnumerable())
            {
                var selectors = Selectors(mixins, els => els).ToList();
                if (selectors.Count() > 1)
                {
                    foreach (var el in selectors)
                        root = root.Descend(el.Selector, el);
                    if (root.Children != null)
                        rules.AddRange(root.Children);
                }
                else
                {
                    var el = selectors.First();
                    foreach (var mixinElement in root.Nearests(el.Name))
                    {
                        if (mixinElement.Children == null)
                            continue;

                        var children = GetMixinChildren(elementBlock, el.Variables, mixinElement.Children);

                        rules.AddRange(children);

                        el.Parent = elementBlock;
                    }
                }

            }

            elementBlock.Children.AddRange(rules);
        }
예제 #2
0
        /// <summary>
        /// TODO: Added quick fix for multipule mixins, but need to add mixins with variables which will changes things a bit
        /// </summary>
        /// <param name="node"></param>
        /// <param name="elementBlock"></param>
        //        private void OldMixin(LessPegNode node, Element element)
        //        {
        //            var root = element.GetRoot();
        //            foreach (var el in Selectors(node.Child, els => els))
        //                root = root.Descend(el.Selector, el);
        //            if (root.Children != null) element.Children.AddRange(root.Children);
        //        }
        private void Mixin(LessPegNode node, ElementBlock elementBlock)
        {
            var root = elementBlock.GetRoot();
            var rules = new List<INode>();
            foreach (var mixins in node.Children())
            {
                var selectors = Selectors(mixins, els => els).ToList();
                if (selectors.Count() > 1)
                {
                    foreach (var el in selectors)
                        root = root.Descend(el.Selector, el);

                    var last = selectors.Last();

                    var children = GetMixinChildren(elementBlock, last, root);

                    if(children != null)
                        rules.AddRange(children);
                }
                else
                {
                    var el = selectors.First();
                    foreach (var mixinElement in root.Nearests(el.Name))
                    {
                        var children = GetMixinChildren(elementBlock, el, mixinElement);

                        if(children != null)
                            rules.AddRange(children);
                    }
                }

            }

            elementBlock.Children.AddRange(rules);
        }