Sha256: 57d05d7bb5e2526238f4d90e055dc28419115cb4eb89bce9e2cd9d3f0121c3eb

Contents?: true

Size: 1.54 KB

Versions: 31

Compression:

Stored size: 1.54 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 conditional expression.
    # If this is nil, this is an `@else` node, not an `@else if`.
    #
    # @return [Script::Expr]
    attr_reader :expr

    # The next {IfNode} in the if-else list, or `nil`.
    #
    # @return [IfNode]
    attr_accessor :else

    # @param expr [Script::Expr] See \{#expr}
    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

    # @see Node#options=
    def options=(options)
      super
      self.else.options = options if self.else
    end

    def _dump(f)
      Marshal.dump([self.expr, self.else, self.children])
    end

    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

    # @see Node#deep_copy
    def deep_copy
      node = super
      node.else = self.else.deep_copy if self.else
      node
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
haml_ejs-0.0.1 vendor/sass/lib/sass/tree/if_node.rb
haml-3.1.3 vendor/sass/lib/sass/tree/if_node.rb
haml-3.2.0.alpha.8 vendor/sass/lib/sass/tree/if_node.rb
sass-3.1.3 lib/sass/tree/if_node.rb
sass-3.2.0.alpha.9 lib/sass/tree/if_node.rb
sass-3.2.0.alpha.8 lib/sass/tree/if_node.rb
haml-3.2.0.alpha.5 vendor/sass/lib/sass/tree/if_node.rb
haml-3.2.0.alpha.4 vendor/sass/lib/sass/tree/if_node.rb
haml-3.1.2 vendor/sass/lib/sass/tree/if_node.rb
sass-3.1.2 lib/sass/tree/if_node.rb
sass-3.2.0.alpha.7 lib/sass/tree/if_node.rb
sass-3.2.0.alpha.6 lib/sass/tree/if_node.rb
haml-3.2.0.alpha.3 vendor/sass/lib/sass/tree/if_node.rb
sass-3.2.0.alpha.4 lib/sass/tree/if_node.rb
sass-3.2.0.alpha.3 lib/sass/tree/if_node.rb
sass-3.1.1 lib/sass/tree/if_node.rb
haml-3.2.0.alpha.2 vendor/sass/lib/sass/tree/if_node.rb
haml-3.1.1 vendor/sass/lib/sass/tree/if_node.rb
sass-3.1.0 lib/sass/tree/if_node.rb
sass-3.1.0.alpha.263 lib/sass/tree/if_node.rb