Sha256: 8235058ba045dc12bcd30556baca9a800970b084f0df5b984345d944a48933bf

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

module Sass
  module Tree
    # A dynamic node representing a variable definition.
    #
    # @see Sass::Tree
    class VariableNode < Node
      # @param name [String] The name of the variable
      # @param expr [Script::Node] The parse tree for the initial variable value
      # @param guarded [Boolean] Whether this is a guarded variable assignment (`||=`)
      def initialize(name, expr, guarded)
        @name = name
        @expr = expr
        @guarded = guarded
        super()
      end

      protected

      def to_src(tabs, opts, fmt)
        "#{'  ' * tabs}$#{@name}: #{@expr.to_sass}#{' !default' if @guarded}#{semi fmt}\n"
      end

      # Loads the new variable value into the environment.
      #
      # @param environment [Sass::Environment] The lexical environment containing
      #   variable and mixin values
      def _perform(environment)
        return [] if @guarded && !environment.var(@name).nil?
        val = @expr.perform(environment)
        if @expr.context == :equals && val.is_a?(Sass::Script::String)
          val = Sass::Script::String.new(val.value)
        end
        environment.set_var(@name, val)
        []
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
haml-edge-2.3.186 lib/sass/tree/variable_node.rb
haml-edge-2.3.185 lib/sass/tree/variable_node.rb
haml-edge-2.3.184 lib/sass/tree/variable_node.rb
haml-3.0.0.beta.1 lib/sass/tree/variable_node.rb
haml-edge-2.3.183 lib/sass/tree/variable_node.rb
haml-edge-2.3.182 lib/sass/tree/variable_node.rb
haml-edge-2.3.181 lib/sass/tree/variable_node.rb
haml-edge-2.3.180 lib/sass/tree/variable_node.rb