Class: Sass::Tree::IfNode

Inherits:
Node 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 if`s. 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, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #invisible?, #last, #perform, #render, #style, #to_s, #to_sass

Constructor Details

#initialize(expr) ⇒ IfNode

Returns a new instance of IfNode.

Parameters:

  • expr (Script::Expr)

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



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

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:



15
16
17
# File 'lib/sass/tree/if_node.rb', line 15

def else
  @else
end

Instance Method Details

#add_else(node) ⇒ Object

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

Parameters:

  • node (IfNode)

    The ‘@else` node to append



28
29
30
31
# File 'lib/sass/tree/if_node.rb', line 28

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

#options=(options) ⇒ Object



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

def options=(options)
  super
  self.else.options = options if self.else
end