Class: Sass::Tree::RuleNode

Inherits:
Node
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb

Overview

A static node representing a CSS rule.

See Also:

Constant Summary

Instance Attribute Summary (collapse)

Attributes inherited from Node

#children, #filename, #has_children, #line, #options, #source_range

Instance Method Summary (collapse)

Methods inherited from Node

#<<, #balance, #bubbles?, #css, #css_with_sourcemap, #deep_copy, #each, #inspect, #style, #to_sass, #to_scss

Constructor Details

- (RuleNode) initialize(rule, selector_source_range = nil)

Returns a new instance of RuleNode

Parameters:



66
67
68
69
70
71
72
73
74
75
76
77
78
# File '/home/nweiz/code/sass-site/.sass/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

- (Boolean) group_end

Whether or not this rule is the last rule in a nested group. This is only set in a CSS tree.

Returns:

  • (Boolean)


54
55
56
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 54

def group_end
  @group_end
end

- (Selector::CommaSequence) parsed_rules

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 '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 25

def parsed_rules
  @parsed_rules
end

- (Selector::CommaSequence) resolved_rules

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 '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 32

def resolved_rules
  @resolved_rules
end

- (Array<String, Sass::Script::Tree::Node>) rule

The CSS selector for this rule, interspersed with Script::Tree::Nodes representing #{}-interpolation. Any adjacent strings will be merged together.

Returns:



17
18
19
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 17

def rule
  @rule
end

- (Sass::Source::Range) selector_source_range

The entire selector source range for this rule.

Returns:



48
49
50
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 48

def selector_source_range
  @selector_source_range
end

- (String) stack_trace

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.

Returns:

  • (String)


61
62
63
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 61

def stack_trace
  @stack_trace
end

- (Integer) tabs

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

Returns:

  • (Integer)


44
45
46
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 44

def tabs
  @tabs
end

Instance Method Details

- (Boolean) ==(other)

Compares the contents of two rules.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)

    Whether or not this node and the other object are the same



97
98
99
# File '/home/nweiz/code/sass-site/.sass/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.

Parameters:



104
105
106
107
108
# File '/home/nweiz/code/sass-site/.sass/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

- (Boolean) continued?

Returns Whether or not this rule is continued on the next line

Returns:

  • (Boolean)

    Whether or not this rule is continued on the next line



111
112
113
114
# File '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 111

def continued?
  last = @rule.last
  last.is_a?(String) && last[-1] == ?,
end

- ({#to_s => #to_s}) debug_info

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.

Returns:

  • ({#to_s => #to_s})


122
123
124
125
126
# File '/home/nweiz/code/sass-site/.sass/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 '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 87

def filename=(filename)
  @parsed_rules.filename = filename if @parsed_rules
  super
end

- (Boolean) invisible?

A rule node is invisible if it has only placeholder selectors.

Returns:

  • (Boolean)


129
130
131
# File '/home/nweiz/code/sass-site/.sass/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 '/home/nweiz/code/sass-site/.sass/lib/sass/tree/rule_node.rb', line 81

def line=(line)
  @parsed_rules.line = line if @parsed_rules
  super
end