Sha256: 1d4e06ea16c53ea39cc30cf4ec68bf595a6e707b45f9d9a0d2ac0481842f7669

Contents?: true

Size: 1.38 KB

Versions: 56

Compression:

Stored size: 1.38 KB

Contents

module Sass::Script::Tree
  # A SassScript parse node representing a variable.
  class Variable < Node
    # The name of the variable.
    #
    # @return [String]
    attr_reader :name

    # The underscored name of the variable.
    #
    # @return [String]
    attr_reader :underscored_name

    # @param name [String] See \{#name}
    def initialize(name)
      @name = name
      @underscored_name = name.gsub(/-/, "_")
      super()
    end

    # @return [String] A string representation of the variable
    def inspect(opts = {})
      "$#{dasherize(name, opts)}"
    end
    alias_method :to_sass, :inspect

    # Returns an empty array.
    #
    # @return [Array<Node>] empty
    # @see Node#children
    def children
      []
    end

    # @see Node#deep_copy
    def deep_copy
      dup
    end

    protected

    # Evaluates the variable.
    #
    # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
    # @return [Sass::Script::Value] The SassScript object that is the value of the variable
    # @raise [Sass::SyntaxError] if the variable is undefined
    def _perform(environment)
      val = environment.var(name)
      raise Sass::SyntaxError.new("Undefined variable: \"$#{name}\".") unless val
      if val.is_a?(Sass::Script::Value::Number) && val.original
        val = val.dup
        val.original = nil
      end
      val
    end
  end
end

Version data entries

56 entries across 54 versions & 4 rubygems

Version Path
sass-4.0.0.alpha.1 lib/sass/script/tree/variable.rb
sass-3.4.20 lib/sass/script/tree/variable.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/sass-3.4.18/lib/sass/script/tree/variable.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/sass-3.4.19/lib/sass/script/tree/variable.rb
sass-3.4.19 lib/sass/script/tree/variable.rb
sass-3.4.18 lib/sass/script/tree/variable.rb
sass-3.4.17 lib/sass/script/tree/variable.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/sass-3.4.15/lib/sass/script/tree/variable.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/sass-3.4.15/lib/sass/script/tree/variable.rb
sass-3.4.16 lib/sass/script/tree/variable.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/sass-3.4.14/lib/sass/script/tree/variable.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/sass-3.4.15/lib/sass/script/tree/variable.rb
sass-3.4.15 lib/sass/script/tree/variable.rb
sass-3.4.14 lib/sass/script/tree/variable.rb
sass-3.4.13 lib/sass/script/tree/variable.rb
sass-3.4.12 lib/sass/script/tree/variable.rb
sass-3.4.11 lib/sass/script/tree/variable.rb
sass-3.4.10 lib/sass/script/tree/variable.rb
sass-3.4.9 lib/sass/script/tree/variable.rb
sass-3.4.8 lib/sass/script/tree/variable.rb