Class: Sass::Tree::IfNode

Inherits:
Node
  • Object
show all
Defined in:
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(expr) ⇒ IfNode

Returns a new instance of IfNode.

Parameters:

  • expr (Script::Expr)

    See #expr



24
25
26
27
28
# File 'lib/sass/tree/if_node.rb', line 24

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

Instance Attribute Details

#elseIfNode

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

Returns:



21
22
23
# File 'lib/sass/tree/if_node.rb', line 21

def else
  @else
end

#exprScript::Expr

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

Returns:

  • (Script::Expr)


16
17
18
# File '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 '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 'lib/sass/tree/if_node.rb', line 38

def _dump(f)
  Marshal.dump([self.expr, self.else, self.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 'lib/sass/tree/if_node.rb', line 33

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