Class: Sass::Tree::IfNode

Inherits:
Node
  • Object
show all
Defined in:
/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb

Overview

A dynamic node representing a Sass @if statement.

IfNodes are a little odd, in that they also represent @else and @else ifs. This is done as a linked list: each IfNode has a link (#else) to the next IfNode.

See Also:

Instance Attribute Summary (collapse)

Attributes inherited from Node

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Node

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

Constructor Details

- (IfNode) initialize(expr)

Returns a new instance of IfNode

Parameters:

  • expr (Script::Expr)

    See #expr



24
25
26
27
28
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 24

def initialize(expr)
  @expr = expr
  @last_else = self
  super()
end

Instance Attribute Details

- (IfNode) else

The next Sass::Tree::IfNode in the if-else list, or nil.

Returns:



21
22
23
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 21

def else
  @else
end

- (Script::Expr) expr

The conditional expression. If this is nil, this is an @else node, not an @else if.

Returns:

  • (Script::Expr)


16
17
18
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 16

def expr
  @expr
end

Class Method Details

+ _load(data)



42
43
44
45
46
47
48
49
50
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 42

def self._load(data)
  expr, else_, children = Marshal.load(data)
  node = IfNode.new(expr)
  node.else = else_
  node.children = children
  node.instance_variable_set('@last_else',
    node.else ? node.else.instance_variable_get('@last_else') : node)
  node
end

Instance Method Details

- _dump(f)



38
39
40
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 38

def _dump(f)
  Marshal.dump([expr, self.else, children])
end

- add_else(node)

Append an @else node to the end of the list.

Parameters:

  • node (IfNode)

    The @else node to append



33
34
35
36
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/tree/if_node.rb', line 33

def add_else(node)
  @last_else.else = node
  @last_else = node
end