Sha256: b4dc6e4d8765d7cedbcf66aef9c1123fb713ce91f48284a2b8b8702d146b12ec

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

require 'sass/script/literal'

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(/\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

9 entries across 7 versions & 2 rubygems

Version Path
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/sass-3.2.7/lib/sass/script/string.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/sass-3.2.7/lib/sass/script/string.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/sass-3.2.7/lib/sass/script/string.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/sass-3.2.7/lib/sass/script/string.rb
sass-3.3.0.alpha.120 lib/sass/script/string.rb
sass-3.3.0.alpha.107 lib/sass/script/string.rb
sass-3.3.0.alpha.103 lib/sass/script/string.rb
sass-3.2.7 lib/sass/script/string.rb
sass-3.3.0.alpha.102 lib/sass/script/string.rb