lib/sass/tree/rule_node.rb in sass-3.1.0.alpha.214 vs lib/sass/tree/rule_node.rb in sass-3.1.0.alpha.216
- old
+ new
@@ -54,13 +54,26 @@
# The CSS rule. See \{#rule}
def initialize(rule)
merged = Sass::Util.merge_adjacent_strings(rule)
@rule = Sass::Util.strip_string_array(merged)
@tabs = 0
+ try_to_parse_non_interpolated_rules
super()
end
+ # If we've precached the parsed selector, set the line on it, too.
+ def line=(line)
+ @parsed_rules.line = line if @parsed_rules
+ super
+ end
+
+ # If we've precached the parsed selector, set the filename on it, too.
+ def filename=(filename)
+ @parsed_rules.filename = filename if @parsed_rules
+ super
+ end
+
# Compares the contents of two rules.
#
# @param other [Object] The object to compare with
# @return [Boolean] Whether or not this node and the other object
# are the same
@@ -72,10 +85,11 @@
#
# @param node [RuleNode] The other node
def add_rules(node)
@rule = Sass::Util.strip_string_array(
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
+ try_to_parse_non_interpolated_rules
end
# @return [Boolean] Whether or not this rule is continued on the next line
def continued?
last = @rule.last
@@ -97,8 +111,19 @@
#
# @return [{#to_s => #to_s}]
def debug_info
{:filename => filename && ("file://" + URI.escape(File.expand_path(filename))),
:line => self.line}
+ end
+
+ private
+
+ def try_to_parse_non_interpolated_rules
+ if @rule.all? {|t| t.kind_of?(String)}
+ # We don't use real filename/line info because we don't have it yet.
+ # When we get it, we'll set it on the parsed rules if possible.
+ parser = Sass::SCSS::StaticParser.new(@rule.join.strip, 1)
+ @parsed_rules = parser.parse_selector('') rescue nil
+ end
end
end
end