Class Index [+]

Quicksearch

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]

Public Class Methods

new(expr) click to toggle source

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

  If this is nil, this is an `@else` node, not an `@else if`
    # 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

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 28
28:     def add_else(node)
29:       @last_else.else = node
30:       @last_else = node
31:     end
options=(options) click to toggle source

@see Node#options=

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

Protected Instance Methods

_perform(environment) click to toggle source

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] The resulting static nodes @see Sass::Tree

    # File lib/sass/tree/if_node.rb, line 62
62:     def _perform(environment)
63:       environment = Sass::Environment.new(environment)
64:       return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
65:       return @else.perform(environment) if @else
66:       []
67:     end
invalid_child?(child) click to toggle source

Returns an error message if the given child node is invalid, and false otherwise.

{ExtendNode}s are valid within {IfNode}s.

@param child [Tree::Node] A potential child node. @return [Boolean, String] Whether or not the child node is valid,

  as well as the error message to display if it is invalid
    # File lib/sass/tree/if_node.rb, line 77
77:     def invalid_child?(child)
78:       super unless child.is_a?(ExtendNode)
79:     end
to_src(tabs, opts, fmt, is_else = false) click to toggle source

@see Node#to_src

    # File lib/sass/tree/if_node.rb, line 42
42:     def to_src(tabs, opts, fmt, is_else = false)
43:       name =
44:         if !is_else; "if"
45:         elsif @expr; "else if"
46:         else; "else"
47:         end
48:       str = "#{'  ' * tabs}@#{name}"
49:       str << " #{@expr.to_sass(opts)}" if @expr
50:       str << children_to_src(tabs, opts, fmt)
51:       str << @else.send(:to_src, tabs, opts, fmt, true) if @else
52:       str
53:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.