Sha256: 979c06aff6cbec6ca266741b3506061100ade31e3cdc7bc6b9c00c0bab485231

Contents?: true

Size: 1.34 KB

Versions: 33

Compression:

Stored size: 1.34 KB

Contents

module Sass::Script::Value
  # A SassScript object representing a CSS string *or* a CSS identifier.
  class String < Base
    # The Ruby value of the string.
    #
    # @return [String]
    attr_reader :value

    # 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`
    attr_reader :type

    # Creates a new string.
    #
    # @param value [String] See \{#value}
    # @param type [Symbol] See \{#type}
    def initialize(value, type = :identifier)
      super(value)
      @type = type
    end

    # @see Value#plus
    def plus(other)
      other_str = other.is_a?(Sass::Script::Value::String) ? other.value : other.to_s
      Sass::Script::Value::String.new(self.value + other_str, self.type)
    end

    # @see Value#to_s
    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

    # @see Value#to_sass
    def to_sass(opts = {})
      to_s
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
sass-3.3.0.alpha.256 lib/sass/script/value/string.rb
sass-3.3.0.alpha.255 lib/sass/script/value/string.rb
sass-3.3.0.alpha.252 lib/sass/script/value/string.rb
sass-3.3.0.alpha.253 lib/sass/script/value/string.rb
sass-3.3.0.alpha.247 lib/sass/script/value/string.rb
sass-3.3.0.alpha.243 lib/sass/script/value/string.rb
sass-3.3.0.alpha.231 lib/sass/script/value/string.rb
sass-3.3.0.alpha.229 lib/sass/script/value/string.rb
sass-3.3.0.alpha.227 lib/sass/script/value/string.rb
sass-3.3.0.alpha.226 lib/sass/script/value/string.rb
sass-3.3.0.alpha.225 lib/sass/script/value/string.rb
sass-3.3.0.alpha.224 lib/sass/script/value/string.rb
sass-3.3.0.alpha.222 lib/sass/script/value/string.rb
sass-3.3.0.alpha.218 lib/sass/script/value/string.rb
sass-3.3.0.alpha.216 lib/sass/script/value/string.rb
sass-3.3.0.alpha.215 lib/sass/script/value/string.rb
sass-3.3.0.alpha.214 lib/sass/script/value/string.rb
sass-3.3.0.alpha.213 lib/sass/script/value/string.rb
sass-3.3.0.alpha.212 lib/sass/script/value/string.rb
sass-3.3.0.alpha.211 lib/sass/script/value/string.rb