Sha256: ec2f05338ec323dc11ab74556baf1821901477b4f5c933f3023ee1f17b837d44

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

module Sass::Script
  # A SassScript object representing a CSS string *or* a CSS identifier.
  class String < Literal
    # 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 Literal#plus
    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

    # @see Node#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 Node#to_sass
    def to_sass(opts = {})
      to_s
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sass-3.3.0.alpha.149 lib/sass/script/string.rb
sass-3.3.0.alpha.144 lib/sass/script/string.rb
sass-3.3.0.alpha.142 lib/sass/script/string.rb
sass-3.3.0.alpha.141 lib/sass/script/string.rb
sass-3.3.0.alpha.138 lib/sass/script/string.rb
sass-3.3.0.alpha.136 lib/sass/script/string.rb
sass-3.3.0.alpha.134 lib/sass/script/string.rb
sass-3.3.0.alpha.133 lib/sass/script/string.rb
sass-3.3.0.alpha.129 lib/sass/script/string.rb
sass-3.3.0.alpha.128 lib/sass/script/string.rb
sass-3.3.0.alpha.127 lib/sass/script/string.rb
sass-3.3.0.alpha.132 lib/sass/script/string.rb