Class Sass::Tree::IfNode
In: lib/sass/tree/if_node.rb
Parent: Node

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

Methods

_perform   add_else   new   options=  

Attributes

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

@return [IfNode]

Public Class methods

@param expr [Script::Expr] The conditional expression.

  If this is nil, this is an `@else` node, not an `@else if`

[Source]

    # File lib/sass/tree/if_node.rb, line 19
19:     def initialize(expr)
20:       @expr = expr
21:       @last_else = self
22:       super()
23:     end

Public Instance methods

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

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

[Source]

    # File lib/sass/tree/if_node.rb, line 28
28:     def add_else(node)
29:       @last_else.else = node
30:       @last_else = node
31:     end

[Source]

    # File lib/sass/tree/if_node.rb, line 33
33:     def options=(options)
34:       super
35:       self.else.options = options if self.else
36:     end

Protected Instance methods

Runs the child nodes if the conditional expression is true; otherwise, tries the \{else} nodes.

@param environment [Sass::Environment] The lexical environment containing

  variable and mixin values

@return [Array<Tree::Node>] The resulting static nodes @see Sass::Tree

[Source]

    # File lib/sass/tree/if_node.rb, line 47
47:     def _perform(environment)
48:       environment = Sass::Environment.new(environment)
49:       return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
50:       return @else.perform(environment) if @else
51:       []
52:     end

[Validate]