Class: Sass::Tree::RuleNode
Overview
A static node representing a CSS rule.
Constant Summary collapse
- PARENT =
The character used to include the parent selector
'&'
Instance Attribute Summary collapse
-
#group_end ⇒ Boolean
Whether or not this rule is the last rule in a nested group.
-
#parsed_rules ⇒ Selector::CommaSequence
The CSS selector for this rule, without any unresolved interpolation but with parent references still intact.
-
#resolved_rules ⇒ Selector::CommaSequence
The CSS selector for this rule, without any unresolved interpolation or parent references.
-
#rule ⇒ Array<String, Sass::Script::Tree::Node>
The CSS selector for this rule, interspersed with Script::Tree::Nodes representing
#{}
-interpolation. -
#selector_source_range ⇒ Sass::Source::Range
The entire selector source range for this rule.
-
#stack_trace ⇒ String
The stack trace.
-
#tabs ⇒ Integer
How deep this rule is indented relative to a base-level rule.
Attributes inherited from Node
#children, #filename, #has_children, #line, #options, #source_range
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the contents of two rules.
-
#add_rules(node)
Adds another RuleNode's rules to this one's.
-
#continued? ⇒ Boolean
Whether or not this rule is continued on the next line.
-
#debug_info ⇒ {#to_s => #to_s}
A hash that will be associated with this rule in the CSS document if the
:debug_info
option is enabled. -
#filename=(filename)
If we've precached the parsed selector, set the filename on it, too.
-
#initialize(rule, selector_source_range = nil) ⇒ RuleNode
constructor
A new instance of RuleNode.
-
#invisible? ⇒ Boolean
A rule node is invisible if it has only placeholder selectors.
-
#line=(line)
If we've precached the parsed selector, set the line on it, too.
Methods inherited from Node
#<<, #balance, #bubbles?, #css, #css_with_sourcemap, #deep_copy, #each, #inspect, #style, #to_sass, #to_scss
Constructor Details
#initialize(rule, selector_source_range = nil) ⇒ RuleNode
Returns a new instance of RuleNode.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sass/tree/rule_node.rb', line 66
def initialize(rule, selector_source_range = nil)
if rule.is_a?(Sass::Selector::CommaSequence)
@rule = [rule.to_s]
@parsed_rules = rule
else
merged = Sass::Util.merge_adjacent_strings(rule)
@rule = Sass::Util.strip_string_array(merged)
try_to_parse_non_interpolated_rules
end
@selector_source_range = selector_source_range
@tabs = 0
super()
end
|
Instance Attribute Details
#group_end ⇒ Boolean
Whether or not this rule is the last rule in a nested group. This is only set in a CSS tree.
54 55 56 |
# File 'lib/sass/tree/rule_node.rb', line 54
def group_end
@group_end
end
|
#parsed_rules ⇒ Selector::CommaSequence
The CSS selector for this rule, without any unresolved interpolation but with parent references still intact. It's only guaranteed to be set once Visitors::Perform has been run, but it may be set before then for optimization reasons.
25 26 27 |
# File 'lib/sass/tree/rule_node.rb', line 25
def parsed_rules
@parsed_rules
end
|
#resolved_rules ⇒ Selector::CommaSequence
The CSS selector for this rule, without any unresolved interpolation or parent references. It's only set once Visitors::Perform has been run.
32 33 34 |
# File 'lib/sass/tree/rule_node.rb', line 32
def resolved_rules
@resolved_rules
end
|
#rule ⇒ Array<String, Sass::Script::Tree::Node>
The CSS selector for this rule,
interspersed with Script::Tree::Nodes
representing #{}
-interpolation.
Any adjacent strings will be merged together.
17 18 19 |
# File 'lib/sass/tree/rule_node.rb', line 17
def rule
@rule
end
|
#selector_source_range ⇒ Sass::Source::Range
The entire selector source range for this rule.
48 49 50 |
# File 'lib/sass/tree/rule_node.rb', line 48
def selector_source_range
@selector_source_range
end
|
#stack_trace ⇒ String
The stack trace. This is only readable in a CSS tree as it is written during the perform step and only when the :trace_selectors option is set.
61 62 63 |
# File 'lib/sass/tree/rule_node.rb', line 61
def stack_trace
@stack_trace
end
|
#tabs ⇒ Integer
How deep this rule is indented relative to a base-level rule. This is only greater than 0 in the case that:
- This node is in a CSS tree
- The style is :nested
- This is a child rule of another rule
- The parent rule has properties, and thus will be rendered
44 45 46 |
# File 'lib/sass/tree/rule_node.rb', line 44
def tabs
@tabs
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares the contents of two rules.
97 98 99 |
# File 'lib/sass/tree/rule_node.rb', line 97
def ==(other)
self.class == other.class && rule == other.rule && super
end
|
#add_rules(node)
Adds another Sass::Tree::RuleNode's rules to this one's.
104 105 106 107 108 |
# File 'lib/sass/tree/rule_node.rb', line 104
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
|
#continued? ⇒ Boolean
Returns Whether or not this rule is continued on the next line.
111 112 113 114 |
# File 'lib/sass/tree/rule_node.rb', line 111
def continued?
last = @rule.last
last.is_a?(String) && last[-1] == ?,
end
|
#debug_info ⇒ {#to_s => #to_s}
A hash that will be associated with this rule in the CSS document
if the :debug_info
option is enabled.
This data is used by e.g. the FireSass Firebug
extension.
122 123 124 125 126 |
# File 'lib/sass/tree/rule_node.rb', line 122
def debug_info
{:filename => filename &&
("file://" + URI::DEFAULT_PARSER.escape(File.expand_path(filename))),
:line => line}
end
|
#filename=(filename)
If we've precached the parsed selector, set the filename on it, too.
87 88 89 90 |
# File 'lib/sass/tree/rule_node.rb', line 87
def filename=(filename)
@parsed_rules.filename = filename if @parsed_rules
super
end
|
#invisible? ⇒ Boolean
A rule node is invisible if it has only placeholder selectors.
129 130 131 |
# File 'lib/sass/tree/rule_node.rb', line 129
def invisible?
resolved_rules.members.all? {|seq| seq.invisible?}
end
|
#line=(line)
If we've precached the parsed selector, set the line on it, too.
81 82 83 84 |
# File 'lib/sass/tree/rule_node.rb', line 81
def line=(line)
@parsed_rules.line = line if @parsed_rules
super
end
|