class Sass::Script::String - sass-3.2.19 Documentation

# class Sass::Script::String

A SassScript object representing a CSS string or a CSS identifier.

### Attributes

type[R]

Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren't.

@return [Symbol] `:string` or `:identifier`

value[R]

The Ruby value of the string.

@return [String]

### Public Class Methods

new(value, type = :identifier) click to toggle source

Creates a new string.

@param value [String] See {#value} @param type [Symbol] See {#type}

Calls superclass method Sass::Script::Literal.new

    # File lib/sass/script/string.rb, line 22
    def initialize(value, type = :identifier)
      super(value)
      @type = type
    end

### Public Instance Methods

plus(other) click to toggle source

@see Sass::Script::Literal#plus

    # File lib/sass/script/string.rb, line 28
    def plus(other)
      other_str = other.is_a?(Sass::Script::String) ? other.value : other.to_s
      Sass::Script::String.new(self.value + other_str, self.type)
    end

to_s(opts = {}) click to toggle source

@see Node#to_s

    # File lib/sass/script/string.rb, line 34
    def to_s(opts = {})
      if @type == :identifier
        return @value.gsub(/\n\s*/, " ")
      end

      return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
      return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
      return "\"#{value}\"" unless value.include?('"')
      return "'#{value}'" unless value.include?("'")
      "\"#{value.gsub('"', "\\\"")}\"" #'
    end

to_sass(opts = {}) click to toggle source

@see Sass::Script::Node#to_sass

    # File lib/sass/script/string.rb, line 47
    def to_sass(opts = {})
      to_s
    end