Class: Sass::Tree::RuleNode

Inherits:
Node
  • Object
show all
Defined in:
lib/sass/tree/rule_node.rb

Overview

A static node reprenting a CSS rule.

See Also:

Constant Summary collapse

PARENT =

The character used to include the parent selector

'&'

Instance Attribute Summary collapse

Attributes inherited from Node

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

Instance Method Summary collapse

Methods inherited from Node

#<<, #balance, #deep_copy, #each, #invisible?, #style, #to_s, #to_sass, #to_scss

Constructor Details

#initialize(rule) ⇒ RuleNode

Returns a new instance of RuleNode.

Parameters:



55
56
57
58
59
60
61
# File 'lib/sass/tree/rule_node.rb', line 55

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

Instance Attribute Details

#group_endBoolean

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

Returns:

  • (Boolean)


51
52
53
# File 'lib/sass/tree/rule_node.rb', line 51

def group_end
  @group_end
end

#parsed_rulesSelector::CommaSequence

The CSS selector for this rule, without any unresolved interpolation but with parent references still intact. It's only set once Tree::Node#perform has been called.



26
27
28
# File 'lib/sass/tree/rule_node.rb', line 26

def parsed_rules
  @parsed_rules
end

#resolved_rulesSelector::CommaSequence

The CSS selector for this rule, without any unresolved interpolation or parent references. It's only set once Visitors::Cssize has been run.



33
34
35
# File 'lib/sass/tree/rule_node.rb', line 33

def resolved_rules
  @resolved_rules
end

#ruleArray<String, Sass::Script::Node>

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

Returns:



18
19
20
# File 'lib/sass/tree/rule_node.rb', line 18

def rule
  @rule
end

#tabsFixnum

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:

  • (Fixnum)


45
46
47
# File 'lib/sass/tree/rule_node.rb', line 45

def tabs
  @tabs
end

Instance Method Details

#==(other) ⇒ Boolean

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



80
81
82
# File 'lib/sass/tree/rule_node.rb', line 80

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:



87
88
89
90
91
# File 'lib/sass/tree/rule_node.rb', line 87

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.

Returns:

  • (Boolean)

    Whether or not this rule is continued on the next line



94
95
96
97
# File 'lib/sass/tree/rule_node.rb', line 94

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.

Returns:



113
114
115
116
# File 'lib/sass/tree/rule_node.rb', line 113

def debug_info
  {:filename => filename && ("file://" + URI.escape(File.expand_path(filename))),
   :line => self.line}
end

#do_extend(extends)

Extends this Rule's selector with the given extends.

See Also:



102
103
104
105
106
# File 'lib/sass/tree/rule_node.rb', line 102

def do_extend(extends)
  node = dup
  node.resolved_rules = resolved_rules.do_extend(extends)
  node
end

#filename=(filename)

If we've precached the parsed selector, set the filename on it, too.



70
71
72
73
# File 'lib/sass/tree/rule_node.rb', line 70

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

#line=(line)

If we've precached the parsed selector, set the line on it, too.



64
65
66
67
# File 'lib/sass/tree/rule_node.rb', line 64

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