class Sass::Tree::IfNode

A dynamic node representing a Sass ‘@if` statement.

{IfNode}s 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 Sass::Tree

Attributes

else[RW]

The next {IfNode} in the if-else list, or ‘nil`.

@return [IfNode]

expr[RW]

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

@return [Script::Expr]

Public Class Methods

_load(data) click to toggle source
# 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
new(expr) click to toggle source

@param expr [Script::Expr] See {#expr}

Calls superclass method
# File lib/sass/tree/if_node.rb, line 24
def initialize(expr)
  @expr = expr
  @last_else = self
  super()
end

Public Instance Methods

_dump(f) click to toggle source
# File lib/sass/tree/if_node.rb, line 38
def _dump(f)
  Marshal.dump([expr, self.else, children])
end
add_else(node) click to toggle source

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

@param node [IfNode] The ‘@else` node to append

# File lib/sass/tree/if_node.rb, line 33
def add_else(node)
  @last_else.else = node
  @last_else = node
end