Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some better code documentation.

  • Loading branch information...
commit 22ed3f30ccfff6dea2d3a6dfed6c80b9ef7c8a76 1 parent e8de202
@chriseppstein authored
Showing with 21 additions and 5 deletions.
  1. +21 −5 lib/sass/tree/node.rb
View
26 lib/sass/tree/node.rb
@@ -264,22 +264,26 @@ def _around_dump
# tree to rewrite itself as an array of nodes that should replace it
# in its parent's child array.
#
- # This step is used to bubble nested nodes to the top level
- # in cases where CSS does not understand them in a nested context.
+ # This step is used to bubble nodes up the tree and to merge
+ # nodes with their parent in cases where CSS does not understand them
+ # in a nested context.
#
- # \{#restructure} shouldn't be overridden directly;
- # instead, override \{#\_restructure} or \{#restructure!}.
+ # \{#restructure} generally shouldn't be overridden directly;
+ # instead, override \{#bubbles?}, \{#merges?}.
#
# @return [Array<Tree::Node>] The resulting tree of static nodes
# @see Sass::Tree
# @see Sass::Tree::RootNode#restructure
def restructure
+ # First we restructure the children and replace them with their returned array of nodes
new_children = children.map {|c| c.restructure}.flatten
unless new_children.any?{|c| c.bubbles?(self) || c.merges?(self)}
- # optimization path?
+ # No more restructuring to do just return.
self.children = new_children
return [self]
end
+ # break the children into sets of nodes separated by nodes that need to be restructured.
+ # The parent node will be duplicated/replaced for each set.
child_groups = [[]]
new_children.each do |child|
if child.bubbles?(self) || child.merges?(self)
@@ -289,7 +293,11 @@ def restructure
child_groups.last << child
end
end
+ # The above approach can generate empty sets -- dump them
child_groups.reject!{|group| group.empty?}
+
+ # perform the restructuring by bubbling and merging those
+ # nodes which require it.
replacements = child_groups.map do |children|
node = self.dup
if children.size == 1 && children.first.bubbles?(self)
@@ -319,6 +327,14 @@ def merges?(parent)
false
end
+ # Merges this node with another, returning a new node
+ #
+ # Any node that returns true for \{#merges?} should
+ # implement this method.
+ def merge_with(parent)
+ Sass::Util.abstract(self)
+ end
+
protected
# Computes the CSS corresponding to this particular Sass node.
Please sign in to comment.
Something went wrong with that request. Please try again.