Sha256: 0c4bfb3ca89ddabcd924040fab944e4c50d945bf92e14db49c26a764e55376df

Contents?: true

Size: 1.5 KB

Versions: 203

Compression:

Stored size: 1.5 KB

Contents

require 'sass/tree/node'

module Sass::Tree
  # 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
  class IfNode < Node
    # The next {IfNode} in the if-else list, or `nil`.
    #
    # @return [IfNode]
    attr_accessor :else

    # @param expr [Script::Expr] The conditional expression.
    #   If this is nil, this is an `@else` node, not an `@else if`
    def initialize(expr)
      @expr = expr
      @last_else = self
      super()
    end

    # Append an `@else` node to the end of the list.
    #
    # @param node [IfNode] The `@else` node to append
    def add_else(node)
      @last_else.else = node
      @last_else = node
    end

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

    protected

    # 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
    def _perform(environment)
      environment = Sass::Environment.new(environment)
      return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
      return @else.perform(environment) if @else
      []
    end
  end
end

Version data entries

203 entries across 202 versions & 6 rubygems

Version Path
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/tree/if_node.rb
haml-2.2.23 lib/sass/tree/if_node.rb
haml-edge-2.3.179 lib/sass/tree/if_node.rb
haml-edge-2.3.178 lib/sass/tree/if_node.rb
haml-edge-2.3.177 lib/sass/tree/if_node.rb
haml-edge-2.3.176 lib/sass/tree/if_node.rb
haml-edge-2.3.175 lib/sass/tree/if_node.rb
haml-2.2.22 lib/sass/tree/if_node.rb
haml-edge-2.3.174 lib/sass/tree/if_node.rb
haml-edge-2.3.173 lib/sass/tree/if_node.rb
haml-edge-2.3.172 lib/sass/tree/if_node.rb
haml-edge-2.3.171 lib/sass/tree/if_node.rb
haml-edge-2.3.170 lib/sass/tree/if_node.rb
haml-2.2.21 lib/sass/tree/if_node.rb
drnic-haml-2.3.1 lib/sass/tree/if_node.rb
haml-edge-2.3.169 lib/sass/tree/if_node.rb
haml-edge-2.3.168 lib/sass/tree/if_node.rb
haml-edge-2.3.167 lib/sass/tree/if_node.rb
haml-edge-2.3.166 lib/sass/tree/if_node.rb
haml-edge-2.3.165 lib/sass/tree/if_node.rb