Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make @media bubbling work.

  • Loading branch information...
commit 81a419b7c36b6a9c967cf7d7b8f7fd62325cce87 1 parent 6f1109b
@nex3 nex3 authored
Showing with 33 additions and 3 deletions.
  1. +29 −0 lib/sass/tree/media_node.rb
  2. +4 −3 lib/sass/tree/rule_node.rb
View
29 lib/sass/tree/media_node.rb
@@ -23,5 +23,34 @@ def initialize(query)
@tabs = 0
super("@media #{query}")
end
+
+ # Pass on the parent if it's a RuleNode.
+ #
+ # @see Node#cssize
+ def cssize(extends, parent = nil)
+ _cssize(extends, (parent if [MediaNode, RuleNode].include?(parent.class)))
+ rescue Sass::SyntaxError => e
+ e.modify_backtrace(:filename => filename, :line => line)
+ raise e
+ end
+
+ protected
+
+ # If we're passed a parent, bubble it down.
+ #
+ # @see Node#cssize
+ def cssize!(extends, parent)
+ return super unless parent
+ new_rule = parent.dup
+ new_rule.children = self.children
+ self.children = Array(new_rule.cssize(extends, self))
+ end
+
+ # @see Node#to_s
+ def _to_s(tabs)
+ str = super(tabs + self.tabs)
+ str.gsub!(/\n\Z/, '') unless style == :compressed || group_end
+ str
+ end
end
end
View
7 lib/sass/tree/rule_node.rb
@@ -197,8 +197,8 @@ def perform!(environment)
# or nil if the parent isn't a {RuleNode}
def _cssize(extends, parent)
node = super
- rules = node.children.grep(RuleNode)
- props = node.children.reject {|c| c.is_a?(RuleNode) || c.invisible?}
+ rules = node.children.select {|c| c.is_a?(RuleNode) || c.is_a?(MediaNode)}
+ props = node.children.reject {|c| c.is_a?(RuleNode) || c.is_a?(MediaNode) || c.invisible?}
unless props.empty?
node.children = props
@@ -220,7 +220,8 @@ def _cssize(extends, parent)
# or nil if the parent isn't a {RuleNode}
# @raise [Sass::SyntaxError] if the rule has no parents but uses `&`
def cssize!(extends, parent)
- self.resolved_rules = @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
+ # It's possible for resolved_rules to be set if we've duplicated this node during @media bubbling
+ self.resolved_rules ||= @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
super
end
Please sign in to comment.
Something went wrong with that request. Please try again.